xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

how to use GitHub gist as an npm module All In One

how to use GitHub gist as an npm module All In One

如何将 GitHub gist 用作 npm 模块 All In One


{
  "version": "0.0.2",
  "name": "math.js",
  "author": "xgqfrms",
  "bin": "./math.js"
}
#!/usr/bin/env node

// math.js & `bin` package.json


console.log('math.js 👻');

const add = (a, b) => {
  return a + b;
}

 
const math = {
  add,
};

// test case
const result = add(1, 2);
console.log('result =', result, result === (1 + 2) ? '✅' : '❌');

// ESM
// export default math;
// Declaration or statement expected.ts(1128) ❌
// export math;

// CJS
// module.exports.add = add;
// module.exports = math;

https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8

solution ✅

steps

  1. create one gist with filename readme.md or whatever filename

  2. edit gist

image

  1. add files, package.json, app.js ...and so on

demo

https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8

npx

$ npx https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8

$ npx gist:981c08fcb7e09056e1c5d9192f272c8

# --ignore-existing
$ npx --ignore-existing https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8

$ npx --ignore-existing gist:981c08fcb7e09056e1c5d9192f272c8

# npx: the --ignore-existing argument has been removed.
# See `npm help exec` for more information
$ npm help exec


#!/usr/bin/env node & package.json bin

# solution
$ npx https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8

$ npx gist:1981c08fcb7e09056e1c5d9192f272c8

gist as npm package

https://dev.edenspiekermann.com/2016/03/02/gists-as-npm-packages/

https://dev.to/paul_melero/how-to-npm-install-from-github-repositories-or-gists-directly-6og

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-05-08 17:02  xgqfrms  阅读(54)  评论(0编辑  收藏  举报