├── .husky
├── .gitignore
└── pre-commit
├── .prettierignore
├── .eslintignore
├── .prettierrc.json
├── .gitignore
├── packages
└── cli
│ ├── module-ts
│ ├── template
│ │ ├── base
│ │ │ ├── .eslintignore
│ │ │ ├── .prettierrc.json
│ │ │ ├── .prettierignore
│ │ │ ├── TODO.md
│ │ │ ├── .gitignore
│ │ │ ├── demo
│ │ │ │ ├── demo-node.js
│ │ │ │ ├── demo-global.html
│ │ │ │ └── demo-amd.html
│ │ │ ├── .husky
│ │ │ │ ├── pre-commit
│ │ │ │ └── commit-msg
│ │ │ ├── commitlint.config.js
│ │ │ ├── .vscode
│ │ │ │ ├── extensions.json
│ │ │ │ └── settings.json
│ │ │ ├── .github
│ │ │ │ ├── FUNDING.yml
│ │ │ │ ├── ISSUE_TEMPLATE.md
│ │ │ │ └── workflows
│ │ │ │ │ ├── release.yml
│ │ │ │ │ └── ci.yml
│ │ │ ├── .lintstagedrc.cjs
│ │ │ ├── CHANGELOG.md
│ │ │ ├── jslib.json
│ │ │ ├── src
│ │ │ │ ├── test.ts
│ │ │ │ └── index.ts
│ │ │ ├── .nycrc
│ │ │ ├── test
│ │ │ │ ├── test.js
│ │ │ │ └── browser
│ │ │ │ │ └── index.html
│ │ │ ├── .editorconfig
│ │ │ ├── config
│ │ │ │ ├── rollup.config.esm.cjs
│ │ │ │ ├── rollup.config.cjs
│ │ │ │ ├── rollup.config.aio.cjs
│ │ │ │ └── rollup.cjs
│ │ │ ├── doc
│ │ │ │ └── api.md
│ │ │ ├── LICENSE
│ │ │ ├── .eslintrc.cjs
│ │ │ ├── package.json
│ │ │ ├── README.md
│ │ │ └── tsconfig.json
│ │ ├── .gitignore.tmpl
│ │ ├── jslib.json.tmpl
│ │ ├── package.json.tmpl
│ │ ├── demo-global.html.tmpl
│ │ ├── license.tmpl
│ │ ├── test-index.html.tmpl
│ │ ├── build-rollup.cjs.tmpl
│ │ ├── README.zh.md.tmpl
│ │ └── README.en.md.tmpl
│ ├── config.js
│ ├── demo.js
│ ├── test.js
│ ├── manager.js
│ ├── package.js
│ ├── index.js
│ ├── lint.js
│ ├── build.js
│ └── root.js
│ ├── module-js
│ ├── template
│ │ ├── base
│ │ │ ├── .eslintignore
│ │ │ ├── .prettierrc.json
│ │ │ ├── types
│ │ │ │ └── index.d.ts
│ │ │ ├── .prettierignore
│ │ │ ├── TODO.md
│ │ │ ├── .gitignore
│ │ │ ├── demo
│ │ │ │ ├── demo-node.js
│ │ │ │ ├── demo-global.html
│ │ │ │ └── demo-amd.html
│ │ │ ├── .husky
│ │ │ │ ├── pre-commit
│ │ │ │ └── commit-msg
│ │ │ ├── commitlint.config.js
│ │ │ ├── .vscode
│ │ │ │ ├── extensions.json
│ │ │ │ └── settings.json
│ │ │ ├── .github
│ │ │ │ ├── FUNDING.yml
│ │ │ │ ├── ISSUE_TEMPLATE.md
│ │ │ │ └── workflows
│ │ │ │ │ ├── release.yml
│ │ │ │ │ └── ci.yml
│ │ │ ├── .lintstagedrc.cjs
│ │ │ ├── CHANGELOG.md
│ │ │ ├── jslib.json
│ │ │ ├── src
│ │ │ │ ├── test.js
│ │ │ │ └── index.js
│ │ │ ├── .nycrc
│ │ │ ├── test
│ │ │ │ ├── test.js
│ │ │ │ └── browser
│ │ │ │ │ └── index.html
│ │ │ ├── config
│ │ │ │ ├── rollup.config.cjs
│ │ │ │ ├── rollup.config.esm.cjs
│ │ │ │ ├── rollup.config.aio.cjs
│ │ │ │ └── rollup.cjs
│ │ │ ├── .editorconfig
│ │ │ ├── .babelrc
│ │ │ ├── doc
│ │ │ │ └── api.md
│ │ │ ├── .eslintrc.cjs
│ │ │ ├── LICENSE
│ │ │ ├── package.json
│ │ │ └── README.md
│ │ ├── .gitignore.tmpl
│ │ ├── jslib.json.tmpl
│ │ ├── package.json.tmpl
│ │ ├── demo-global.html.tmpl
│ │ ├── license.tmpl
│ │ ├── test-index.html.tmpl
│ │ ├── build-rollup.cjs.tmpl
│ │ ├── README.zh.md.tmpl
│ │ └── README.en.md.tmpl
│ ├── config.js
│ ├── demo.js
│ ├── test.js
│ ├── package.js
│ ├── manager.js
│ ├── index.js
│ ├── lint.js
│ ├── build.js
│ └── root.js
│ ├── util
│ ├── file.js
│ ├── log.js
│ └── copy.js
│ ├── bin
│ ├── update.js
│ ├── init.js
│ ├── index.js
│ └── run-prompts.js
│ ├── package.json
│ └── README.md
├── .vscode
├── extensions.json
└── settings.json
├── .lintstagedrc.js
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
└── workflows
│ ├── publish.yml
│ ├── check-publish.yml
│ └── ci.yml
├── lerna.json
├── .editorconfig
├── .eslintrc.js
├── TODO.zh.md
├── TODO.md
├── LICENSE
├── package.json
├── README.zh-CN.md
├── CHANGELOG.zh.md
├── README.md
└── CHANGELOG.md
/.husky/.gitignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | template
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | template
2 |
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | .eslintcache
4 | temp
5 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.eslintignore:
--------------------------------------------------------------------------------
1 | dist
2 | require.js
3 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.eslintignore:
--------------------------------------------------------------------------------
1 | dist
2 | require.js
3 | *.ts
4 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | npx lint-staged
5 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true
3 | }
4 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/types/index.d.ts:
--------------------------------------------------------------------------------
1 | export declare const name = 'base';
2 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true
3 | }
4 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.prettierignore:
--------------------------------------------------------------------------------
1 | dist
2 | coverage
3 | package-lock.json
4 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/TODO.md:
--------------------------------------------------------------------------------
1 | # TODO List
2 |
3 | - [X] Done
4 | - [ ] Undone
5 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.prettierignore:
--------------------------------------------------------------------------------
1 | dist
2 | coverage
3 | package-lock.json
4 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/TODO.md:
--------------------------------------------------------------------------------
1 | # TODO List
2 |
3 | - [X] Done
4 | - [ ] Undone
5 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
3 | }
4 |
--------------------------------------------------------------------------------
/.lintstagedrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | '**/*.{ts,tsx,js,jsx}': ['prettier --write', 'eslint --cache'],
3 | };
4 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/.gitignore.tmpl:
--------------------------------------------------------------------------------
1 | coverage
2 | node_modules
3 | dist
4 | .eslintcache
5 | .nyc_output
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.gitignore:
--------------------------------------------------------------------------------
1 | coverage
2 | node_modules
3 | dist
4 | .eslintcache
5 | .nyc_output
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | custom: ['https://yanhaijing.com/mywallet/']
4 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.formatOnSave": true,
3 | "editor.defaultFormatter": "esbenp.prettier-vscode"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/demo/demo-node.js:
--------------------------------------------------------------------------------
1 | var base = require('../dist/index.js');
2 | console.log(base.name);
3 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/.gitignore.tmpl:
--------------------------------------------------------------------------------
1 | coverage
2 | node_modules
3 | dist
4 | .eslintcache
5 | .nyc_output
6 | types
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.gitignore:
--------------------------------------------------------------------------------
1 | coverage
2 | node_modules
3 | dist
4 | .eslintcache
5 | .nyc_output
6 | types
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/demo/demo-node.js:
--------------------------------------------------------------------------------
1 | var base = require('../dist/index.js');
2 | console.log(base.name);
3 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | . "$(dirname -- "$0")/_/husky.sh"
3 |
4 | npx lint-staged
5 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/commitlint.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['@commitlint/config-conventional'],
3 | };
4 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | . "$(dirname -- "$0")/_/husky.sh"
3 |
4 | npx lint-staged
5 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/commitlint.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['@commitlint/config-conventional'],
3 | };
4 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "npmClient": "yarn",
3 | "useWorkspaces": true,
4 | "packages": [
5 | "packages/*"
6 | ],
7 | "version": "3.0.6"
8 | }
9 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
3 | }
4 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
3 | }
4 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | . "$(dirname -- "$0")/_/husky.sh"
3 |
4 | npx --no -- commitlint --edit "$1"
5 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | . "$(dirname -- "$0")/_/husky.sh"
3 |
4 | npx --no -- commitlint --edit "$1"
5 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | custom: ['https://yanhaijing.com/mywallet/']
4 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.lintstagedrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | '**/*.{js,mjs,cjs,ts,cts,mts}': ['prettier --write', 'eslint --cache'],
3 | };
4 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.formatOnSave": true,
3 | "editor.defaultFormatter": "esbenp.prettier-vscode"
4 | }
5 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | custom: ['https://yanhaijing.com/mywallet/']
4 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.lintstagedrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | '**/*.{js,mjs,cjs,ts,cts,mts}': ['prettier --write', 'eslint --cache'],
3 | };
4 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.formatOnSave": true,
3 | "editor.defaultFormatter": "esbenp.prettier-vscode"
4 | }
5 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE:
--------------------------------------------------------------------------------
1 | ### 问题是什么
2 | 问题的具体描述,尽量详细
3 |
4 | ### 环境
5 | - 系统:mac 12.7.6
6 | - node版本:18.20.5
7 | - npm版本:10.8.2
8 | - 其他版本信息
9 |
10 | ### 在线例子
11 | 如果有请提供在线例子
12 |
13 | ### 其他
14 | 其他信息
15 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # CHANGE LOG
2 |
3 | ## 0.2.0 / 2023-9-24
4 |
5 | - Add c feature
6 | - Add d feature
7 |
8 | ## 0.1.0 / 2023-9-23
9 |
10 | - Add a feature
11 | - Add b feature
12 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # CHANGE LOG
2 |
3 | ## 0.2.0 / 2023-9-24
4 |
5 | - Add c feature
6 | - Add d feature
7 |
8 | ## 0.1.0 / 2023-9-23
9 |
10 | - Add a feature
11 | - Add b feature
12 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/jslib.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tslibname",
3 | "npmname": "tslibname",
4 | "umdname": "tslibname",
5 | "username": "tslibusername",
6 | "type": "ts",
7 | "version": "2.3.4"
8 | }
9 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/jslib.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jslibname",
3 | "npmname": "jslibnpmname",
4 | "umdname": "jslibumdname",
5 | "username": "jslibusername",
6 | "type": "js",
7 | "version": "2.3.4"
8 | }
9 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/src/test.js:
--------------------------------------------------------------------------------
1 | export const yan = 'yan';
2 |
3 | const yan2 = 'yan2';
4 |
5 | export default yan2;
6 |
7 | class A {
8 | aaa() {}
9 | }
10 |
11 | export class B extends A {
12 | bbb() {}
13 | }
14 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/jslib.json.tmpl:
--------------------------------------------------------------------------------
1 | {
2 | "name": "<%=name%>",
3 | "npmname": "<%=npmname%>",
4 | "umdname": "<%=umdname%>",
5 | "username": "<%=username%>",
6 | "type": "<%=type%>",
7 | "version": "<%=version%>"
8 | }
9 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/jslib.json.tmpl:
--------------------------------------------------------------------------------
1 | {
2 | "name": "<%=name%>",
3 | "npmname": "<%=npmname%>",
4 | "umdname": "<%=umdname%>",
5 | "username": "<%=username%>",
6 | "type": "<%=type%>",
7 | "version": "<%=version%>"
8 | }
9 |
--------------------------------------------------------------------------------
/packages/cli/util/file.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 | const path = require('path');
3 |
4 | function checkProjectExists(cmdPath, name) {
5 | return fs.existsSync(path.resolve(cmdPath, name));
6 | }
7 |
8 | exports.checkProjectExists = checkProjectExists;
9 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.nycrc:
--------------------------------------------------------------------------------
1 | {
2 | "check-coverage": true,
3 | "lines": 75,
4 | "statements": 75,
5 | "functions": 0,
6 | "branches": 75,
7 | "reporter": ["lcov", "text"],
8 | "require": ["@babel/register"],
9 | "sourceMap": false,
10 | "instrument": false
11 | }
12 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/src/index.js:
--------------------------------------------------------------------------------
1 | import yan2, { yan, B } from './test.js';
2 |
3 | console.log(yan);
4 | console.log(yan2, B);
5 | console.log([].includes('yeah!'));
6 | var a = 1 + 1;
7 | var b = a;
8 | console.log(a);
9 | console.log(b);
10 |
11 | export const name = 'base';
12 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/package.json.tmpl:
--------------------------------------------------------------------------------
1 | {
2 | "name": "<%=npmname%>",
3 | "author": "<%=username%>",
4 | "repository": {
5 | "type": "git",
6 | "url": "git://github.com/<%=username%>/<%=name%>.git"
7 | },
8 | "bugs": {
9 | "url": "https://github.com/<%=username%>/<%=name%>/issues"
10 | }
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/src/test.ts:
--------------------------------------------------------------------------------
1 | export const yan = 'yan';
2 |
3 | const yan2 = 'yan2';
4 |
5 | export default yan2;
6 |
7 | class A {
8 | public aaa(): void {
9 | console.log('122');
10 | }
11 | }
12 |
13 | export class B extends A {
14 | public bbb(): void {
15 | console.log('122');
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/package.json.tmpl:
--------------------------------------------------------------------------------
1 | {
2 | "name": "<%=npmname%>",
3 | "author": "<%=username%>",
4 | "repository": {
5 | "type": "git",
6 | "url": "git://github.com/<%=username%>/<%=name%>.git"
7 | },
8 | "bugs": {
9 | "url": "https://github.com/<%=username%>/<%=name%>/issues"
10 | }
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/src/index.ts:
--------------------------------------------------------------------------------
1 | import yan2, { B, yan } from './test';
2 |
3 | console.log([1].includes(1));
4 | console.log(yan);
5 | console.log(yan2);
6 |
7 | const a = 1 + 1;
8 | const b = a;
9 | console.log(a);
10 | console.log(b);
11 | console.log(B);
12 |
13 | export function greeter(person: string): string {
14 | return 'Hello, ' + person;
15 | }
16 |
17 | export const name = 'base';
18 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### What problem
2 |
3 | Description of the problem, as detailed as possible.
4 |
5 | ### Environment
6 |
7 | - Mobile: MI6
8 | - System: Android7.1.1
9 | - Browser:Chrome61
10 | - jslib version: 0.2.0
11 | - some other information
12 |
13 | ### Online demo
14 |
15 | Please provide online demo if possible.
16 |
17 | ### Other
18 |
19 | some other information.
20 |
21 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### What problem
2 |
3 | Description of the problem, as detailed as possible.
4 |
5 | ### Environment
6 |
7 | - Mobile: MI6
8 | - System: Android7.1.1
9 | - Browser:Chrome61
10 | - jslib version: 0.2.0
11 | - some other information
12 |
13 | ### Online demo
14 |
15 | Please provide online demo if possible.
16 |
17 | ### Other
18 |
19 | some other information.
20 |
21 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.nycrc:
--------------------------------------------------------------------------------
1 | {
2 | "check-coverage": true,
3 | "lines": 75,
4 | "statements": 75,
5 | "functions": 0,
6 | "branches": 75,
7 | "require": ["ts-node/register", "source-map-support/register"],
8 | "reporter": ["lcov", "text"],
9 | "extension": [".ts"],
10 | "include": ["src/**.ts"],
11 | "exclude": ["**/*.d.ts"],
12 | "sourceMap": true,
13 | "instrument": true,
14 | "all": true
15 | }
16 |
--------------------------------------------------------------------------------
/packages/cli/bin/update.js:
--------------------------------------------------------------------------------
1 | const pkg = require('../package.json');
2 | const modulejs = require('../module-js');
3 | const modulets = require('../module-ts');
4 |
5 | function update(option) {
6 | const cmdPath = process.cwd();
7 | option.version = pkg.version;
8 | if (option.type === 'js') {
9 | modulejs.update(cmdPath, option);
10 | } else if (option.type === 'ts') {
11 | modulets.update(cmdPath, option);
12 | }
13 | }
14 |
15 | exports.update = update;
16 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/test/test.js:
--------------------------------------------------------------------------------
1 | var expect = require('expect.js');
2 |
3 | // js 测试源文件
4 | var base = require('../src/index.js');
5 |
6 | describe('单元测试', function () {
7 | this.timeout(1000);
8 |
9 | describe('功能1', function () {
10 | it('相等', function () {
11 | expect(base.name).to.equal('base');
12 | });
13 | });
14 |
15 | describe('功能2', function () {
16 | it('不相等', function () {
17 | expect(base.name).not.to.equal(1);
18 | });
19 | });
20 | });
21 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/demo-global.html.tmpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Document
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/demo/demo-global.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Document
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/demo-global.html.tmpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Document
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/packages/cli/module-js/config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('config: init');
6 |
7 | util.copyTmpl(
8 | path.resolve(__dirname, `./template/jslib.json.tmpl`),
9 | path.resolve(cmdPath, name, 'jslib.json'),
10 | option,
11 | );
12 | }
13 |
14 | function update() {
15 | console.log('config: update');
16 | }
17 |
18 | module.exports = {
19 | init: init,
20 | update: update,
21 | };
22 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/demo/demo-global.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Document
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('config: init');
6 |
7 | util.copyTmpl(
8 | path.resolve(__dirname, `./template/jslib.json.tmpl`),
9 | path.resolve(cmdPath, name, 'jslib.json'),
10 | option,
11 | );
12 | }
13 |
14 | function update() {
15 | console.log('config: update');
16 | }
17 |
18 | module.exports = {
19 | init: init,
20 | update: update,
21 | };
22 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/test/test.js:
--------------------------------------------------------------------------------
1 | var expect = require('expect.js');
2 |
3 | // ts 测试编译后文件
4 | var base = require('../src/index.ts');
5 |
6 | describe('单元测试', function () {
7 | this.timeout(1000);
8 |
9 | describe('功能1', function () {
10 | it('相等', function () {
11 | expect(base.name).to.equal('base');
12 | });
13 | });
14 |
15 | describe('功能2', function () {
16 | it('不相等', function () {
17 | expect(base.name).not.to.equal(1);
18 | });
19 | });
20 | });
21 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # 根目录的配置
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | end_of_line = lf
7 | insert_final_newline = true
8 | indent_style = space
9 | indent_size = 4
10 |
11 | [*.html]
12 | indent_size = 2
13 |
14 | [*.{css,less,scss}]
15 | indent_size = 2
16 |
17 | [*.{cjs,js,ts}]
18 | indent_size = 2
19 |
20 | [*.{jsx,tsx}]
21 | indent_size = 2
22 |
23 | [*.vue]
24 | indent_size = 2
25 |
26 | [*.{json,yml,yaml}]
27 | indent_size = 2
28 |
29 | [*.{md,markdown}]
30 | indent_size = 2
31 |
32 | [*rc]
33 | indent_size = 2
34 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/config/rollup.config.cjs:
--------------------------------------------------------------------------------
1 | // rollup.config.js
2 | // commonjs
3 | var common = require('./rollup.cjs');
4 |
5 | module.exports = {
6 | input: 'src/index.js',
7 | output: [
8 | {
9 | file: 'dist/index.js',
10 | format: 'cjs',
11 | // When export and export default are not used at the same time, set legacy to true.
12 | // legacy: true,
13 | banner: common.banner,
14 | sourcemap: true,
15 | },
16 | ],
17 | plugins: [common.getCompiler()],
18 | };
19 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.editorconfig:
--------------------------------------------------------------------------------
1 | # 根目录的配置
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | end_of_line = lf
7 | insert_final_newline = true
8 | indent_style = space
9 | indent_size = 4
10 |
11 | [*.html]
12 | indent_size = 2
13 |
14 | [*.{css,less,scss}]
15 | indent_size = 2
16 |
17 | [*.{js,mjs,cjs,ts,cts,mts}]
18 | indent_size = 2
19 |
20 | [*.{json,yml,yaml}]
21 | indent_size = 2
22 |
23 | [*.{sh}]
24 | indent_size = 2
25 |
26 | [*.{md,makrdown}]
27 | indent_size = 2
28 |
29 | [*rc]
30 | indent_size = 2
31 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.editorconfig:
--------------------------------------------------------------------------------
1 | # 根目录的配置
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | end_of_line = lf
7 | insert_final_newline = true
8 | indent_style = space
9 | indent_size = 4
10 |
11 | [*.html]
12 | indent_size = 2
13 |
14 | [*.{css,less,scss}]
15 | indent_size = 2
16 |
17 | [*.{js,mjs,cjs,ts,cts,mts}]
18 | indent_size = 2
19 |
20 | [*.{json,yml,yaml}]
21 | indent_size = 2
22 |
23 | [*.{sh}]
24 | indent_size = 2
25 |
26 | [*.{md,makrdown}]
27 | indent_size = 2
28 |
29 | [*rc]
30 | indent_size = 2
31 |
--------------------------------------------------------------------------------
/packages/cli/module-js/demo.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('demo: init');
6 |
7 | util.copyTmpl(
8 | path.resolve(__dirname, `./template/demo-global.html.tmpl`),
9 | path.resolve(cmdPath, name, 'demo/demo-global.html'),
10 | option,
11 | );
12 | }
13 |
14 | function update(_cmdPath, _option) {
15 | console.log('demo: update');
16 | }
17 |
18 | module.exports = {
19 | init: init,
20 | update: update,
21 | };
22 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/demo.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('demo: init');
6 |
7 | util.copyTmpl(
8 | path.resolve(__dirname, `./template/demo-global.html.tmpl`),
9 | path.resolve(cmdPath, name, 'demo/demo-global.html'),
10 | option,
11 | );
12 | }
13 |
14 | function update(_cmdPath, _option) {
15 | console.log('demo: update');
16 | }
17 |
18 | module.exports = {
19 | init: init,
20 | update: update,
21 | };
22 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: {
4 | node: true,
5 | es2022: true,
6 | },
7 | parserOptions: {
8 | ecmaVersion: 'latest',
9 | sourceType: 'module',
10 | },
11 | extends: ['eslint:recommended', 'plugin:prettier/recommended'],
12 | rules: {
13 | 'no-unused-vars': [
14 | 2,
15 | {
16 | vars: 'local',
17 | args: 'after-used',
18 | ignoreRestSiblings: true,
19 | varsIgnorePattern: '^_',
20 | argsIgnorePattern: '^_',
21 | },
22 | ],
23 | },
24 | };
25 |
--------------------------------------------------------------------------------
/TODO.zh.md:
--------------------------------------------------------------------------------
1 | # 计划列表
2 |
3 | 这里列出会在未来添加的新功能,和已经完成的功能
4 |
5 | - [x] 升级 babel 7
6 | - [x] 增加 typescript 的支持
7 | - [x] 测试覆盖率
8 | - [x] 统一 eslint
9 | - [x] 提供 CLI 支持
10 | - [x] 升级依赖工具版本
11 | - [x] 统一 babel 编译 ts
12 | - [x] 添加 prettier
13 | - [x] 添加 commitlint
14 | - [x] 添加 husky
15 | - [x] 添加一个本地 server
16 | - [x] 支持 node exports condition
17 | - [x] 迁移 travis 到 github action
18 | - [x] 支持 github action 自动发包
19 | - [x] 升级 rollup v4
20 | - [ ] 支持区分环境打包
21 | - [ ] 添加 jsdom
22 | - [ ] 添加 puppeteer
23 | - [ ] 添加 watch 功能
24 | - [ ] 添加 chrome headless 等
25 | - [ ] 升级 eslint v9
26 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/demo/demo-amd.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Document
6 |
7 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/demo/demo-amd.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Document
6 |
7 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/packages/cli/util/log.js:
--------------------------------------------------------------------------------
1 | const chalk = require('chalk');
2 |
3 | const error = console.error;
4 | const log = console.error;
5 | const info = console.info;
6 | const warn = console.warn;
7 |
8 | function init() {
9 | console.success = function (...args) {
10 | log(chalk.bold.green(...args));
11 | };
12 | console.error = function (...args) {
13 | error(chalk.bold.red(...args));
14 | };
15 | console.warn = function (...args) {
16 | warn(chalk.hex('#FFA500')(...args));
17 | };
18 | console.info = function (...args) {
19 | info(chalk.bold.blue(...args));
20 | };
21 | }
22 |
23 | exports.init = init;
24 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/config/rollup.config.esm.cjs:
--------------------------------------------------------------------------------
1 | // rollup.config.js
2 | // ES output
3 | var common = require('./rollup.cjs');
4 |
5 | module.exports = {
6 | input: 'src/index.js',
7 | output: [
8 | {
9 | file: 'dist/index.esm.js',
10 | format: 'es',
11 | // When export and export default are not used at the same time, set legacy to true.
12 | // legacy: true,
13 | banner: common.banner,
14 | sourcemap: true,
15 | },
16 | {
17 | file: 'dist/index.mjs',
18 | format: 'es',
19 | // legacy: true,
20 | banner: common.banner,
21 | sourcemap: true,
22 | },
23 | ],
24 | plugins: [common.getCompiler()],
25 | };
26 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/config/rollup.config.esm.cjs:
--------------------------------------------------------------------------------
1 | // rollup.config.js
2 | // ES output
3 | var common = require('./rollup.cjs');
4 |
5 | module.exports = {
6 | input: 'src/index.ts',
7 | output: [
8 | {
9 | file: 'dist/index.esm.js',
10 | format: 'es',
11 | // When export and export default are not used at the same time, set legacy to true.
12 | // legacy: true,
13 | banner: common.banner,
14 | sourcemap: true
15 | },
16 | {
17 | file: 'dist/index.mjs',
18 | format: 'es',
19 | // legacy: true,
20 | banner: common.banner,
21 | sourcemap: true
22 | },
23 | ],
24 | plugins: [...common.getCompiler()],
25 | };
26 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "@babel/preset-env",
5 | {
6 | "targets": {
7 | "browsers": "last 2 versions, > 1%, ie >= 11, Android >= 4.1, iOS >= 10.3",
8 | "node": "14"
9 | },
10 | "modules": "commonjs",
11 | "loose": false
12 | }
13 | ]
14 | ],
15 | "plugins": [
16 | [
17 | "@babel/plugin-transform-runtime",
18 | {
19 | "corejs": 3,
20 | "versions": "^7.23.2",
21 | "helpers": true,
22 | "regenerator": false
23 | }
24 | ]
25 | ],
26 | "env": {
27 | "test": {
28 | "plugins": ["istanbul"]
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/config/rollup.config.cjs:
--------------------------------------------------------------------------------
1 | // rollup.config.js
2 | // commonjs
3 | var common = require('./rollup.cjs');
4 |
5 | module.exports = {
6 | input: 'src/index.ts',
7 | output: {
8 | file: 'dist/index.js',
9 | format: 'cjs',
10 | // When export and export default are not used at the same time, set legacy to true.
11 | // legacy: true,
12 | banner: common.banner,
13 | sourcemap: true
14 | },
15 | plugins: [
16 | ...common.getCompiler({
17 | tsconfigOverride: {
18 | compilerOptions: {
19 | declaration: true,
20 | declarationDir: 'types',
21 | },
22 | },
23 | useTsconfigDeclarationDir: true,
24 | }),
25 | ],
26 | };
27 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/doc/api.md:
--------------------------------------------------------------------------------
1 | # Document
2 |
3 | This is a `xxx` library with `xxx` features.
4 |
5 | ## Api template
6 |
7 | simple introduction of function
8 |
9 | detail introduction of function
10 |
11 | parameters and return of function need follow below rules:
12 |
13 | - param {string} name1 name1 description
14 | - param {number} [name2] name2 description ([] means optional)
15 | - param {string|number} name3 name3 description (| means multi types)
16 | - param { * } name3 name3 description (* means any type)
17 | - param {boolean} obj.sex definition of compound parameters
18 | - return {string} description for return
19 |
20 | For example (must have code example)
21 |
22 | ```js
23 | // do something
24 | ```
25 |
26 | special notice for errors and so on.
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/doc/api.md:
--------------------------------------------------------------------------------
1 | # Document
2 |
3 | This is a `xxx` library with `xxx` features.
4 |
5 | ## Api template
6 |
7 | simple introduction of function
8 |
9 | detail introduction of function
10 |
11 | parameters and return of function need follow below rules:
12 |
13 | - param {string} name1 name1 description
14 | - param {number} [name2] name2 description ([] means optional)
15 | - param {string|number} name3 name3 description (| means multi types)
16 | - param { * } name3 name3 description (* means any type)
17 | - param {boolean} obj.sex definition of compound parameters
18 | - return {string} description for return
19 |
20 | For example (must have code example)
21 |
22 | ```js
23 | // do something
24 | ```
25 |
26 | special notice for errors and so on.
--------------------------------------------------------------------------------
/packages/cli/module-ts/test.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('test: init');
6 |
7 | util.copyTmpl(
8 | path.resolve(__dirname, `./template/test-index.html.tmpl`),
9 | path.resolve(cmdPath, name, './test/browser/index.html'),
10 | option,
11 | );
12 | }
13 |
14 | function update(cmdPath, option) {
15 | console.log('test: update');
16 |
17 | util.copyFile(
18 | path.resolve(__dirname, `./template/base/.nycrc`),
19 | path.resolve(cmdPath, './.nycrc'),
20 | );
21 |
22 | util.copyTmpl(
23 | path.resolve(__dirname, `./template/test-index.html.tmpl`),
24 | path.resolve(cmdPath, './test/browser/index.html'),
25 | option,
26 | );
27 | }
28 |
29 | module.exports = {
30 | init: init,
31 | update: update,
32 | };
33 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | parser: '@babel/eslint-parser',
3 | env: {
4 | browser: true,
5 | es2021: true,
6 | node: true,
7 | mocha: true,
8 | },
9 | parserOptions: {
10 | ecmaVersion: 'latest',
11 | sourceType: 'module',
12 | // 即使没有 babelrc 配置文件,也使用 babel-eslint 来解析
13 | requireConfigFile: false,
14 | },
15 | extends: [
16 | 'eslint:recommended',
17 | 'plugin:prettier/recommended',
18 | 'plugin:import/recommended',
19 | ],
20 | rules: {
21 | 'no-unused-vars': [
22 | 2,
23 | {
24 | vars: 'local',
25 | args: 'after-used',
26 | ignoreRestSiblings: true,
27 | varsIgnorePattern: '^_',
28 | argsIgnorePattern: '^_',
29 | },
30 | ],
31 | eqeqeq: [2],
32 | 'import/no-unresolved': [1],
33 | },
34 | };
35 |
--------------------------------------------------------------------------------
/TODO.md:
--------------------------------------------------------------------------------
1 | # TODO List
2 |
3 | This document lists new features to be added in the future and features that have already been completed.
4 |
5 | - [x] Upgrade to Babel 7
6 | - [x] Add TypeScript support
7 | - [x] Test coverage
8 | - [x] Unified ESLint configuration
9 | - [x] Provide CLI support
10 | - [x] Upgrade dependency versions
11 | - [x] Unified Babel compilation for TypeScript
12 | - [x] Add Prettier
13 | - [x] Add Commitlint
14 | - [x] Add Husky
15 | - [x] Add a local server
16 | - [x] Support Node.js exports condition
17 | - [x] Migrate from Travis to GitHub Actions
18 | - [x] Upgrade to Rollup v4
19 | - [x] Support GitHub Actions for automated package publishing
20 | - [ ] Support environment-specific builds
21 | - [ ] Add jsdom
22 | - [ ] Add Puppeteer
23 | - [ ] Add watch functionality
24 | - [ ] Add Chrome Headless and related features
25 | - [ ] Upgrade to ESLint v9
26 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Publish Release
2 |
3 | on:
4 | push:
5 | tags:
6 | - 'v*.*.*'
7 |
8 | jobs:
9 | release:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - name: Checkout code
14 | uses: actions/checkout@v3
15 |
16 | - name: Setup Node.js
17 | uses: actions/setup-node@v3
18 | with:
19 | node-version: '18'
20 | cache: 'npm'
21 |
22 | - name: Install dependencies
23 | run: npm ci
24 |
25 | - name: Lint library
26 | run: npm run lint
27 |
28 | - name: Test library
29 | run: npm run test
30 |
31 | - name: Build library
32 | run: npm run build
33 |
34 | - name: Publish to npm (Stable)
35 | uses: JS-DevTools/npm-publish@v3
36 | with:
37 | token: ${{ secrets.NPM_TOKEN }}
38 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Publish Release
2 |
3 | on:
4 | push:
5 | tags:
6 | - 'v*.*.*'
7 |
8 | jobs:
9 | release:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - name: Checkout code
14 | uses: actions/checkout@v3
15 |
16 | - name: Setup Node.js
17 | uses: actions/setup-node@v3
18 | with:
19 | node-version: '18'
20 | cache: 'npm'
21 |
22 | - name: Install dependencies
23 | run: npm ci
24 |
25 | - name: Lint library
26 | run: npm run lint
27 |
28 | - name: Test library
29 | run: npm run test
30 |
31 | - name: Build library
32 | run: npm run build
33 |
34 | - name: Publish to npm (Stable)
35 | uses: JS-DevTools/npm-publish@v3
36 | with:
37 | token: ${{ secrets.NPM_TOKEN }}
38 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/config/rollup.config.aio.cjs:
--------------------------------------------------------------------------------
1 | // rollup.config.js
2 | // umd
3 | var nodeResolve = require('@rollup/plugin-node-resolve');
4 | var commonjs = require('@rollup/plugin-commonjs');
5 | var terser = require('@rollup/plugin-terser');
6 |
7 | var common = require('./rollup.cjs');
8 |
9 | module.exports = {
10 | input: 'src/index.js',
11 | output: [
12 | {
13 | file: 'dist/index.aio.js',
14 | format: 'umd',
15 | // When export and export default are not used at the same time, set legacy to true.
16 | // legacy: true,
17 | name: common.name,
18 | banner: common.banner,
19 | },
20 | {
21 | file: 'dist/index.aio.min.js',
22 | format: 'umd',
23 | // legacy: true,
24 | name: common.name,
25 | banner: common.banner,
26 | plugins: [terser()],
27 | },
28 | ],
29 | plugins: [nodeResolve({}), commonjs({}), common.getCompiler()],
30 | };
31 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/config/rollup.config.aio.cjs:
--------------------------------------------------------------------------------
1 | // rollup.config.js
2 | // umd
3 | var nodeResolve = require('@rollup/plugin-node-resolve');
4 | var commonjs = require('@rollup/plugin-commonjs');
5 | var terser = require('@rollup/plugin-terser');
6 |
7 | var common = require('./rollup.cjs');
8 |
9 | module.exports = {
10 | input: 'src/index.ts',
11 | output: [
12 | {
13 | file: 'dist/index.aio.js',
14 | format: 'umd',
15 | // When export and export default are not used at the same time, set legacy to true.
16 | // legacy: true,
17 | name: common.name,
18 | banner: common.banner,
19 | },
20 | {
21 | file: 'dist/index.aio.min.js',
22 | format: 'umd',
23 | // legacy: true,
24 | name: common.name,
25 | banner: common.banner,
26 | plugins: [terser()],
27 | },
28 | ],
29 | plugins: [nodeResolve({}), commonjs({}), ...common.getCompiler()],
30 | };
31 |
--------------------------------------------------------------------------------
/packages/cli/module-js/test.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('test: init');
6 |
7 | util.copyTmpl(
8 | path.resolve(__dirname, `./template/test-index.html.tmpl`),
9 | path.resolve(cmdPath, name, './test/browser/index.html'),
10 | option,
11 | );
12 | }
13 |
14 | function update(cmdPath, option) {
15 | console.log('test: update');
16 |
17 | util.copyFile(
18 | path.resolve(__dirname, `./template/base/.nycrc`),
19 | path.resolve(cmdPath, './.nycrc'),
20 | );
21 |
22 | util.copyTmpl(
23 | path.resolve(__dirname, `./template/test-index.html.tmpl`),
24 | path.resolve(cmdPath, './test/browser/index.html'),
25 | option,
26 | );
27 |
28 | util.copyFile(
29 | path.resolve(__dirname, `./template/base/.babelrc`),
30 | path.resolve(cmdPath, './.babelrc'),
31 | );
32 | }
33 |
34 | module.exports = {
35 | init: init,
36 | update: update,
37 | };
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2018-2025 yanhaijing
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2017-2025 jslibusername
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2017-2025 tslibusername
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/license.tmpl:
--------------------------------------------------------------------------------
1 | Copyright (C) 2017-<%=(new Date).getFullYear()%> <%=username%>
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/license.tmpl:
--------------------------------------------------------------------------------
1 | Copyright (C) 2017-<%=(new Date).getFullYear()%> <%=username%>
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: true,
4 | es2021: true,
5 | node: true,
6 | mocha: true,
7 | },
8 | parser: '@typescript-eslint/parser',
9 | parserOptions: {
10 | ecmaVersion: 'latest',
11 | sourceType: 'module',
12 | },
13 | plugins: ['@typescript-eslint'],
14 | extends: [
15 | 'eslint:recommended',
16 | 'plugin:@typescript-eslint/recommended',
17 | 'plugin:import/recommended',
18 | 'plugin:import/typescript',
19 | ],
20 | overrides: [
21 | {
22 | env: {
23 | node: true,
24 | },
25 | files: ['*.{js,cjs}'],
26 | parserOptions: {
27 | sourceType: 'script',
28 | },
29 | rules: {
30 | '@typescript-eslint/no-var-requires': 0,
31 | },
32 | },
33 | ],
34 | rules: {
35 | /**
36 | * ts 会检查
37 | */
38 | 'import/no-unresolved': 'off',
39 | /**
40 | * ts 会检查全局变量
41 | */
42 | 'import/no-deprecated': 'off',
43 | 'import/named': 'off',
44 | 'import/namespace': 'off',
45 | 'import/default': 'off',
46 | 'import/no-named-as-default-member': 'off',
47 | },
48 | };
49 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/test-index.html.tmpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mocha
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 |
30 |
31 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/test-index.html.tmpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mocha
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 |
30 |
31 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/test/browser/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mocha
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 |
30 |
31 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/test/browser/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mocha
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 |
30 |
31 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@js-lib/cli",
3 | "version": "1.1.0",
4 | "description": "The best third party JS|TS library scaffold",
5 | "scripts": {
6 | "prepare": "husky install",
7 | "preinstall": "npx only-allow yarn",
8 | "lint": "eslint packages --ext .js,.ts",
9 | "test": "echo \"Error: no test specified\" && exit 1"
10 | },
11 | "repository": {
12 | "type": "git",
13 | "url": "git+https://github.com/yanhaijing/jslib-base.git"
14 | },
15 | "author": "yanhaijing",
16 | "license": "MIT",
17 | "bugs": {
18 | "url": "https://github.com/yanhaijing/jslib-base/issues"
19 | },
20 | "homepage": "https://github.com/yanhaijing/jslib-base#readme",
21 | "devDependencies": {
22 | "lerna": "^3.22.1",
23 | "prettier": "3.1.0",
24 | "eslint": "^8.54.0",
25 | "eslint-config-prettier": "^9.0.0",
26 | "eslint-plugin-prettier": "^5.0.1",
27 | "husky": "^8.0.0",
28 | "lint-staged": "^14.0.1"
29 | },
30 | "private": true,
31 | "workspaces": [
32 | "packages/*"
33 | ],
34 | "publishConfig": {
35 | "registry": "https://registry.npmjs.org",
36 | "access": "public"
37 | },
38 | "engines": {
39 | "node": ">= 16.0.0"
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/packages/cli/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@js-lib/cli",
3 | "version": "3.0.6",
4 | "description": "The best third party JS|TS library scaffold",
5 | "author": "yanhaijing ",
6 | "homepage": "https://github.com/yanhaijing/jslib-base/tree/master#readme",
7 | "license": "MIT",
8 | "main": "index.js",
9 | "bin": {
10 | "jslib": "./bin/index.js"
11 | },
12 | "files": [
13 | "bin",
14 | "module-js",
15 | "module-ts",
16 | "util",
17 | "index.js"
18 | ],
19 | "engines": {
20 | "node": ">= 18.0.0"
21 | },
22 | "publishConfig": {
23 | "registry": "https://registry.npmjs.org",
24 | "access": "public"
25 | },
26 | "repository": {
27 | "type": "git",
28 | "url": "git+https://github.com/yanhaijing/jslib-base.git"
29 | },
30 | "scripts": {
31 | "test": "echo \"Error: run tests from root\" && exit 1"
32 | },
33 | "dependencies": {
34 | "@jsmini/extend": "^0.5.0",
35 | "chalk": "^4.1.2",
36 | "copy-dir": "^1.3.0",
37 | "inquirer": "^8.2.6",
38 | "ora": "^5.4.1",
39 | "shelljs": "^0.8.5",
40 | "template_js": "^3.1.4",
41 | "validate-npm-package-name": "^5.0.0",
42 | "yargs": "^17.7.2"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish npm Package
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | release_type:
7 | type: choice
8 | description: 'Release Tag'
9 | required: true
10 | default: 'latest'
11 | options:
12 | - latest
13 | - next
14 |
15 | jobs:
16 | publish:
17 | runs-on: ubuntu-latest
18 |
19 | steps:
20 | - name: Checkout code
21 | uses: actions/checkout@v3
22 |
23 | - name: Set up Node.js
24 | uses: actions/setup-node@v3
25 | with:
26 | node-version: '18'
27 |
28 | - name: Publish to npm
29 | uses: JS-DevTools/npm-publish@v3
30 | with:
31 | package: packages/cli
32 | token: ${{ secrets.NPM_TOKEN }}
33 | tag: ${{ github.event.inputs.release_type }}
34 |
35 | - name: Create Git tag
36 | run: |
37 | # Create a new tag based on the current version in package.json
38 | VERSION=$(node -p "require('./packages/cli/package.json').version")
39 | TAG="v$VERSION"
40 | git tag $TAG
41 | git push origin $TAG
42 | env:
43 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub Token to authenticate the push
44 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/manager.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const { exec } = require('child_process');
3 | const ora = require('ora');
4 | const shell = require('shelljs');
5 | function init(cmdPath, name, option) {
6 | const manager = option.manager;
7 |
8 | if (!manager) {
9 | return Promise.resolve();
10 | }
11 |
12 | if (!shell.which('git')) {
13 | console.error('未找到git命令,跳过install过程');
14 | return Promise.reject();
15 | }
16 |
17 | if (
18 | shell.exec('git init', {
19 | cwd: path.resolve(cmdPath, name),
20 | }).code !== 0
21 | ) {
22 | console.error('git init失败,跳过install过程');
23 | return Promise.reject();
24 | }
25 | return new Promise(function (resolve, reject) {
26 | const spinner = ora();
27 |
28 | spinner.start(`Installing packages from npm, wait for a second...`);
29 |
30 | exec(
31 | `${manager} install`,
32 | {
33 | cwd: path.resolve(cmdPath, name),
34 | },
35 | function (error, _stdout, _stderr) {
36 | if (error) {
37 | reject();
38 | return;
39 | }
40 | spinner.succeed(`Install packages successfully!`);
41 | resolve();
42 | },
43 | );
44 | });
45 | }
46 |
47 | module.exports = {
48 | init: init,
49 | };
50 |
--------------------------------------------------------------------------------
/packages/cli/module-js/package.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('package: init');
6 | util.mergeTmpl2JSON(
7 | path.resolve(__dirname, `./template/package.json.tmpl`),
8 | path.resolve(cmdPath, name, 'package.json'),
9 | option,
10 | );
11 | }
12 |
13 | function update(cmdPath, _option) {
14 | console.log('package: update');
15 | // 删除 1.x 版本的无用数据
16 | util.deleteJSONKeys(
17 | {
18 | 'jsnext:main': undefined,
19 | },
20 | path.resolve(cmdPath, 'package.json'),
21 | );
22 |
23 | const {
24 | scripts,
25 | sideEffects,
26 | devDependencies,
27 | dependencies,
28 | files,
29 | engines,
30 | publishConfig,
31 | exports,
32 | types,
33 | config,
34 | } = util.readJSON(path.resolve(__dirname, `./template/base/package.json`));
35 |
36 | util.mergeObj2JSON(
37 | {
38 | scripts,
39 | sideEffects,
40 | devDependencies,
41 | dependencies,
42 | files,
43 | engines,
44 | publishConfig,
45 | exports,
46 | types,
47 | config,
48 | },
49 | path.resolve(cmdPath, 'package.json'),
50 | );
51 | }
52 |
53 | module.exports = {
54 | init: init,
55 | update: update,
56 | };
57 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/package.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('package: init');
6 | util.mergeTmpl2JSON(
7 | path.resolve(__dirname, `./template/package.json.tmpl`),
8 | path.resolve(cmdPath, name, 'package.json'),
9 | option,
10 | );
11 | }
12 |
13 | function update(cmdPath, _option) {
14 | console.log('package: update');
15 | // 删除 1.x 版本的无用数据
16 | util.deleteJSONKeys(
17 | {
18 | 'jsnext:main': undefined,
19 | },
20 | path.resolve(cmdPath, 'package.json'),
21 | );
22 |
23 | const {
24 | scripts,
25 | sideEffects,
26 | devDependencies,
27 | dependencies,
28 | files,
29 | engines,
30 | publishConfig,
31 | exports,
32 | types,
33 | config,
34 | } = util.readJSON(path.resolve(__dirname, `./template/base/package.json`));
35 |
36 | util.mergeObj2JSON(
37 | {
38 | scripts,
39 | sideEffects,
40 | devDependencies,
41 | dependencies,
42 | files,
43 | engines,
44 | publishConfig,
45 | exports,
46 | types,
47 | config,
48 | },
49 | path.resolve(cmdPath, 'package.json'),
50 | );
51 | }
52 |
53 | module.exports = {
54 | init: init,
55 | update: update,
56 | };
57 |
--------------------------------------------------------------------------------
/packages/cli/module-js/manager.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const { exec } = require('child_process');
3 | const ora = require('ora');
4 | const shell = require('shelljs');
5 | function init(cmdPath, name, option) {
6 | const manager = option.manager;
7 |
8 | if (!manager) {
9 | return Promise.resolve();
10 | }
11 |
12 | if (!shell.which('git')) {
13 | console.error('git command not found, skipping install process');
14 | return Promise.reject();
15 | }
16 |
17 | if (
18 | shell.exec('git init', {
19 | cwd: path.resolve(cmdPath, name),
20 | }).code !== 0
21 | ) {
22 | console.error('git init failed, skipping install process');
23 | return Promise.reject();
24 | }
25 | return new Promise(function (resolve, reject) {
26 | const spinner = ora();
27 |
28 | spinner.start(`Installing packages from npm, wait for a second...`);
29 |
30 | exec(
31 | `${manager} install`,
32 | {
33 | cwd: path.resolve(cmdPath, name),
34 | },
35 | function (error, _stdout, _stderr) {
36 | if (error) {
37 | reject();
38 | return;
39 | }
40 | spinner.succeed(`Install packages successfully!`);
41 | resolve();
42 | },
43 | );
44 | });
45 | }
46 |
47 | module.exports = {
48 | init: init,
49 | };
50 |
--------------------------------------------------------------------------------
/packages/cli/module-js/index.js:
--------------------------------------------------------------------------------
1 | const ora = require('ora');
2 | const spinner = ora();
3 | const config = require('./config');
4 | const root = require('./root');
5 | const lint = require('./lint');
6 | const packagejson = require('./package');
7 | const demo = require('./demo');
8 | const build = require('./build');
9 | const test = require('./test');
10 | const manager = require('./manager');
11 |
12 | function init(cmdPath, option) {
13 | root.init(cmdPath, option.pathname, option);
14 | config.init(cmdPath, option.pathname, option);
15 | packagejson.init(cmdPath, option.pathname, option);
16 | demo.init(cmdPath, option.pathname, option);
17 | lint.init(cmdPath, option.pathname, option);
18 | build.init(cmdPath, option.pathname, option);
19 | test.init(cmdPath, option.pathname, option);
20 | manager.init(cmdPath, option.pathname, option).then(
21 | () => {
22 | spinner.succeed('Create lib successfully');
23 | },
24 | () => {
25 | spinner.fail('Create lib failure');
26 | },
27 | );
28 | }
29 |
30 | function update(cmdPath, option) {
31 | root.update(cmdPath, option);
32 | packagejson.update(cmdPath, option);
33 | lint.update(cmdPath, option);
34 | build.update(cmdPath, option);
35 | test.update(cmdPath, option);
36 | }
37 |
38 | exports.init = init;
39 | exports.update = update;
40 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/index.js:
--------------------------------------------------------------------------------
1 | const ora = require('ora');
2 | const spinner = ora();
3 | const config = require('./config');
4 | const root = require('./root');
5 | const lint = require('./lint');
6 | const packagejson = require('./package');
7 | const demo = require('./demo');
8 | const build = require('./build');
9 | const test = require('./test');
10 | const manager = require('./manager');
11 |
12 | function init(cmdPath, option) {
13 | root.init(cmdPath, option.pathname, option);
14 | config.init(cmdPath, option.pathname, option);
15 | packagejson.init(cmdPath, option.pathname, option);
16 | demo.init(cmdPath, option.pathname, option);
17 | lint.init(cmdPath, option.pathname, option);
18 | build.init(cmdPath, option.pathname, option);
19 | test.init(cmdPath, option.pathname, option);
20 | manager.init(cmdPath, option.pathname, option).then(
21 | () => {
22 | spinner.succeed('Create lib successfully');
23 | },
24 | () => {
25 | spinner.fail('Create lib failure');
26 | },
27 | );
28 | }
29 |
30 | function update(cmdPath, option) {
31 | root.update(cmdPath, option);
32 | packagejson.update(cmdPath, option);
33 | lint.update(cmdPath, option);
34 | build.update(cmdPath, option);
35 | test.update(cmdPath, option);
36 | }
37 |
38 | exports.init = init;
39 | exports.update = update;
40 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/config/rollup.cjs:
--------------------------------------------------------------------------------
1 | var babel = require('@rollup/plugin-babel');
2 |
3 | var pkg = require('../package.json');
4 |
5 | var version = pkg.version;
6 |
7 | var banner =
8 | `/*!
9 | * ${pkg.name} ${version} (https://github.com/jslibusername/jslibname)
10 | * API https://github.com/jslibusername/jslibname/blob/master/doc/api.md
11 | * Copyright 2017-${(new Date).getFullYear()} jslibusername. All Rights Reserved
12 | * Licensed under MIT (https://github.com/jslibusername/jslibname/blob/master/LICENSE)
13 | */
14 | `;
15 |
16 | function getCompiler() {
17 | return babel({
18 | babelrc: false,
19 | presets: [
20 | [
21 | '@babel/preset-env',
22 | {
23 | targets: {
24 | browsers:
25 | 'last 2 versions, > 1%, ie >= 11, Android >= 4.1, iOS >= 10.3',
26 | node: '14',
27 | },
28 | modules: false,
29 | loose: false,
30 | },
31 | ],
32 | ],
33 | plugins: [
34 | [
35 | '@babel/plugin-transform-runtime',
36 | {
37 | corejs: 3,
38 | versions: '^7.23.2',
39 | helpers: true,
40 | regenerator: false,
41 | },
42 | ],
43 | ],
44 | babelHelpers: 'runtime',
45 | exclude: 'node_modules/**',
46 | });
47 | }
48 |
49 | exports.name = 'jslibumdname';
50 | exports.banner = banner;
51 | exports.getCompiler = getCompiler;
52 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/build-rollup.cjs.tmpl:
--------------------------------------------------------------------------------
1 | var babel = require('@rollup/plugin-babel');
2 |
3 | var pkg = require('../package.json');
4 |
5 | var version = pkg.version;
6 |
7 | var banner =
8 | `/*!
9 | * ${pkg.name} ${version} (https://github.com/<%=username%>/<%=name%>)
10 | * API https://github.com/<%=username%>/<%=name%>/blob/master/doc/api.md
11 | * Copyright 2017-${(new Date).getFullYear()} <%=username%>. All Rights Reserved
12 | * Licensed under MIT (https://github.com/<%=username%>/<%=name%>/blob/master/LICENSE)
13 | */
14 | `;
15 |
16 | function getCompiler() {
17 | return babel({
18 | babelrc: false,
19 | presets: [
20 | [
21 | '@babel/preset-env',
22 | {
23 | targets: {
24 | browsers:
25 | 'last 2 versions, > 1%, ie >= 11, Android >= 4.1, iOS >= 10.3',
26 | node: '14',
27 | },
28 | modules: false,
29 | loose: false,
30 | },
31 | ],
32 | ],
33 | plugins: [
34 | [
35 | '@babel/plugin-transform-runtime',
36 | {
37 | corejs: 3,
38 | versions: '^7.23.2',
39 | helpers: true,
40 | regenerator: false,
41 | },
42 | ],
43 | ],
44 | babelHelpers: 'runtime',
45 | exclude: 'node_modules/**',
46 | });
47 | }
48 |
49 | exports.name = '<%=umdname%>';
50 | exports.banner = banner;
51 | exports.getCompiler = getCompiler;
52 |
--------------------------------------------------------------------------------
/packages/cli/module-js/lint.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(_cmdPath, _name, _option) {
5 | console.log('lint: init');
6 | }
7 |
8 | function update(cmdPath, _option) {
9 | console.log('lint: update');
10 |
11 | util.copyDir(
12 | path.resolve(__dirname, `./template/base/.husky`),
13 | path.resolve(cmdPath, '.husky'),
14 | {
15 | mode: true,
16 | },
17 | );
18 | util.copyFile(
19 | path.resolve(__dirname, `./template/base/.lintstagedrc.cjs`),
20 | path.resolve(cmdPath, '.lintstagedrc.cjs'),
21 | );
22 | util.copyFile(
23 | path.resolve(__dirname, `./template/base/.prettierignore`),
24 | path.resolve(cmdPath, '.prettierignore'),
25 | );
26 | util.copyFile(
27 | path.resolve(__dirname, `./template/base/.prettierrc.json`),
28 | path.resolve(cmdPath, '.prettierrc.json'),
29 | );
30 | util.copyFile(
31 | path.resolve(__dirname, `./template/base/commitlint.config.js`),
32 | path.resolve(cmdPath, 'commitlint.config.js'),
33 | );
34 | util.copyFile(
35 | path.resolve(__dirname, `./template/base/.eslintrc.cjs`),
36 | path.resolve(cmdPath, '.eslintrc.cjs'),
37 | );
38 | util.copyFile(
39 | path.resolve(__dirname, `./template/base/.eslintignore`),
40 | path.resolve(cmdPath, '.eslintignore'),
41 | );
42 |
43 | // 删除 1.x 版本的无用数据
44 | util.deleteFile(path.resolve(cmdPath, '.eslintrc.js'));
45 | }
46 |
47 | module.exports = {
48 | init: init,
49 | update: update,
50 | };
51 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/lint.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(_cmdPath, _name, _option) {
5 | console.log('lint: init');
6 | }
7 |
8 | function update(cmdPath, _option) {
9 | console.log('lint: update');
10 |
11 | util.copyDir(
12 | path.resolve(__dirname, `./template/base/.husky`),
13 | path.resolve(cmdPath, '.husky'),
14 | {
15 | mode: true,
16 | },
17 | );
18 | util.copyFile(
19 | path.resolve(__dirname, `./template/base/.lintstagedrc.cjs`),
20 | path.resolve(cmdPath, '.lintstagedrc.cjs'),
21 | );
22 | util.copyFile(
23 | path.resolve(__dirname, `./template/base/.prettierignore`),
24 | path.resolve(cmdPath, '.prettierignore'),
25 | );
26 | util.copyFile(
27 | path.resolve(__dirname, `./template/base/.prettierrc.json`),
28 | path.resolve(cmdPath, '.prettierrc.json'),
29 | );
30 | util.copyFile(
31 | path.resolve(__dirname, `./template/base/commitlint.config.js`),
32 | path.resolve(cmdPath, 'commitlint.config.js'),
33 | );
34 | util.copyFile(
35 | path.resolve(__dirname, `./template/base/.eslintrc.cjs`),
36 | path.resolve(cmdPath, '.eslintrc.cjs'),
37 | );
38 | util.copyFile(
39 | path.resolve(__dirname, `./template/base/.eslintignore`),
40 | path.resolve(cmdPath, '.eslintignore'),
41 | );
42 |
43 | // 删除 1.x 版本的无用数据
44 | util.deleteFile(path.resolve(cmdPath, '.eslintrc.js'));
45 | }
46 |
47 | module.exports = {
48 | init: init,
49 | update: update,
50 | };
51 |
--------------------------------------------------------------------------------
/packages/cli/module-js/build.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('build: init');
6 |
7 | util.copyTmpl(
8 | path.resolve(__dirname, `./template/build-rollup.cjs.tmpl`),
9 | path.resolve(cmdPath, name, 'config/rollup.cjs'),
10 | option,
11 | );
12 | }
13 |
14 | function update(cmdPath, option) {
15 | console.log('build: update');
16 |
17 | // 删除 1.x 版本的无用数据
18 | util.deleteJSONKeys(
19 | {
20 | scripts: {
21 | 'build:aio.min': undefined,
22 | },
23 | dependencies: {
24 | '@babel/runtime': undefined,
25 | },
26 | devDependencies: {
27 | 'babel-core': undefined,
28 | 'babel-preset-env': undefined,
29 | 'rollup-plugin-babel': undefined,
30 | 'rollup-plugin-commonjs': undefined,
31 | 'rollup-plugin-node-resolve': undefined,
32 | '@babel/cli': undefined,
33 | '@babel/core': undefined,
34 | 'rollup-plugin-uglify': undefined,
35 | },
36 | },
37 | path.resolve(cmdPath, './package.json'),
38 | );
39 | util.deleteDir(path.resolve(cmdPath, './config'));
40 |
41 | util.copyDir(
42 | path.resolve(__dirname, `./template/base/config`),
43 | path.resolve(cmdPath, 'config'),
44 | );
45 |
46 | util.copyTmpl(
47 | path.resolve(__dirname, `./template/build-rollup.cjs.tmpl`),
48 | path.resolve(cmdPath, 'config/rollup.cjs'),
49 | option,
50 | );
51 | }
52 |
53 | module.exports = {
54 | init: init,
55 | update: update,
56 | };
57 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3 |
4 | name: CI
5 |
6 | on:
7 | push:
8 | branches: ['master']
9 | pull_request:
10 | branches: ['master']
11 |
12 | jobs:
13 | commitlint:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@v3
17 | with:
18 | fetch-depth: 0
19 | - uses: wagoid/commitlint-github-action@v4
20 |
21 | lint:
22 | needs: commitlint
23 | runs-on: ubuntu-latest
24 | steps:
25 | - uses: actions/checkout@v3
26 | - name: Use Node.js 18.x
27 | uses: actions/setup-node@v3
28 | with:
29 | node-version: '18.x'
30 | cache: 'npm'
31 | - run: npm ci
32 | - run: npm run lint
33 |
34 | test:
35 | needs: lint
36 | runs-on: ubuntu-latest
37 | strategy:
38 | matrix:
39 | node-version: [18.x, 20.x, 22.x]
40 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
41 | steps:
42 | - uses: actions/checkout@v3
43 | - name: Use Node.js ${{ matrix.node-version }}
44 | uses: actions/setup-node@v3
45 | with:
46 | node-version: ${{ matrix.node-version }}
47 | cache: 'npm'
48 | - run: npm ci
49 | - run: npm test
50 | # - run: npm run coveralls --if-present
51 | - run: npm run build --if-present
52 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3 |
4 | name: CI
5 |
6 | on:
7 | push:
8 | branches: ['master']
9 | pull_request:
10 | branches: ['master']
11 |
12 | jobs:
13 | commitlint:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@v3
17 | with:
18 | fetch-depth: 0
19 | - uses: wagoid/commitlint-github-action@v4
20 |
21 | lint:
22 | needs: commitlint
23 | runs-on: ubuntu-latest
24 | steps:
25 | - uses: actions/checkout@v3
26 | - name: Use Node.js 18.x
27 | uses: actions/setup-node@v3
28 | with:
29 | node-version: '18.x'
30 | cache: 'npm'
31 | - run: npm ci
32 | - run: npm run lint
33 |
34 | test:
35 | needs: lint
36 | runs-on: ubuntu-latest
37 | strategy:
38 | matrix:
39 | node-version: [18.x, 20.x, 22.x]
40 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
41 | steps:
42 | - uses: actions/checkout@v3
43 | - name: Use Node.js ${{ matrix.node-version }}
44 | uses: actions/setup-node@v3
45 | with:
46 | node-version: ${{ matrix.node-version }}
47 | cache: 'npm'
48 | - run: npm ci
49 | - run: npm test
50 | # - run: npm run coveralls --if-present
51 | - run: npm run build --if-present
52 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/build.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const util = require('../util/copy');
3 |
4 | function init(cmdPath, name, option) {
5 | console.log('build: init');
6 |
7 | util.copyTmpl(
8 | path.resolve(__dirname, `./template/build-rollup.cjs.tmpl`),
9 | path.resolve(cmdPath, name, 'config/rollup.cjs'),
10 | option,
11 | );
12 | }
13 |
14 | function update(cmdPath, option) {
15 | console.log('build: update');
16 |
17 | // 删除 1.x 版本的无用数据
18 | util.deleteJSONKeys(
19 | {
20 | scripts: {
21 | 'build:aio.min': undefined,
22 | },
23 | dependencies: {
24 | '@babel/runtime': undefined,
25 | },
26 | devDependencies: {
27 | 'babel-core': undefined,
28 | 'babel-preset-env': undefined,
29 | 'rollup-plugin-babel': undefined,
30 | 'rollup-plugin-commonjs': undefined,
31 | 'rollup-plugin-node-resolve': undefined,
32 | '@babel/cli': undefined,
33 | '@babel/core': undefined,
34 | 'rollup-plugin-uglify': undefined,
35 | },
36 | },
37 | path.resolve(cmdPath, './package.json'),
38 | );
39 | util.deleteDir(path.resolve(cmdPath, './config'));
40 |
41 | util.copyDir(
42 | path.resolve(__dirname, `./template/base/config`),
43 | path.resolve(cmdPath, 'config'),
44 | );
45 |
46 | util.copyTmpl(
47 | path.resolve(__dirname, `./template/build-rollup.cjs.tmpl`),
48 | path.resolve(cmdPath, 'config/rollup.cjs'),
49 | option,
50 | );
51 |
52 | util.copyFile(
53 | path.resolve(__dirname, `./template/base/tsconfig.json`),
54 | path.resolve(cmdPath, 'tsconfig.json'),
55 | );
56 | }
57 |
58 | module.exports = {
59 | init: init,
60 | update: update,
61 | };
62 |
--------------------------------------------------------------------------------
/packages/cli/bin/init.js:
--------------------------------------------------------------------------------
1 | const configjs = require('../module-js/config');
2 | const configts = require('../module-ts/config');
3 | const modulejs = require('../module-js');
4 | const modulets = require('../module-ts');
5 | const pkg = require('../package.json');
6 | const { checkProjectExists } = require('../util/file');
7 |
8 | function init(argv, answers) {
9 | const cmdPath = process.cwd();
10 | const { name, npmname, umdname, username, type, manager } = Object.assign(
11 | {},
12 | argv,
13 | answers,
14 | );
15 | const pathname = String(typeof argv._[1] !== 'undefined' ? argv._[1] : name);
16 |
17 | const option = {
18 | pathname, // 创建的名字
19 | name: String(name), // 项目名字 readme
20 | npmname: String(npmname), // 发布到npm的名字,有可能和项目名字不一样,比如带scope
21 | umdname: String(umdname),
22 | username: String(username),
23 | type,
24 | manager,
25 | version: pkg.version,
26 | };
27 |
28 | // 运行命令
29 | if (!pathname) {
30 | console.error('error: jslib create need name');
31 | return;
32 | }
33 |
34 | // 仅初始化配置文件
35 | if (argv.config) {
36 | if (option.type === 'js') {
37 | configjs.init(cmdPath, '', option);
38 | } else if (option.type === 'ts') {
39 | configts.init(cmdPath, '', option);
40 | }
41 | return;
42 | }
43 |
44 | if (checkProjectExists(cmdPath, pathname) && !argv.force) {
45 | console.error(
46 | 'error: The project is already existed! If you really want to override it, use --force argv to bootstrap!',
47 | );
48 | return;
49 | }
50 |
51 | if (option.type === 'js') {
52 | modulejs.init(cmdPath, option);
53 | } else if (option.type === 'ts') {
54 | modulets.init(cmdPath, option);
55 | }
56 | }
57 |
58 | exports.init = init;
59 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/config/rollup.cjs:
--------------------------------------------------------------------------------
1 | var typescript = require('rollup-plugin-typescript2');
2 | var babel = require('@rollup/plugin-babel');
3 | var { extendDeep } = require('@jsmini/extend');
4 |
5 | var pkg = require('../package.json');
6 |
7 | var version = pkg.version;
8 |
9 | var banner =
10 | `/*!
11 | * ${pkg.name} ${version} (https://github.com/tslibusername/tslibname)
12 | * API https://github.com/tslibusername/tslibname/blob/master/doc/api.md
13 | * Copyright 2017-${(new Date).getFullYear()} tslibusername. All Rights Reserved
14 | * Licensed under MIT (https://github.com/tslibusername/tslibname/blob/master/LICENSE)
15 | */
16 | `;
17 |
18 | function getCompiler(opt) {
19 | opt = extendDeep(
20 | {
21 | tsconfigOverride: {
22 | compilerOptions: { target: 'esnext', module: 'esnext' },
23 | },
24 | },
25 | opt,
26 | );
27 | return [
28 | typescript(opt),
29 | babel({
30 | babelrc: false,
31 | extensions: ['.js', '.mjs', '.ts'],
32 | presets: [
33 | [
34 | '@babel/preset-env',
35 | {
36 | targets: {
37 | browsers:
38 | 'last 2 versions, > 1%, ie >= 11, Android >= 4.1, iOS >= 10.3',
39 | node: '14',
40 | },
41 | modules: false,
42 | loose: false,
43 | },
44 | ],
45 | ],
46 | plugins: [
47 | [
48 | '@babel/plugin-transform-runtime',
49 | {
50 | corejs: 3,
51 | versions: '^7.23.2',
52 | helpers: true,
53 | regenerator: false,
54 | },
55 | ],
56 | ],
57 | babelHelpers: 'runtime',
58 | exclude: 'node_modules/**',
59 | }),
60 | ];
61 | }
62 |
63 | exports.name = 'tslibname';
64 | exports.banner = banner;
65 | exports.getCompiler = getCompiler;
66 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/build-rollup.cjs.tmpl:
--------------------------------------------------------------------------------
1 | var typescript = require('rollup-plugin-typescript2');
2 | var babel = require('@rollup/plugin-babel');
3 | var { extendDeep } = require('@jsmini/extend');
4 |
5 | var pkg = require('../package.json');
6 |
7 | var version = pkg.version;
8 |
9 | var banner =
10 | `/*!
11 | * ${pkg.name} ${version} (https://github.com/<%=username%>/<%=name%>)
12 | * API https://github.com/<%=username%>/<%=name%>/blob/master/doc/api.md
13 | * Copyright 2017-${(new Date).getFullYear()} <%=username%>. All Rights Reserved
14 | * Licensed under MIT (https://github.com/<%=username%>/<%=name%>/blob/master/LICENSE)
15 | */
16 | `;
17 |
18 | function getCompiler(opt) {
19 | opt = extendDeep(
20 | {
21 | tsconfigOverride: {
22 | compilerOptions: { target: 'esnext', module: 'esnext' },
23 | },
24 | },
25 | opt,
26 | );
27 | return [
28 | typescript(opt),
29 | babel({
30 | babelrc: false,
31 | extensions: ['.js', '.mjs', '.ts'],
32 | presets: [
33 | [
34 | '@babel/preset-env',
35 | {
36 | targets: {
37 | browsers:
38 | 'last 2 versions, > 1%, ie >= 11, Android >= 4.1, iOS >= 10.3',
39 | node: '14',
40 | },
41 | modules: false,
42 | loose: false,
43 | },
44 | ],
45 | ],
46 | plugins: [
47 | [
48 | '@babel/plugin-transform-runtime',
49 | {
50 | corejs: 3,
51 | versions: '^7.23.2',
52 | helpers: true,
53 | regenerator: false,
54 | },
55 | ],
56 | ],
57 | babelHelpers: 'runtime',
58 | exclude: 'node_modules/**',
59 | }),
60 | ];
61 | }
62 |
63 | exports.name = '<%=umdname%>';
64 | exports.banner = banner;
65 | exports.getCompiler = getCompiler;
66 |
--------------------------------------------------------------------------------
/packages/cli/bin/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const fs = require('fs');
3 | const path = require('path');
4 | const yargs = require('yargs');
5 |
6 | const log = require('../util/log');
7 |
8 | const { runInitPrompts } = require('./run-prompts');
9 | const { checkProjectExists } = require('../util/file');
10 | const { init } = require('./init');
11 | const { update } = require('./update');
12 |
13 | log.init();
14 |
15 | yargs
16 | .usage('usage: jslib [options]')
17 | .usage('usage: jslib [options]')
18 | .example('jslib new myproject', 'Create a new project myproject')
19 | .alias('h', 'help')
20 | .alias('v', 'version')
21 | .command(
22 | ['new', 'n'],
23 | 'Create a new project',
24 | function (yargs) {
25 | return yargs
26 | .option('force', {
27 | alias: 'f',
28 | describe: 'Force create',
29 | })
30 | .option('config', {
31 | alias: 'c',
32 | describe: 'Initialize only the configuration file',
33 | })
34 | .option('npmname', {
35 | alias: 'n',
36 | describe: 'Initialize the npm package name',
37 | })
38 | .option('umdname', {
39 | alias: 'umd',
40 | describe: 'Initialize the UMD name for package',
41 | })
42 | .option('username', {
43 | alias: 'u',
44 | describe: 'Initialize the username',
45 | })
46 | .option('type', {
47 | alias: 't',
48 | describe: 'Initialize the js/ts selection',
49 | })
50 | .option('manager', {
51 | alias: 'm',
52 | describe: 'Select the package management method',
53 | });
54 | },
55 | function (argv) {
56 | runInitPrompts(argv._[1], yargs.argv).then(function (answers) {
57 | init(argv, answers);
58 | });
59 | },
60 | )
61 | .command(['update', 'u'], 'Update a project', function (_yargs) {
62 | if (!checkProjectExists(process.cwd(), 'jslib.json')) {
63 | console.error(
64 | 'error: This is not a jslib library, missing jslib.json file',
65 | );
66 | return;
67 | }
68 |
69 | const json = JSON.parse(
70 | fs.readFileSync(path.resolve(process.cwd(), 'jslib.json'), {
71 | encoding: 'utf8',
72 | }),
73 | );
74 |
75 | update(json);
76 | })
77 | .demandCommand()
78 | .epilog('copyright 2018-2025').argv;
79 |
--------------------------------------------------------------------------------
/.github/workflows/check-publish.yml:
--------------------------------------------------------------------------------
1 | name: Manual Check Publish
2 |
3 | on:
4 | workflow_dispatch: # 使得该工作流可以通过 GitHub UI 手动触发
5 | inputs:
6 | npm-package:
7 | description: 'Specify the npm package version (default: latest)'
8 | required: false
9 | default: 'latest' # 默认 npm 包版本为 'latest'
10 |
11 | jobs:
12 | test-jslib-js:
13 | name: Test jslib with JS projects
14 | runs-on: ubuntu-latest # 在 Ubuntu 上运行
15 |
16 | strategy:
17 | matrix:
18 | node-version: [18, 20, 22] # 测试不同的 Node.js 版本
19 |
20 | steps:
21 | - name: Set up Node.js ${{ matrix.node-version }}
22 | uses: actions/setup-node@v3
23 | with:
24 | node-version: ${{ matrix.node-version }} # 使用不同的 Node.js 版本
25 |
26 | - name: Create new JS project
27 | run: echo js-project | npx @js-lib/cli@${{ github.event.inputs.npm-package }} new --npmname js-project --umdname js-project --username yanhaijing --type js --manager npm
28 |
29 | - name: Run lint in JS project
30 | working-directory: ./js-project
31 | run: npm run lint
32 |
33 | - name: Run tests in JS project
34 | working-directory: ./js-project
35 | run: npm run test
36 |
37 | - name: Build JS project
38 | working-directory: ./js-project
39 | run: npm run build
40 |
41 | - name: Update JS project
42 | working-directory: ./js-project
43 | run: npx @js-lib/cli@${{ github.event.inputs.npm-package }} update
44 |
45 | test-jslib-ts:
46 | name: Test jslib with TS projects
47 | runs-on: ubuntu-latest # 在 Ubuntu 上运行
48 |
49 | strategy:
50 | matrix:
51 | node-version: [18, 20, 22] # 测试不同的 Node.js 版本
52 |
53 | steps:
54 | - name: Set up Node.js ${{ matrix.node-version }}
55 | uses: actions/setup-node@v3
56 | with:
57 | node-version: ${{ matrix.node-version }} # 使用不同的 Node.js 版本
58 |
59 | - name: Create new TS project
60 | run: echo ts-project | npx @js-lib/cli@${{ github.event.inputs.npm-package }} new --npmname ts-project --umdname ts-project --username yanhaijing --type ts --manager npm
61 |
62 | - name: Run lint in JS project
63 | working-directory: ./ts-project
64 | run: npm run lint
65 |
66 | - name: Run tests in JS project
67 | working-directory: ./ts-project
68 | run: npm run test
69 |
70 | - name: Build JS project
71 | working-directory: ./ts-project
72 | run: npm run build
73 |
74 | - name: Update JS project
75 | working-directory: ./ts-project
76 | run: npx @js-lib/cli@${{ github.event.inputs.npm-package }} update
77 |
--------------------------------------------------------------------------------
/packages/cli/bin/run-prompts.js:
--------------------------------------------------------------------------------
1 | const inquirer = require('inquirer');
2 | const validate = require('validate-npm-package-name');
3 |
4 | function prompts(promptList) {
5 | return new Promise(function (resolve) {
6 | return inquirer.prompt(promptList).then((answers) => {
7 | resolve(answers);
8 | });
9 | });
10 | }
11 |
12 | let promptList = [];
13 |
14 | function runInitPrompts(pathname, argv) {
15 | const { npmname, umdname, username, type, manager } = argv;
16 |
17 | promptList.push({
18 | type: 'input',
19 | message: 'project name:',
20 | name: 'name',
21 | default: pathname,
22 | validate: function (val) {
23 | if (!val) {
24 | return 'Please enter name';
25 | }
26 | return true;
27 | },
28 | });
29 |
30 | if (!npmname) {
31 | promptList.push({
32 | type: 'input',
33 | message: 'npm package name:',
34 | name: 'npmname',
35 | default: pathname,
36 | validate: function (val) {
37 | if (!validate(val).validForNewPackages) {
38 | return 'Forbidden npm name';
39 | }
40 | return true;
41 | },
42 | });
43 | }
44 | if (!umdname) {
45 | promptList.push({
46 | type: 'input',
47 | message: 'UMD name for package:',
48 | name: 'umdname',
49 | default: pathname,
50 | validate: function (val) {
51 | if (!val) {
52 | return 'Please enter name';
53 | }
54 | return true;
55 | },
56 | });
57 | }
58 | if (!username) {
59 | promptList.push({
60 | type: 'input',
61 | message: 'github user name:',
62 | name: 'username',
63 | validate: function (val) {
64 | if (!val) {
65 | return 'Please enter name';
66 | }
67 | return true;
68 | },
69 | });
70 | }
71 | if (!type) {
72 | promptList.push({
73 | type: 'list',
74 | message: 'select template:',
75 | name: 'type',
76 | choices: ['JavaScript', 'TypeScript'],
77 | filter: function (value) {
78 | return {
79 | TypeScript: 'ts',
80 | JavaScript: 'js',
81 | }[value];
82 | },
83 | });
84 | }
85 | if (!manager) {
86 | promptList.push({
87 | type: 'list',
88 | message: 'package manager:',
89 | name: 'manager',
90 | choices: ['npm', 'no install'],
91 | filter: function (value) {
92 | return {
93 | npm: 'npm',
94 | 'no install': null,
95 | }[value];
96 | },
97 | });
98 | }
99 | return prompts(promptList);
100 | }
101 |
102 | exports.runInitPrompts = runInitPrompts;
103 |
--------------------------------------------------------------------------------
/packages/cli/module-js/root.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const {
3 | copyDir,
4 | copyFile,
5 | copyTmpl,
6 | deleteFile,
7 | replaceFileLine,
8 | deleteFileLine,
9 | } = require('../util/copy');
10 | const log = require('../util/log');
11 |
12 | log.init();
13 |
14 | function init(cmdPath, name, option) {
15 | console.log('root: init');
16 |
17 | copyDir(
18 | path.resolve(__dirname, `./template/base`),
19 | path.resolve(cmdPath, name),
20 | {
21 | mode: true,
22 | },
23 | );
24 | copyTmpl(
25 | path.resolve(__dirname, `./template/.gitignore.tmpl`),
26 | path.resolve(cmdPath, name, './.gitignore'),
27 | );
28 | copyTmpl(
29 | path.resolve(__dirname, `./template/license.tmpl`),
30 | path.resolve(cmdPath, name, './LICENSE'),
31 | option,
32 | );
33 | copyTmpl(
34 | path.resolve(__dirname, `./template/README.en.md.tmpl`),
35 | path.resolve(cmdPath, name, './README.md'),
36 | option,
37 | );
38 | copyTmpl(
39 | path.resolve(__dirname, `./template/README.zh.md.tmpl`),
40 | path.resolve(cmdPath, name, './README.zh.md'),
41 | option,
42 | );
43 | }
44 |
45 | function update(cmdPath, option) {
46 | console.log('root: update');
47 | copyFile(
48 | path.resolve(__dirname, `./template/base/.editorconfig`),
49 | path.resolve(cmdPath, '.editorconfig'),
50 | );
51 |
52 | copyFile(
53 | path.resolve(__dirname, `./template/base/.vscode/extensions.json`),
54 | path.resolve(cmdPath, '.vscode/extensions.json'),
55 | );
56 |
57 | copyFile(
58 | path.resolve(__dirname, `./template/base/.vscode/settings.json`),
59 | path.resolve(cmdPath, '.vscode/settings.json'),
60 | );
61 |
62 | copyFile(
63 | path.resolve(__dirname, `./template/base/.github/FUNDING.yml`),
64 | path.resolve(cmdPath, '.github/FUNDING.yml'),
65 | );
66 |
67 | copyFile(
68 | path.resolve(__dirname, `./template/base/.github/workflows/ci.yml`),
69 | path.resolve(cmdPath, '.github/workflows/ci.yml'),
70 | );
71 |
72 | copyFile(
73 | path.resolve(__dirname, `./template/base/.github/workflows/release.yml`),
74 | path.resolve(cmdPath, '.github/workflows/release.yml'),
75 | );
76 |
77 | copyTmpl(
78 | path.resolve(__dirname, `./template/.gitignore.tmpl`),
79 | path.resolve(cmdPath, './.gitignore'),
80 | );
81 |
82 | // 删除 1.x 版本的无用数据
83 | deleteFile(path.resolve(cmdPath, '.travis.yml'));
84 | replaceFileLine(
85 | path.resolve(cmdPath, 'README.md'),
86 | /\[Build Status\]/,
87 | `[](https://github.com/${option.username}/${option.name}/actions/workflows/ci.yml)`,
88 | );
89 | deleteFileLine(path.resolve(cmdPath, 'README.md'), /\[Coveralls\]/);
90 | }
91 |
92 | module.exports = {
93 | init: init,
94 | update: update,
95 | };
96 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/root.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const {
3 | copyDir,
4 | copyFile,
5 | copyTmpl,
6 | deleteFile,
7 | replaceFileLine,
8 | deleteFileLine,
9 | } = require('../util/copy');
10 | const log = require('../util/log');
11 |
12 | log.init();
13 |
14 | function init(cmdPath, name, option) {
15 | console.log('root: init');
16 |
17 | copyDir(
18 | path.resolve(__dirname, `./template/base`),
19 | path.resolve(cmdPath, name),
20 | {
21 | mode: true,
22 | },
23 | );
24 | copyTmpl(
25 | path.resolve(__dirname, `./template/.gitignore.tmpl`),
26 | path.resolve(cmdPath, name, './.gitignore'),
27 | );
28 | copyTmpl(
29 | path.resolve(__dirname, `./template/license.tmpl`),
30 | path.resolve(cmdPath, name, './LICENSE'),
31 | option,
32 | );
33 | copyTmpl(
34 | path.resolve(__dirname, `./template/README.en.md.tmpl`),
35 | path.resolve(cmdPath, name, './README.md'),
36 | option,
37 | );
38 | copyTmpl(
39 | path.resolve(__dirname, `./template/README.zh.md.tmpl`),
40 | path.resolve(cmdPath, name, './README.zh.md'),
41 | option,
42 | );
43 | }
44 |
45 | function update(cmdPath, option) {
46 | console.log('root: update');
47 | copyFile(
48 | path.resolve(__dirname, `./template/base/.editorconfig`),
49 | path.resolve(cmdPath, '.editorconfig'),
50 | );
51 |
52 | copyFile(
53 | path.resolve(__dirname, `./template/base/.vscode/extensions.json`),
54 | path.resolve(cmdPath, '.vscode/extensions.json'),
55 | );
56 |
57 | copyFile(
58 | path.resolve(__dirname, `./template/base/.vscode/settings.json`),
59 | path.resolve(cmdPath, '.vscode/settings.json'),
60 | );
61 |
62 | copyFile(
63 | path.resolve(__dirname, `./template/base/.github/FUNDING.yml`),
64 | path.resolve(cmdPath, '.github/FUNDING.yml'),
65 | );
66 |
67 | copyFile(
68 | path.resolve(__dirname, `./template/base/.github/workflows/ci.yml`),
69 | path.resolve(cmdPath, '.github/workflows/ci.yml'),
70 | );
71 |
72 | copyFile(
73 | path.resolve(__dirname, `./template/base/.github/workflows/release.yml`),
74 | path.resolve(cmdPath, '.github/workflows/release.yml'),
75 | );
76 |
77 | copyTmpl(
78 | path.resolve(__dirname, `./template/.gitignore.tmpl`),
79 | path.resolve(cmdPath, './.gitignore'),
80 | );
81 |
82 | // 删除 1.x 版本的无用数据
83 | deleteFile(path.resolve(cmdPath, '.travis.yml'));
84 | replaceFileLine(
85 | path.resolve(cmdPath, 'README.md'),
86 | /\[Build Status\]/,
87 | `[](https://github.com/${option.username}/${option.name}/actions/workflows/ci.yml)`,
88 | );
89 | deleteFileLine(path.resolve(cmdPath, 'README.md'), /\[Coveralls\]/);
90 | }
91 |
92 | module.exports = {
93 | init: init,
94 | update: update,
95 | };
96 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/README.zh.md.tmpl:
--------------------------------------------------------------------------------
1 | # [<%=name%>](https://github.com/<%=username%>/<%=name%>)
2 | [](https://github.com/yanhaijing/jslib-base)
3 | [](https://github.com/<%=username%>/<%=name%>/blob/master/LICENSE)
4 | [](https://github.com/<%=username%>/<%=name%>/actions/workflows/ci.yml)
5 | [](https://www.npmjs.com/package/<%=npmname%>)
6 | [](http://www.npmtrends.com/<%=npmname%>)
7 | [](http://isitmaintained.com/project/<%=username%>/<%=name%> "Percentage of issues still open")
8 |
9 | 最好用的 `JS|TS` 第三方库脚手架
10 |
11 | ## :star: 特性
12 |
13 | - 支持ES6+或TypeScript编写源码,编译生成生产代码
14 | - 多环境支持(支持浏览器原生,支持AMD,CMD,支持Webpack,Rollup,fis等,支持Node)
15 | - 集成[jsmini](https://github.com/jsmini)
16 |
17 | > 注意: 如果不同时使用 `export` 与 `export default` 可打开 `legacy模式`,`legacy模式` 下的模块系统可以兼容 `ie6-8`,见rollup配置文件
18 |
19 | ## :pill: 兼容性
20 | 单元测试保证支持如下环境:
21 |
22 | | IE | CH | FF | SF | OP | IOS | Android | Node |
23 | | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
24 | | 11+ | 100+ | 100+ | 16+ | 100+ | 10.3+ | 4.1+ | 14+ |
25 |
26 | **注意:编译代码依赖ES5环境,对于ie6-8需要引入[es5-shim](http://github.com/es-shims/es5-shim/)才可以兼容,可以查看[demo/demo-global.html](./demo/demo-global.html)中的例子**
27 |
28 | ## :open_file_folder: 目录介绍
29 |
30 | ```
31 | .
32 | ├── demo 使用demo
33 | ├── dist 编译产出代码
34 | ├── doc 项目文档
35 | ├── src 源代码目录
36 | ├── test 单元测试
37 | ├── CHANGELOG.md 变更日志
38 | └── TODO.md 计划功能
39 | ```
40 |
41 | ## :rocket: 使用者指南
42 |
43 | 通过npm下载安装代码
44 |
45 | ```bash
46 | $ npm install --save <%=npmname%>
47 | ```
48 |
49 | 如果你是node环境
50 |
51 | ```js
52 | const <%=umdname%> = require('<%=npmname%>');
53 | ```
54 |
55 | 如果你是webpack等环境
56 |
57 | ```js
58 | import <%=umdname%> from '<%=npmname%>';
59 | ```
60 |
61 | 如果你是浏览器环境
62 |
63 | ```html
64 |
65 | ```
66 |
67 | ## :bookmark_tabs: 文档
68 | [API](./doc/api.md)
69 |
70 | ## :kissing_heart: 贡献者指南
71 | 首次运行需要先安装依赖
72 |
73 | ```bash
74 | $ npm install
75 | ```
76 |
77 | 一键打包生成生产代码
78 |
79 | ```bash
80 | $ npm run build
81 | ```
82 |
83 | 运行单元测试:
84 |
85 | ```bash
86 | $ npm test
87 | ```
88 |
89 | > 注意:浏览器环境需要手动测试,位于`test/browser`
90 |
91 | 修改 package.json 中的版本号,修改 README.md 中的版本号,修改 CHANGELOG.md,然后发布新版
92 |
93 | ```bash
94 | $ npm run release
95 | ```
96 |
97 | 将新版本发布到npm
98 |
99 | ```bash
100 | $ npm publish
101 | ```
102 |
103 | ## 贡献者列表
104 |
105 | [contributors](https://github.com/<%=username%>/<%=name%>/graphs/contributors)
106 |
107 | ## :gear: 更新日志
108 | [CHANGELOG.md](./CHANGELOG.md)
109 |
110 | ## :airplane: 计划列表
111 | [TODO.md](./TODO.md)
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/README.zh.md.tmpl:
--------------------------------------------------------------------------------
1 | # [<%=name%>](https://github.com/<%=username%>/<%=name%>)
2 | [](https://github.com/yanhaijing/jslib-base)
3 | [](https://github.com/<%=username%>/<%=name%>/blob/master/LICENSE)
4 | [](https://github.com/<%=username%>/<%=name%>/actions/workflows/ci.yml)
5 | [](https://www.npmjs.com/package/<%=npmname%>)
6 | [](http://www.npmtrends.com/<%=npmname%>)
7 | [](http://isitmaintained.com/project/<%=username%>/<%=name%> "Percentage of issues still open")
8 |
9 | 最好用的 `JS|TS` 第三方库脚手架
10 |
11 | ## :star: 特性
12 |
13 | - 支持ES6+或TypeScript编写源码,编译生成生产代码
14 | - 多环境支持(支持浏览器原生,支持AMD,CMD,支持Webpack,Rollup,fis等,支持Node)
15 | - 集成[jsmini](https://github.com/jsmini)
16 |
17 | > 注意: 如果不同时使用 `export` 与 `export default` 可打开 `legacy模式`,`legacy模式` 下的模块系统可以兼容 `ie6-8`,见rollup配置文件
18 |
19 | ## :pill: 兼容性
20 | 单元测试保证支持如下环境:
21 |
22 | | IE | CH | FF | SF | OP | IOS | Android | Node |
23 | | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
24 | | 11+ | 100+ | 100+ | 16+ | 100+ | 10.3+ | 4.1+ | 14+ |
25 |
26 | **注意:编译代码依赖ES5环境,对于ie6-8需要引入[es5-shim](http://github.com/es-shims/es5-shim/)才可以兼容,可以查看[demo/demo-global.html](./demo/demo-global.html)中的例子**
27 |
28 | ## :open_file_folder: 目录介绍
29 |
30 | ```
31 | .
32 | ├── demo 使用demo
33 | ├── dist 编译产出代码
34 | ├── doc 项目文档
35 | ├── src 源代码目录
36 | ├── test 单元测试
37 | ├── CHANGELOG.md 变更日志
38 | └── TODO.md 计划功能
39 | ```
40 |
41 | ## :rocket: 使用者指南
42 |
43 | 通过npm下载安装代码
44 |
45 | ```bash
46 | $ npm install --save <%=npmname%>
47 | ```
48 |
49 | 如果你是node环境
50 |
51 | ```js
52 | const <%=umdname%> = require('<%=npmname%>');
53 | ```
54 |
55 | 如果你是webpack等环境
56 |
57 | ```js
58 | import <%=umdname%> from '<%=npmname%>';
59 | ```
60 |
61 | 如果你是浏览器环境
62 |
63 | ```html
64 |
65 | ```
66 |
67 | ## :bookmark_tabs: 文档
68 | [API](./doc/api.md)
69 |
70 | ## :kissing_heart: 贡献者指南
71 | 首次运行需要先安装依赖
72 |
73 | ```bash
74 | $ npm install
75 | ```
76 |
77 | 一键打包生成生产代码
78 |
79 | ```bash
80 | $ npm run build
81 | ```
82 |
83 | 运行单元测试:
84 |
85 | ```bash
86 | $ npm test
87 | ```
88 |
89 | > 注意:浏览器环境需要手动测试,位于`test/browser`
90 |
91 | 修改 package.json 中的版本号,修改 README.md 中的版本号,修改 CHANGELOG.md,然后发布新版
92 |
93 | ```bash
94 | $ npm run release
95 | ```
96 |
97 | 将新版本发布到npm
98 |
99 | ```bash
100 | $ npm publish
101 | ```
102 |
103 | ## 贡献者列表
104 |
105 | [contributors](https://github.com/<%=username%>/<%=name%>/graphs/contributors)
106 |
107 | ## :gear: 更新日志
108 | [CHANGELOG.md](./CHANGELOG.md)
109 |
110 | ## :airplane: 计划列表
111 | [TODO.md](./TODO.md)
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI for jslib
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | pull_request:
8 | branches:
9 | - master
10 |
11 | jobs:
12 | lint:
13 | name: Run Lint on jslib-base
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout repository
17 | uses: actions/checkout@v3
18 |
19 | - name: Setup Node.js
20 | uses: actions/setup-node@v3
21 | with:
22 | node-version: 18
23 |
24 | - name: Install dependencies with Yarn
25 | run: yarn install
26 |
27 | - name: Run Lint
28 | run: yarn lint
29 |
30 | test-jslib-js:
31 | needs: lint
32 | name: Test jslib with JS projects
33 | runs-on: ubuntu-latest
34 | strategy:
35 | matrix:
36 | node-version: [18, 20, 22]
37 | steps:
38 | - name: Checkout repository
39 | uses: actions/checkout@v3
40 |
41 | - name: Setup Node.js
42 | uses: actions/setup-node@v3
43 | with:
44 | node-version: '${{ matrix.node-version }}'
45 |
46 | - name: Install jslib globally
47 | run: yarn install
48 |
49 | - name: Link jslib globally
50 | working-directory: packages/cli
51 | run: npm link
52 |
53 | - name: Create new JS project
54 | working-directory: ../
55 | run: echo js-project | jslib new --npmname js-project --umdname js-project --username yanhaijing --type js --manager npm
56 |
57 | - name: Run lint in JS project
58 | working-directory: ../js-project
59 | run: npm run lint
60 |
61 | - name: Run tests in JS project
62 | working-directory: ../js-project
63 | run: npm run test
64 |
65 | - name: Build JS project
66 | working-directory: ../js-project
67 | run: npm run build
68 |
69 | - name: Update JS project
70 | working-directory: ../js-project
71 | run: jslib update
72 |
73 | test-jslib-ts:
74 | needs: lint
75 | name: Test jslib with TS projects
76 | runs-on: ubuntu-latest
77 | strategy:
78 | matrix:
79 | node-version: [18, 20, 22]
80 | steps:
81 | - name: Checkout repository
82 | uses: actions/checkout@v3
83 |
84 | - name: Setup Node.js
85 | uses: actions/setup-node@v3
86 | with:
87 | node-version: '${{ matrix.node-version }}'
88 |
89 | - name: Install jslib globally
90 | run: yarn install
91 |
92 | - name: Link jslib globally
93 | working-directory: packages/cli
94 | run: npm link
95 |
96 | - name: Create new TS project
97 | working-directory: ../
98 | run: echo ts-project | jslib new --npmname ts-project --umdname ts-project --username yanhaijing --type ts --manager npm
99 |
100 | - name: Run lint in TS project
101 | working-directory: ../ts-project
102 | run: npm run lint
103 |
104 | - name: Run tests in TS project
105 | working-directory: ../ts-project
106 | run: npm run test
107 |
108 | - name: Build TS project
109 | working-directory: ../ts-project
110 | run: npm run build
111 |
112 | - name: Update TS project
113 | working-directory: ../ts-project
114 | run: jslib update
115 |
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jslibnpmname",
3 | "version": "0.1.0",
4 | "description": "The best third party JS|TS library scaffold",
5 | "sideEffects": false,
6 | "main": "dist/index.js",
7 | "module": "dist/index.esm.js",
8 | "exports": {
9 | "node": {
10 | "import": "./dist/index.mjs",
11 | "default": "./dist/index.js"
12 | },
13 | "default": {
14 | "import": "./dist/index.mjs",
15 | "default": "./dist/index.js"
16 | }
17 | },
18 | "scripts": {
19 | "preinstall": "npx only-allow npm",
20 | "clean": "rimraf ./dist",
21 | "start": "http-server -p 3000 -c-1",
22 | "test": "cross-env NODE_ENV=test nyc mocha",
23 | "release": "npm test && npm run build && git commit -am \"build: $npm_package_version\" && git tag $npm_package_version && git push && git push --tags",
24 | "lint": "eslint -c .eslintrc.cjs 'src/**/*.js'",
25 | "lint:fix": "eslint --fix -c .eslintrc.cjs 'src/**/*.js' --fix",
26 | "prepare": "husky install",
27 | "ci": "commit",
28 | "cz": "git-cz",
29 | "build:self": "rollup -c config/rollup.config.cjs",
30 | "build:esm": "rollup -c config/rollup.config.esm.cjs",
31 | "build:aio": "rollup -c config/rollup.config.aio.cjs",
32 | "build": "npm run clean && npm run build:self && npm run build:esm && npm run build:aio",
33 | "coveralls": "nyc report --reporter=text-lcov | coveralls"
34 | },
35 | "author": "jslibusername",
36 | "license": "MIT",
37 | "repository": {
38 | "type": "git",
39 | "url": "git://github.com/jslibusername/jslibname.git"
40 | },
41 | "bugs": {
42 | "url": "https://github.com/jslibusername/jslibname/issues"
43 | },
44 | "files": [
45 | "/dist",
46 | "/types",
47 | "*.d.ts"
48 | ],
49 | "engines": {
50 | "node": ">=14.0.0",
51 | "npm": ">=6.0.0"
52 | },
53 | "publishConfig": {
54 | "registry": "https://registry.npmjs.org",
55 | "access": "public"
56 | },
57 | "devDependencies": {
58 | "@babel/eslint-parser": "^7.23.3",
59 | "@babel/plugin-transform-runtime": "^7.23.3",
60 | "@babel/preset-env": "^7.23.3",
61 | "@babel/register": "^7.22.15",
62 | "@commitlint/cli": "^18.6.1",
63 | "@commitlint/config-conventional": "^18.6.3",
64 | "@commitlint/cz-commitlint": "^18.6.1",
65 | "@commitlint/format": "^18.6.1",
66 | "@commitlint/prompt-cli": "^18.6.1",
67 | "@js-lib/cli": "^3.0.5",
68 | "@rollup/plugin-babel": "^6.0.4",
69 | "@rollup/plugin-commonjs": "^28.0.2",
70 | "@rollup/plugin-node-resolve": "^16.0.0",
71 | "@rollup/plugin-terser": "^0.4.4",
72 | "babel-plugin-istanbul": "^7.0.0",
73 | "commitizen": "^4.3.1",
74 | "coveralls": "^3.1.1",
75 | "cross-env": "^7.0.3",
76 | "es5-shim": "^4.6.7",
77 | "eslint": "^8.57.1",
78 | "eslint-config-prettier": "^9.1.0",
79 | "eslint-plugin-import": "^2.31.0",
80 | "eslint-plugin-prettier": "^5.2.1",
81 | "expect.js": "^0.3.1",
82 | "http-server": "^14.1.1",
83 | "husky": "^8.0.3",
84 | "lint-staged": "^15.3.0",
85 | "mocha": "^10.8.2",
86 | "nyc": "^17.1.0",
87 | "prettier": "3.4.2",
88 | "rimraf": "^5.0.10",
89 | "rollup": "^4.30.0"
90 | },
91 | "dependencies": {
92 | "@babel/runtime-corejs3": "^7.26.0"
93 | },
94 | "config": {
95 | "commitizen": {
96 | "path": "@commitlint/cz-commitlint"
97 | }
98 | }
99 | }
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tslibname",
3 | "version": "0.1.0",
4 | "description": "The best third party JS|TS library scaffold",
5 | "sideEffects": false,
6 | "main": "dist/index.js",
7 | "module": "dist/index.esm.js",
8 | "exports": {
9 | "node": {
10 | "import": "./dist/index.mjs",
11 | "default": "./dist/index.js"
12 | },
13 | "default": {
14 | "import": "./dist/index.mjs",
15 | "default": "./dist/index.js"
16 | }
17 | },
18 | "types": "./types/index.d.ts",
19 | "scripts": {
20 | "preinstall": "npx only-allow npm",
21 | "clean": "rimraf ./dist ./types",
22 | "start": "http-server -p 3000 -c-1",
23 | "test": "nyc mocha",
24 | "release": "npm test && npm run build && git commit -am \"build: $npm_package_version\" && git tag $npm_package_version && git push && git push --tags",
25 | "lint": "eslint -c .eslintrc.cjs 'src/**/*.ts'",
26 | "lint:fix": "eslint --fix -c .eslintrc.cjs 'src/**/*.ts' --fix",
27 | "prepare": "husky install",
28 | "ci": "commit",
29 | "cz": "git-cz",
30 | "build:self": "rollup -c config/rollup.config.cjs",
31 | "build:esm": "rollup -c config/rollup.config.esm.cjs",
32 | "build:aio": "rollup -c config/rollup.config.aio.cjs",
33 | "build": "npm run clean && npm run build:self && npm run build:esm && npm run build:aio",
34 | "coveralls": "nyc report --reporter=text-lcov | coveralls"
35 | },
36 | "author": "tslibusername",
37 | "license": "MIT",
38 | "repository": {
39 | "type": "git",
40 | "url": "git://github.com/tslibusername/tslibname.git"
41 | },
42 | "bugs": {
43 | "url": "https://github.com/tslibusername/tslibname/issues"
44 | },
45 | "files": [
46 | "/dist",
47 | "/types",
48 | "*.d.ts"
49 | ],
50 | "engines": {
51 | "node": ">=14.0.0",
52 | "npm": ">=6.0.0"
53 | },
54 | "publishConfig": {
55 | "registry": "https://registry.npmjs.org",
56 | "access": "public"
57 | },
58 | "devDependencies": {
59 | "@js-lib/cli": "^3.0.5",
60 | "cross-env": "^7.0.3",
61 | "rimraf": "^5.0.10",
62 | "http-server": "^14.1.1",
63 | "es5-shim": "^4.6.7",
64 | "@babel/plugin-transform-runtime": "^7.25.9",
65 | "@babel/preset-env": "^7.26.0",
66 | "@jsmini/extend": "^0.5.0",
67 | "@rollup/plugin-babel": "^6.0.4",
68 | "@rollup/plugin-commonjs": "^28.0.2",
69 | "@rollup/plugin-node-resolve": "^16.0.0",
70 | "@rollup/plugin-terser": "^0.4.4",
71 | "rollup": "^4.30.0",
72 | "rollup-plugin-typescript2": "^0.36.0",
73 | "tslib": "^2.8.1",
74 | "typescript": "^5.7.2",
75 | "eslint": "^8.57.1",
76 | "eslint-config-prettier": "^9.1.0",
77 | "eslint-plugin-import": "^2.31.0",
78 | "eslint-plugin-prettier": "^5.2.1",
79 | "husky": "^8.0.3",
80 | "lint-staged": "^15.3.0",
81 | "prettier": "3.4.2",
82 | "commitizen": "^4.3.1",
83 | "@commitlint/cli": "^18.6.1",
84 | "@commitlint/config-conventional": "^18.6.3",
85 | "@commitlint/cz-commitlint": "^18.6.1",
86 | "@commitlint/format": "^18.6.1",
87 | "@commitlint/prompt-cli": "^18.6.1",
88 | "@typescript-eslint/eslint-plugin": "^8.19.0",
89 | "@typescript-eslint/parser": "^8.19.0",
90 | "babel-plugin-istanbul": "^7.0.0",
91 | "coveralls": "^3.1.1",
92 | "expect.js": "^0.3.1",
93 | "mocha": "^10.2.0",
94 | "nyc": "^17.1.0",
95 | "source-map-support": "^0.5.21",
96 | "ts-node": "^10.9.2"
97 | },
98 | "dependencies": {
99 | "@babel/runtime-corejs3": "^7.26.0"
100 | },
101 | "config": {
102 | "commitizen": {
103 | "path": "@commitlint/cz-commitlint"
104 | }
105 | }
106 | }
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/README.md:
--------------------------------------------------------------------------------
1 | # [tslibname](https://github.com/tslibusername/tslibname)
2 | [](https://github.com/tslibusername/jslib-base)
3 | [](https://github.com/tslibusername/tslibname/blob/master/LICENSE)
4 | [](https://github.com/tslibusername/tslibname/actions/workflows/ci.yml)
5 | [](https://www.npmjs.com/package/tslibname)
6 | [](http://www.npmtrends.com/tslibname)
7 | [](http://isitmaintained.com/project/tslibusername/tslibname "Percentage of issues still open")
8 |
9 | The best third party `JS|TS` library scaffold.
10 |
11 | ## Characteristics
12 |
13 | - Coded in ES6+ or TypeScript, easily compile and generate production code
14 | - Supports multi environment, including default browsers, Node, AMD, CMD, Webpack, Rollup, Fis and so on.
15 | - Integrated [jsmini](https://github.com/jsmini)
16 |
17 | **Note:** When `export` and `export default` are not used at the same time, there is the option to
18 | turn on `legacy mode`. Under `legacy mode`, the module system can be compatible with `IE6-8`. For more information on legacy mode,
19 | please see rollup supplemental file.
20 |
21 | ## Compatibility
22 | Unit tests guarantee support on the following environment:
23 |
24 | | IE | CH | FF | SF | OP | IOS | Android | Node |
25 | | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
26 | | 11+ | 100+ | 100+ | 16+ | 100+ | 10.3+ | 4.1+ | 14+ |
27 |
28 | > Note: Compiling code depend on ES5, so you need import [es5-shim](http://github.com/es-shims/es5-shim/) to compatible with `IE6-8`, here is a [demo](./demo/demo-global.html)
29 |
30 | ## Directory
31 | ```
32 | ├── demo - Using demo
33 | ├── dist - Compiler output code
34 | ├── doc - Project documents
35 | ├── src - Source code directory
36 | ├── test - Unit tests
37 | ├── CHANGELOG.md - Change log
38 | └── TODO.md - Planned features
39 | ```
40 |
41 | ## Usage Instructions
42 |
43 | Using npm, download and install the code.
44 |
45 | ```bash
46 | $ npm install --save tslibname
47 | ```
48 |
49 | For node environment:
50 |
51 | ```js
52 | const tslibname = require('tslibname');
53 | ```
54 |
55 | For webpack or similar environment:
56 |
57 | ```js
58 | import tslibname from 'tslibname';
59 | ```
60 |
61 | For browser environment:
62 |
63 | ```html
64 |
65 | ```
66 |
67 | ## Documents
68 | [API](./doc/api.md)
69 |
70 | ## Contribution Guide
71 | For the first time to run, you need to install dependencies firstly.
72 |
73 | ```bash
74 | $ npm install
75 | ```
76 |
77 | To build the project:
78 |
79 | ```bash
80 | $ npm run build
81 | ```
82 |
83 | To run unit tests:
84 |
85 | ```bash
86 | $ npm test
87 | ```
88 |
89 | > Note: The browser environment needs to be tested manually under ```test/browser```
90 |
91 | Modify the version number in package.json, modify the version number in README.md, modify the CHANGELOG.md, and then release the new version.
92 |
93 | ```bash
94 | $ npm run release
95 | ```
96 |
97 | Publish the new version to NPM.
98 |
99 | ```bash
100 | $ npm publish
101 | ```
102 |
103 | ## Contributors
104 |
105 | [contributors](https://github.com/tslibusername/tslibname/graphs/contributors)
106 |
107 | ## Change Log
108 | [CHANGELOG.md](./CHANGELOG.md)
109 |
110 | ## TODO
111 | [TODO.md](./TODO.md)
--------------------------------------------------------------------------------
/packages/cli/module-js/template/README.en.md.tmpl:
--------------------------------------------------------------------------------
1 | # [<%=name%>](https://github.com/<%=username%>/<%=name%>)
2 | [](https://github.com/yanhaijing/jslib-base)
3 | [](https://github.com/<%=username%>/<%=name%>/blob/master/LICENSE)
4 | [](https://github.com/<%=username%>/<%=name%>/actions/workflows/ci.yml)
5 | [](https://www.npmjs.com/package/<%=npmname%>)
6 | [](http://www.npmtrends.com/<%=npmname%>)
7 | [](http://isitmaintained.com/project/<%=username%>/<%=name%> "Percentage of issues still open")
8 |
9 | The best third party `JS|TS` library scaffold.
10 |
11 | ## Characteristics
12 |
13 | - Coded in ES6+ or TypeScript, easily compile and generate production code
14 | - Supports multi environment, including default browsers, Node, AMD, CMD, Webpack, Rollup, Fis and so on.
15 | - Integrated [jsmini](https://github.com/jsmini)
16 |
17 | **Note:** When `export` and `export default` are not used at the same time, there is the option to
18 | turn on `legacy mode`. Under `legacy mode`, the module system can be compatible with `IE6-8`. For more information on legacy mode,
19 | please see rollup supplemental file.
20 |
21 | ## Compatibility
22 | Unit tests guarantee support on the following environment:
23 |
24 | | IE | CH | FF | SF | OP | IOS | Android | Node |
25 | | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
26 | | 11+ | 100+ | 100+ | 16+ | 100+ | 10.3+ | 4.1+ | 14+ |
27 |
28 | > Note: Compiling code depend on ES5, so you need import [es5-shim](http://github.com/es-shims/es5-shim/) to compatible with `IE6-8`, here is a [demo](./demo/demo-global.html)
29 |
30 | ## Directory
31 | ```
32 | ├── demo - Using demo
33 | ├── dist - Compiler output code
34 | ├── doc - Project documents
35 | ├── src - Source code directory
36 | ├── test - Unit tests
37 | ├── CHANGELOG.md - Change log
38 | └── TODO.md - Planned features
39 | ```
40 |
41 | ## Usage Instructions
42 |
43 | Using npm, download and install the code.
44 |
45 | ```bash
46 | $ npm install --save <%=npmname%>
47 | ```
48 |
49 | For node environment:
50 |
51 | ```js
52 | const <%=umdname%> = require('<%=npmname%>');
53 | ```
54 |
55 | For webpack or similar environment:
56 |
57 | ```js
58 | import <%=umdname%> from '<%=npmname%>';
59 | ```
60 |
61 | For browser environment:
62 |
63 | ```html
64 |
65 | ```
66 |
67 | ## Documents
68 | [API](./doc/api.md)
69 |
70 | ## Contribution Guide
71 | For the first time to run, you need to install dependencies firstly.
72 |
73 | ```bash
74 | $ npm install
75 | ```
76 |
77 | To build the project:
78 |
79 | ```bash
80 | $ npm run build
81 | ```
82 |
83 | To run unit tests:
84 |
85 | ```bash
86 | $ npm test
87 | ```
88 |
89 | > Note: The browser environment needs to be tested manually under ```test/browser```
90 |
91 | Modify the version number in package.json, modify the version number in README.md, modify the CHANGELOG.md, and then release the new version.
92 |
93 | ```bash
94 | $ npm run release
95 | ```
96 |
97 | Publish the new version to NPM.
98 |
99 | ```bash
100 | $ npm publish
101 | ```
102 |
103 | ## Contributors
104 |
105 | [contributors](https://github.com/<%=username%>/<%=name%>/graphs/contributors)
106 |
107 | ## Change Log
108 | [CHANGELOG.md](./CHANGELOG.md)
109 |
110 | ## TODO
111 | [TODO.md](./TODO.md)
--------------------------------------------------------------------------------
/packages/cli/module-js/template/base/README.md:
--------------------------------------------------------------------------------
1 | # [jslibname](https://github.com/jslibusername/jslibname)
2 | [](https://github.com/yanhaijing/jslib-base)
3 | [](https://github.com/jslibusername/jslibname/blob/master/LICENSE)
4 | [](https://github.com/jslibusername/jslibname/actions/workflows/ci.yml)
5 | [](https://www.npmjs.com/package/jslibnpmname)
6 | [](http://www.npmtrends.com/jslibnpmname)
7 | [](http://isitmaintained.com/project/jslibusername/jslibname "Percentage of issues still open")
8 |
9 | The best third party `JS|TS` library scaffold.
10 |
11 | ## Characteristics
12 |
13 | - Coded in ES6+ or TypeScript, easily compile and generate production code
14 | - Supports multi environment, including default browsers, Node, AMD, CMD, Webpack, Rollup, Fis and so on.
15 | - Integrated [jsmini](https://github.com/jsmini)
16 |
17 | **Note:** When `export` and `export default` are not used at the same time, there is the option to
18 | turn on `legacy mode`. Under `legacy mode`, the module system can be compatible with `IE6-8`. For more information on legacy mode,
19 | please see rollup supplemental file.
20 |
21 | ## Compatibility
22 | Unit tests guarantee support on the following environment:
23 |
24 | | IE | CH | FF | SF | OP | IOS | Android | Node |
25 | | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
26 | | 11+ | 100+ | 100+ | 16+ | 100+ | 10.3+ | 4.1+ | 14+ |
27 |
28 | > Note: Compiling code depend on ES5, so you need import [es5-shim](http://github.com/es-shims/es5-shim/) to compatible with `IE6-8`, here is a [demo](./demo/demo-global.html)
29 |
30 | ## Directory
31 | ```
32 | ├── demo - Using demo
33 | ├── dist - Compiler output code
34 | ├── doc - Project documents
35 | ├── src - Source code directory
36 | ├── test - Unit tests
37 | ├── CHANGELOG.md - Change log
38 | └── TODO.md - Planned features
39 | ```
40 |
41 | ## Usage Instructions
42 |
43 | Using npm, download and install the code.
44 |
45 | ```bash
46 | $ npm install --save jslibnpmname
47 | ```
48 |
49 | For node environment:
50 |
51 | ```js
52 | const jslibumdname = require('jslibnpmname');
53 | ```
54 |
55 | For webpack or similar environment:
56 |
57 | ```js
58 | import jslibumdname from 'jslibnpmname';
59 | ```
60 |
61 | For browser environment:
62 |
63 | ```html
64 |
65 | ```
66 |
67 | ## Documents
68 | [API](./doc/api.md)
69 |
70 | ## Contribution Guide
71 | For the first time to run, you need to install dependencies firstly.
72 |
73 | ```bash
74 | $ npm install
75 | ```
76 |
77 | To build the project:
78 |
79 | ```bash
80 | $ npm run build
81 | ```
82 |
83 | To run unit tests:
84 |
85 | ```bash
86 | $ npm test
87 | ```
88 |
89 | > Note: The browser environment needs to be tested manually under ```test/browser```
90 |
91 | Modify the version number in package.json, modify the version number in README.md, modify the CHANGELOG.md, and then release the new version.
92 |
93 | ```bash
94 | $ npm run release
95 | ```
96 |
97 | Publish the new version to NPM.
98 |
99 | ```bash
100 | $ npm publish
101 | ```
102 |
103 | ## Contributors
104 |
105 | [contributors](https://github.com/jslibusername/jslibname/graphs/contributors)
106 |
107 | ## Change Log
108 | [CHANGELOG.md](./CHANGELOG.md)
109 |
110 | ## TODO
111 | [TODO.md](./TODO.md)
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/README.en.md.tmpl:
--------------------------------------------------------------------------------
1 | # [<%=name%>](https://github.com/<%=username%>/<%=name%>)
2 | [](https://github.com/yanhaijing/jslib-base)
3 | [](https://github.com/<%=username%>/<%=name%>/blob/master/LICENSE)
4 | [](https://github.com/<%=username%>/<%=name%>/actions/workflows/ci.yml)
5 | [](https://www.npmjs.com/package/<%=npmname%>)
6 | [](http://www.npmtrends.com/<%=npmname%>)
7 | [](http://isitmaintained.com/project/<%=username%>/<%=name%> "Percentage of issues still open")
8 |
9 | The best third party `JS|TS` library scaffold.
10 |
11 | ## Characteristics
12 |
13 | - Coded in ES6+ or TypeScript, easily compile and generate production code
14 | - Supports multi environment, including default browsers, Node, AMD, CMD, Webpack, Rollup, Fis and so on.
15 | - Integrated [jsmini](https://github.com/jsmini)
16 |
17 | **Note:** When `export` and `export default` are not used at the same time, there is the option to
18 | turn on `legacy mode`. Under `legacy mode`, the module system can be compatible with `IE6-8`. For more information on legacy mode,
19 | please see rollup supplemental file.
20 |
21 | ## Compatibility
22 | Unit tests guarantee support on the following environment:
23 |
24 | | IE | CH | FF | SF | OP | IOS | Android | Node |
25 | | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
26 | | 11+ | 100+ | 100+ | 16+ | 100+ | 10.3+ | 4.1+ | 14+ |
27 |
28 | > Note: Compiling code depend on ES5, so you need import [es5-shim](http://github.com/es-shims/es5-shim/) to compatible with `IE6-8`, here is a [demo](./demo/demo-global.html)
29 |
30 | ## Directory
31 | ```
32 | ├── demo - Using demo
33 | ├── dist - Compiler output code
34 | ├── doc - Project documents
35 | ├── src - Source code directory
36 | ├── test - Unit tests
37 | ├── CHANGELOG.md - Change log
38 | └── TODO.md - Planned features
39 | ```
40 |
41 | ## Usage Instructions
42 |
43 | Using npm, download and install the code.
44 |
45 | ```bash
46 | $ npm install --save <%=npmname%>
47 | ```
48 |
49 | For node environment:
50 |
51 | ```js
52 | const <%=umdname%> = require('<%=npmname%>');
53 | ```
54 |
55 | For webpack or similar environment:
56 |
57 | ```js
58 | import <%=umdname%> from '<%=npmname%>';
59 | ```
60 |
61 | For browser environment:
62 |
63 | ```html
64 |
65 | ```
66 |
67 | ## Documents
68 | [API](./doc/api.md)
69 |
70 | ## Contribution Guide
71 | For the first time to run, you need to install dependencies firstly.
72 |
73 | ```bash
74 | $ npm install
75 | ```
76 |
77 | To build the project:
78 |
79 | ```bash
80 | $ npm run build
81 | ```
82 |
83 | To run unit tests:
84 |
85 | ```bash
86 | $ npm test
87 | ```
88 |
89 | > Note: The browser environment needs to be tested manually under ```test/browser```
90 |
91 | Modify the version number in package.json, modify the version number in README.md, modify the CHANGELOG.md, and then release the new version.
92 |
93 | ```bash
94 | $ npm run release
95 | ```
96 |
97 | Publish the new version to NPM.
98 |
99 | ```bash
100 | $ npm publish
101 | ```
102 |
103 | ## Contributors
104 |
105 | [contributors](https://github.com/<%=username%>/<%=name%>/graphs/contributors)
106 |
107 | ## Change Log
108 | [CHANGELOG.md](./CHANGELOG.md)
109 |
110 | ## TODO
111 | [TODO.md](./TODO.md)
--------------------------------------------------------------------------------
/README.zh-CN.md:
--------------------------------------------------------------------------------
1 | # [jslib-base](https://github.com/yanhaijing/jslib-base)
2 |
3 | [](https://github.com/yanhaijing/jslib-base)
4 | [](https://github.com/yanhaijing/jslib-base/blob/master/LICENSE)
5 | [](https://www.npmjs.com/package/@js-lib/cli)
6 | [](http://www.npmtrends.com/@js-lib/cli)
7 | [](http://isitmaintained.com/project/yanhaijing/jslib-base 'Percentage of issues still open')
8 |
9 | [English](./README.md) | 简体中文
10 |
11 | 最好用的 `JS|TS` 第三方库脚手架,10 秒快速搭建一个 `JS|TS` 库的基础框架。
12 |
13 | **基于 jslib-base 的库,都可以分享到[jsmini](https://github.com/jsmini)平台**
14 |
15 | ## :star: 特性
16 |
17 | - 交互式新建命令行
18 | - 提供升级功能,老库一键升级
19 | - 支持 JavaScript 和 TypeScript 两种语言
20 | - 构建打包方案
21 | - typescript + babel + rollup
22 | - 第三方依赖自动注入(支持 tree shaking)
23 | - 多环境适配
24 | - 支持浏览器原生 script 使用
25 | - 提供 UMD, ESM 模块,支持 Webpack,Vite 等生态引用
26 | - 适配 Node.js 新旧模块,commonjs + ESM
27 | - 代码风格与校验(eslint + prettier + husky + lint-staged)
28 | - 单元测试套件(mocha + expect.js + istanbul + nyc + coveralls)
29 | - commit lint(commitlint + commitizen)
30 | - GitHub Actions (ci + release)
31 | - 本地服务器(http-server)
32 |
33 | ## :rocket: 使用者指南
34 |
35 | 新建一个项目,推荐使用 Node.js 18 及以上版本。
36 |
37 | ```bash
38 | $ npx @js-lib/cli new mylib
39 | # 交互式询问,输入项目信息
40 | $ cd mylib
41 | $ npm i
42 | ```
43 |
44 | 更新项目,只需在项目根目录执行如下命令。
45 |
46 | ```bash
47 | $ npx @js-lib/cli update
48 | ```
49 |
50 | 对于旧项目,不能直接执行 update 命令,可以先初始化一个配置文件。
51 |
52 | ```bash
53 | $ npx @js-lib/cli new -c
54 | ```
55 |
56 | 目录简介
57 |
58 | ```
59 | .
60 | ├── demo 使用 demo
61 | ├── dist 编译产出代码
62 | ├── doc 项目文档
63 | ├── src 源代码目录
64 | ├── test 单元测试
65 | ├── CHANGELOG.md 变更日志
66 | └── TODO.md 计划功能
67 | ```
68 |
69 | 常用命令脚本。
70 |
71 | ```bash
72 | $ npm run lint # 校验代码
73 | $ npm run test # 运行单测
74 | $ npm run build # 构建代码
75 | $ npm run release # 发布代码
76 | $ npm publish # 发布到 npm
77 | ```
78 |
79 | ## :kissing_heart: 贡献者指南
80 |
81 | 如果你想修 cli 生成的库代码,可以直接修改模版代码,这比较简单,合并后我会将模版搬运到cli,模版仓库如下:
82 |
83 | - [jslib](https://github.com/yanhaijing/jslib)
84 | - [tslib](https://github.com/yanhaijing/tslib)
85 |
86 | 本项目使用 lerna 来管理多个插件,lerna 常用命令如下:
87 |
88 | ```bash
89 | $ npx lerna init # 初始化
90 | $ npx lerna create @js-lib/todo # 创建一个package
91 | $ npx lerna add yargs --scope=@js-lib/cli # 给package安装依赖
92 | $ npx lerna list # 列出所有的包
93 | $ npx lerna bootstrap # 安装全部依赖
94 | $ npx lerna link # 建立全部软连接
95 | $ npx lerna changed # 列出下次发版npx lerna publish 要更新的包
96 | ```
97 |
98 | 不打 tag 发布。
99 |
100 | ```bash
101 | $ npx lerna version --no-git-tag-version # 仅修改version
102 | $ npx lerna publish from-package --dist-tag next # 发布测试包,需要选择对应的 alpha 版本号
103 | $ npx lerna publish from-package # 发布正式包
104 | ```
105 |
106 | 打 tag 发布。
107 |
108 | ```bash
109 | $ npx lerna publish --dist-tag next # 发布测试包,需要选择对应的 alpha 版本号
110 | $ npx lerna publish # 发布正式包
111 | ```
112 |
113 | ## 贡献者列表
114 |
115 | [contributors](https://github.com/yanhaijing/jslib-base/graphs/contributors)
116 |
117 | ## :gear: 更新日志
118 |
119 | [CHANGELOG.md](./CHANGELOG.md)
120 |
121 | ## :airplane: 计划列表
122 |
123 | [TODO.md](./TODO.md)
124 |
125 | ## :bulb: 谁在使用
126 |
127 | - [jsmini](https://github.com/jsmini)
128 | - [template.js](https://github.com/yanhaijing/template.js)
129 | - [shin-monitor](https://github.com/pwstrick/shin-monitor)
130 | - [baselib](https://github.com/LesixCoder/utils)
131 | - [streaming-json-js](https://github.com/karminski/streaming-json-js)
132 | - [better-js-lib](https://github.com/SFTC/better-js-lib)
133 | - [...](https://github.com/yanhaijing/jslib-base/issues/10)
134 |
135 | ## 参考文档
136 |
137 | - [Lerna 中文教程详解](https://juejin.im/post/5ced1609e51d455d850d3a6c)
138 |
--------------------------------------------------------------------------------
/CHANGELOG.zh.md:
--------------------------------------------------------------------------------
1 | # 变更日志
2 |
3 | ## 3.0.6 / 2024-5-1
4 |
5 | - template:jslib: 更新 package-lock.json
6 | - template:tslib: 更新 package-lock.json
7 |
8 | ## 3.0.5 / 2024-5-1
9 |
10 | - cli: fix update 不更新 package.json
11 |
12 | ## 3.0.4 / 2024-5-1
13 |
14 | - cli: fix update 时报错
15 |
16 | ## 3.0.2 / 2024-5-1
17 |
18 | - template:jslib: 修复缺少 .gitignore
19 | - template:tslib: 修复缺少 .gitignore
20 |
21 | ## 3.0.1 / 2024-5-1
22 |
23 | - cli: fix init 时报错
24 |
25 | ## 3.0.0 / 2024-5-1
26 |
27 | - cli
28 | - 架构升级,由 `module` 升级为 `template`
29 | - 去除 `lang` 参数
30 | - 交互文案迁移为英文
31 | - `update` 命令移除参数
32 | - 添加 CI github actions
33 | - 提升 nodejs 最低版本支持为 18
34 | - template:jslib
35 | - 添加 publish npm github actions
36 | - 提升 nodejs 最低版本支持为 18
37 | - 升级 rollup v3 -> v4
38 | - 升级 @commitlint v16 -> v18
39 | - 升级 nyc v15 -> v17
40 | - 升级 babel-plugin-istanbul v6 -> v7
41 | - 升级其他依赖库到最新版
42 | - template:tslib
43 | - 添加 publish npm github actions
44 | - 提升 nodejs 最低版本支持为 18
45 | - 升级 rollup v3 -> v4
46 | - 升级 @commitlint v16 -> v18
47 | - 升级 nyc v15 -> v17
48 | - 升级 @typescript-eslint v6 -> v8
49 | - 升级 typescript v5.2 -> v5.7
50 | - 升级其他依赖库到最新版
51 |
52 | ## 2.3.4 / 2023-11-19
53 |
54 | - fix: 升级 template_js@3.1.4
55 |
56 | ## 2.3.3 / 2023-11-19
57 |
58 | - fix: 升级 @jsmini/extend@0.5.0,修复 ts 项目在node16下安装警告的问题
59 |
60 | ## 2.3.2 / 2023-11-19
61 |
62 | - fix: 修复升级 rollup-plugin-typescript2@0.36.0 导致的 tslib 有依赖时 build 报错的问题
63 |
64 | ## 2.3.1 / 2023-11-19
65 |
66 | - 升级 commitlint 依赖
67 |
68 | ## 2.3.0 / 2023-11-19
69 |
70 | - 添加生成 sourceMap 功能
71 | - 新增支持 Node.js v20
72 | - 升级全部依赖到最新版
73 |
74 | ## 2.2.7 / 2023-10-2
75 |
76 | - 优化 README 文档
77 | - 修复 LICENSE 文件中缺失名字的问题
78 |
79 | ## 2.2.6 / 2023-9-24
80 |
81 | - 修复ts项目缺失 @babel/runtime-corejs3 依赖
82 |
83 | ## 2.2.5 / 2023-9-24
84 |
85 | - 更新 README.md 文件
86 | - clean 命令添加删除 types 目录
87 |
88 | ## 2.2.4 / 2023-9-24
89 |
90 | - 更新 CHANGELOG.md 文件
91 |
92 | ## 2.2.3 / 2023-9-24
93 |
94 | - 修复 engines 兼容性信息,保持和构建工具一致
95 |
96 | ## 2.2.2 / 2023-9-24
97 |
98 | - 修复update时删除不存在文件时报错的问题
99 |
100 | ## 2.2.1 / 2023-9-24
101 |
102 | - 更新 README.md 兼容性信息,保持和构建工具一致
103 |
104 | ## 2.2.0 / 2023-9-24
105 |
106 | - 修复ts项目缺少types的问题
107 | - 支持 README.md 文件中 [Build Status] 的替换
108 | - 支持 README.md 文件中 [Coveralls] 的删除
109 |
110 | ## 2.1.0 / 2023-9-24
111 |
112 | - update 命令支持删除 1.x 无用文件和配置
113 |
114 | ## 2.0.0 / 2023-9-23
115 |
116 | - 升级全部工具到最新版
117 | - typescript 库接入 babel 工具
118 | - 添加 prettier
119 | - 添加 commitlint
120 | - 添加 husky
121 | - 添加一个本地 server
122 | - 支持 node exports condition
123 | - 迁移 travis 到 github action
124 | - 去掉 coveralls 的支持
125 | - 减少新建的参数数量,9个 -> 7个
126 |
127 | ## 1.7.0 / 2023-9-19
128 |
129 | - 架构调整, mono => sud module
130 | - 重新验证了项目各种功能
131 | - 在 node14 中,js 和 ts 项目,功能完好
132 | - 如果大于 node14 安装依赖可能报错,可以使用`npm i --legacy-peer-deps`
133 |
134 | ## 1.6.0 / 2019-12-18
135 |
136 | - 升级 template.js 版本
137 |
138 | ## 1.5.1 / 2019-10-20
139 |
140 | - 修复`rollup`插件,update 时报错的问题
141 |
142 | ## 1.5.0 / 2019-10-20
143 |
144 | - 新增`test`参数,选择测试方案
145 | - 新增`module`参数,选择模块方案
146 |
147 | ## 1.4.2 / 2019-10-10
148 |
149 | - 修复 npm 发布时丢失 d.ts 的问题
150 |
151 | ## 1.4.1 / 2019-10-7
152 |
153 | - `-c`时不再需要`-f`参数
154 |
155 | ## 1.4.0 / 2019-10-7
156 |
157 | - 增加对 root 插件的 update
158 | - 删除对`@jsmini/type`的依赖
159 |
160 | ## 1.3.0 / 2019-10-7
161 |
162 | - 增加 version 写入配置文件
163 | - `update`增加对文件内容的升级
164 |
165 | ## 1.2.0 / 2019-10-7
166 |
167 | - 增加 umdname 参数
168 |
169 | ## 1.1.0 / 2019-10-7
170 |
171 | - 命令行参数和提示参数一致化处理
172 | - 增加自动安装依赖功能
173 |
174 | ## 1.0.0 / 2019-10-1
175 |
176 | - 架构调整,由 base 改为 cli 工具
177 | - 支持`jslib new`命令
178 | - 支持`jslib update`命令
179 |
180 | ## 0.6.0 / 2019-6-16
181 |
182 | - 统一改用 eslint 校验 js 和 ts
183 |
184 | ## 0.5.0 / 2018-12-17
185 |
186 | - TS 支持测试源文件,改用 nyc
187 |
188 | ## 0.4.0 / 2018-11-27
189 |
190 | - JS 支持测试源文件,改用 nyc
191 |
192 | ## 0.3.0 / 2018-11-23
193 |
194 | - 添加对 typescript 的支持
195 | - 升级 babel7
196 | - 添加对测试覆盖率的支持
197 | - 文档添加 emoji
198 |
199 | ## 0.2.0 / 2018-3-10
200 |
201 | - 支持 banner
202 | - 添加 es5-shim
203 |
204 | ## 0.1.0 / 2018-3-1
205 |
206 | - ES6 编写源码,编译生成生产代码
207 | - 第三方依赖自动注入
208 | - 支持浏览器原生
209 | - 支持 AMD,CMD
210 | - 支持 Webpack,Rollup,fis 等
211 | - 支持 Node
212 | - 集成单元测试环境
213 | - 集成 eslint
214 | - 集成[travis-ci](https://www.travis-ci.org/)
215 |
--------------------------------------------------------------------------------
/packages/cli/README.md:
--------------------------------------------------------------------------------
1 | # [jslib-base](https://github.com/yanhaijing/jslib-base)
2 |
3 | [](https://github.com/yanhaijing/jslib-base)
4 | [](https://github.com/yanhaijing/jslib-base/blob/master/LICENSE)
5 | [](https://www.npmjs.com/package/@js-lib/cli)
6 | [](http://www.npmtrends.com/@js-lib/cli)
7 | [](http://isitmaintained.com/project/yanhaijing/jslib-base 'Percentage of issues still open')
8 | 
9 |
10 | English | [简体中文](https://github.com/yanhaijing/jslib-base/blob/master/README.zh-CN.md)
11 |
12 | The best `JS|TS` third-party library scaffold, quickly setup the basic framework of a new library in 10 seconds.
13 |
14 | **Libraries based on jslib-base can be shared on the [jsmini](https://github.com/jsmini) platform.**
15 |
16 | ## :star: Features
17 |
18 | - Command-line tool for quick creation and seamless upgrades
19 | - Supports writing source code in ES6+ or TypeScript, and compiles to generate production code
20 | - Auto-injection of third-party dependencies (automatically removes unnecessary code in third-party dependencies through tree shaking)
21 | - Supports multiple environments (native browser, AMD, commonjs, Webpack, Rollup, vite, fis, Node.js, etc.)
22 | - Integrated code style checker (eslint + prettier + husky)
23 | - Integrated unit test environment (mocha)
24 | - Integrated test coverage report (istanbul+nyc)
25 | - Integrated continuous integration tool github action
26 | - Integrated with [jsmini](https://github.com/jsmini)
27 |
28 | ## :rocket: User Guide
29 |
30 | To create a new project, it is recommended to use Node.js version 18 or higher.
31 |
32 | ```bash
33 | $ npx @js-lib/cli new mylib
34 | # Interactive queries, input project info
35 | $ cd mylib
36 | $ npm i
37 | ```
38 |
39 | To update the project, just execute the following command in the project root directory.
40 |
41 | ```bash
42 | $ npx @js-lib/cli update
43 | ```
44 |
45 | For old projects, you can't directly execute the update command, you can first initialize a config file.
46 |
47 | ```bash
48 | $ npx @js-lib/cli new -c
49 | ```
50 |
51 | Directory Overview
52 |
53 | ```
54 | .
55 | ├── demo Usage demo
56 | ├── dist Compiled out code
57 | ├── doc Project documents
58 | ├── src Source code directory
59 | ├── test Unit tests
60 | ├── CHANGELOG.md Change log
61 | └── TODO.md To-do features
62 | ```
63 |
64 | Common command scripts
65 |
66 | ```bash
67 | $ npm run lint
68 | $ npm run test
69 | $ npm run build
70 | $ npm run release
71 | $ npm publish
72 | ```
73 |
74 | ## Contribution Guide
75 |
76 | If you only want to modify the library code generated by the CLI, you can directly edit the template code, which is simpler.
77 |
78 | After merging, I will migrate the template to the CLI. The template repository is as follows:
79 |
80 | - [jslib](https://github.com/yanhaijing/jslib)
81 | - [tslib](https://github.com/yanhaijing/tslib)
82 |
83 | This project uses lerna to manage multiple plugins, common lerna commands are:
84 |
85 | ```bash
86 | $ npx lerna init # Initialization
87 | $ npx lerna create @js-lib/todo # Create a package
88 | $ npx lerna add yargs --scope=@js-lib/cli # Install dependencies for a package
89 | $ npx lerna list # List all the packages
90 | $ npx lerna bootstrap # Install all dependencies
91 | $ npx lerna link # Create all links
92 | $ npx lerna changed # List the packages to be updated in the next release
93 | $ npx lerna publish # Release with tag, upload to git, upload to npm
94 | ```
95 |
96 | ## Contributors
97 |
98 | [contributors](https://github.com/yanhaijing/jslib-base/graphs/contributors)
99 |
100 | ## Change Log
101 |
102 | [CHANGELOG.md](https://github.com/yanhaijing/jslib-base/blob/master/CHANGELOG.md)
103 |
104 | ## TODO
105 |
106 | [TODO.md](https://github.com/yanhaijing/jslib-base/blob/master/TODO.md)
107 |
108 | ## Current Users
109 |
110 | - [jsmini](https://github.com/jsmini)
111 | - [template.js](https://github.com/yanhaijing/template.js)
112 | - [...](https://github.com/yanhaijing/jslib-base/issues/10)
113 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [jslib-base](https://github.com/yanhaijing/jslib-base)
2 |
3 | [](https://github.com/yanhaijing/jslib-base)
4 | [](https://github.com/yanhaijing/jslib-base/blob/master/LICENSE)
5 | [](https://www.npmjs.com/package/@js-lib/cli)
6 | [](http://www.npmtrends.com/@js-lib/cli)
7 | [](http://isitmaintained.com/project/yanhaijing/jslib-base 'Percentage of issues still open')
8 | 
9 |
10 | English | [简体中文](https://github.com/yanhaijing/jslib-base/blob/master/README.zh-CN.md)
11 |
12 | The best `JS|TS` third-party library scaffold, quickly setup the basic framework of a `JS|TS` library in 10 seconds.
13 |
14 | **Libraries based on jslib-base can be shared on the [jsmini](https://github.com/jsmini) platform.**
15 |
16 | ## :star: Features
17 |
18 | - **Interactive CLI for project initialization**
19 | - **Upgrade functionality** – Easily upgrade old libraries with one command
20 | - **Supports both JavaScript and TypeScript**
21 | - **Build & Packaging Solutions**
22 | - TypeScript + Babel + Rollup
23 | - Automatic third-party dependency injection (supports tree shaking)
24 | - **Multi-Environment Compatibility**
25 | - Supports native browser script usage
26 | - Provides UMD and ESM modules, compatible with Webpack, Vite, and other ecosystems
27 | - Adapts to both old and new Node.js module systems (CommonJS + ESM)
28 | - **Code Style & Linting**
29 | - ESLint + Prettier + Husky + Lint-Staged
30 | - **Unit Testing Suite**
31 | - Mocha + Expect.js + Istanbul + NYC + Coveralls
32 | - **Commit Linting**
33 | - Commitlint + Commitizen
34 | - **GitHub Actions**
35 | - CI + Release
36 | - **Local Development Server**
37 | - http-server
38 |
39 | ## :rocket: User Guide
40 |
41 | To create a new project, it is recommended to use Node.js version 18 or higher.
42 |
43 | ```bash
44 | $ npx @js-lib/cli new mylib
45 | # Interactive queries, input project info
46 | $ cd mylib
47 | $ npm i
48 | ```
49 |
50 | To update the project, just execute the following command in the project root directory.
51 |
52 | ```bash
53 | $ npx @js-lib/cli update
54 | ```
55 |
56 | For old projects, you can't directly execute the update command, you can first initialize a config file.
57 |
58 | ```bash
59 | $ npx @js-lib/cli new -c
60 | ```
61 |
62 | Directory Overview
63 |
64 | ```
65 | .
66 | ├── demo Usage demo
67 | ├── dist Compiled out code
68 | ├── doc Project documents
69 | ├── src Source code directory
70 | ├── test Unit tests
71 | ├── CHANGELOG.md Change log
72 | └── TODO.md To-do features
73 | ```
74 |
75 | Common command scripts
76 |
77 | ```bash
78 | $ npm run lint
79 | $ npm run test
80 | $ npm run build
81 | $ npm run release
82 | $ npm publish
83 | ```
84 |
85 | ## Contribution Guide
86 |
87 | If you only want to modify the library code generated by the CLI, you can directly edit the template code, which is simpler.
88 |
89 | After merging, I will migrate the template to the CLI. The template repository is as follows:
90 |
91 | - [jslib](https://github.com/yanhaijing/jslib)
92 | - [tslib](https://github.com/yanhaijing/tslib)
93 |
94 | This project uses lerna to manage multiple plugins, common lerna commands are:
95 |
96 | ```bash
97 | $ npx lerna init # Initialization
98 | $ npx lerna create @js-lib/todo # Create a package
99 | $ npx lerna add yargs --scope=@js-lib/cli # Install dependencies for a package
100 | $ npx lerna list # List all the packages
101 | $ npx lerna bootstrap # Install all dependencies
102 | $ npx lerna link # Create all links
103 | $ npx lerna changed # List the packages to be updated in the next release
104 | $ npx lerna publish # Release with tag, upload to git, upload to npm
105 | ```
106 |
107 | ## Contributors
108 |
109 | [contributors](https://github.com/yanhaijing/jslib-base/graphs/contributors)
110 |
111 | ## Change Log
112 |
113 | [CHANGELOG.md](https://github.com/yanhaijing/jslib-base/blob/master/CHANGELOG.md)
114 |
115 | ## TODO
116 |
117 | [TODO.md](https://github.com/yanhaijing/jslib-base/blob/master/TODO.md)
118 |
119 | ## Current Users
120 |
121 | - [jsmini](https://github.com/jsmini)
122 | - [template.js](https://github.com/yanhaijing/template.js)
123 | - [shin-monitor](https://github.com/pwstrick/shin-monitor)
124 | - [baselib](https://github.com/LesixCoder/utils)
125 | - [streaming-json-js](https://github.com/karminski/streaming-json-js)
126 | - [better-js-lib](https://github.com/SFTC/better-js-lib)
127 | - [...](https://github.com/yanhaijing/jslib-base/issues/10)
128 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | ## 3.0.6 / 2024-5-1
4 |
5 | - template:jslib: update package-lock.json
6 | - template:tslib: update package-lock.json
7 |
8 | ## 3.0.5 / 2024-5-1
9 |
10 | - cli: fix update miss package.json
11 |
12 | ## 3.0.4 / 2024-5-1
13 |
14 | - cli: fix update error
15 |
16 | ## 3.0.2 / 2024-5-1
17 |
18 | - template:jslib: fix miss .gitignore
19 | - template:tslib: fix miss .gitignore
20 |
21 | ## 3.0.1 / 2024-5-1
22 |
23 | - cli: fix init error
24 |
25 | ## 3.0.0 / 2024-5-1
26 |
27 | - CLI
28 | - Architecture upgrade: from `module` to `template`
29 | - Removed the `lang` parameter
30 | - Interaction text migrated to English
31 | - Removed parameters from the `update` command
32 | - Added CI with GitHub Actions
33 | - Increased minimum supported Node.js version to 18
34 | - Template: jslib
35 | - Added publish to npm GitHub Actions
36 | - Increased minimum supported Node.js version to 18
37 | - Upgraded Rollup from v3 to v4
38 | - Upgraded @commitlint from v16 to v18
39 | - Upgraded nyc from v15 to v17
40 | - Upgraded babel-plugin-istanbul from v6 to v7
41 | - Upgraded other dependencies to their latest versions
42 | - Template: tslib
43 | - Added publish to npm GitHub Actions
44 | - Increased minimum supported Node.js version to 18
45 | - Upgraded Rollup from v3 to v4
46 | - Upgraded @commitlint from v16 to v18
47 | - Upgraded nyc from v15 to v17
48 | - Upgraded @typescript-eslint from v6 to v8
49 | - Upgraded TypeScript from v5.2 to v5.7
50 | - Upgraded other dependencies to their latest versions
51 |
52 | ## 2.3.4 / 2023-11-19
53 |
54 | - fix: Upgraded `template_js@3.1.4`.
55 |
56 | ## 2.3.3 / 2023-11-19
57 |
58 | - fix: Upgraded `@jsmini/extend@0.5.0` to fix warnings when installing in Node.js 16 for TypeScript projects.
59 |
60 | ## 2.3.2 / 2023-11-19
61 |
62 | - fix: Resolved build errors caused by upgrading `rollup-plugin-typescript2@0.36.0` with `tslib` dependencies.
63 |
64 | ## 2.3.1 / 2023-11-19
65 |
66 | - Upgraded `commitlint` dependencies.
67 |
68 | ## 2.3.0 / 2023-11-19
69 |
70 | - Added `sourceMap` generation functionality.
71 | - Added support for Node.js v20.
72 | - Upgraded all dependencies to the latest versions.
73 |
74 | ## 2.2.7 / 2023-10-2
75 |
76 | - Optimized the `README` documentation.
77 | - Fixed missing names in the `LICENSE` file.
78 |
79 | ## 2.2.6 / 2023-9-24
80 |
81 | - Fixed missing `@babel/runtime-corejs3` dependencies in TypeScript projects.
82 |
83 | ## 2.2.5 / 2023-9-24
84 |
85 | - Updated the `README.md` file.
86 | - Added the deletion of the `types` directory to the `clean` command.
87 |
88 | ## 2.2.4 / 2023-9-24
89 |
90 | - Updated the `CHANGELOG.md` file.
91 |
92 | ## 2.2.3 / 2023-9-24
93 |
94 | - Fixed compatibility information in `engines` to align with the build tool.
95 |
96 | ## 2.2.2 / 2023-9-24
97 |
98 | - Fixed errors when deleting non-existent files during `update`.
99 |
100 | ## 2.2.1 / 2023-9-24
101 |
102 | - Updated compatibility information in `README.md` to align with the build tool.
103 |
104 | ## 2.2.0 / 2023-9-24
105 |
106 | - Fixed missing `types` in TypeScript projects.
107 | - Supported replacement of `[Build Status]` in `README.md`.
108 | - Supported removal of `[Coveralls]` from `README.md`.
109 |
110 | ## 2.1.0 / 2023-9-24
111 |
112 | - `update` command now supports deleting unused files and configurations from version 1.x.
113 |
114 | ## 2.0.0 / 2023-9-23
115 |
116 | - Upgraded all tools to the latest versions.
117 | - Integrated Babel for TypeScript libraries.
118 | - Added `prettier`.
119 | - Added `commitlint`.
120 | - Added `husky`.
121 | - Added a local server.
122 | - Supported `node exports` condition.
123 | - Migrated from Travis CI to GitHub Actions.
124 | - Removed support for Coveralls.
125 | - Reduced the number of parameters for new commands from 9 to 7.
126 |
127 | ## 1.7.0 / 2023-9-19
128 |
129 | - Architectural adjustment from `mono` to `sub-module`.
130 | - Re-verified all project functionalities:
131 | - Fully functional in Node.js 14 for both JavaScript and TypeScript projects.
132 | - Dependency installation may fail for versions above Node.js 14. Use `npm i --legacy-peer-deps`.
133 |
134 | ## 1.6.0 / 2019-12-18
135 |
136 | - Upgraded the `template.js` version.
137 |
138 | ## 1.5.1 / 2019-10-20
139 |
140 | - Fixed errors in `rollup` plugins during `update`.
141 |
142 | ## 1.5.0 / 2019-10-20
143 |
144 | - Added `test` parameter to select test strategies.
145 | - Added `module` parameter to select module strategies.
146 |
147 | ## 1.4.2 / 2019-10-10
148 |
149 | - Fixed missing `d.ts` during npm publishing.
150 |
151 | ## 1.4.1 / 2019-10-7
152 |
153 | - Removed the need for the `-f` parameter when using `-c`.
154 |
155 | ## 1.4.0 / 2019-10-7
156 |
157 | - Added support for updating root plugins.
158 | - Removed dependency on `@jsmini/type`.
159 |
160 | ## 1.3.0 / 2019-10-7
161 |
162 | - Added version writing to configuration files.
163 | - Enhanced `update` to support file content upgrades.
164 |
165 | ## 1.2.0 / 2019-10-7
166 |
167 | - Added `umdname` parameter.
168 |
169 | ## 1.1.0 / 2019-10-7
170 |
171 | - Unified CLI and prompt parameter handling.
172 | - Added automatic dependency installation.
173 |
174 | ## 1.0.0 / 2019-10-1
175 |
176 | - Adjusted architecture from `base` to CLI tools.
177 | - Supported `jslib new` command.
178 | - Supported `jslib update` command.
179 |
180 | ## 0.6.0 / 2019-6-16
181 |
182 | - Standardized using `eslint` for both JavaScript and TypeScript.
183 |
184 | ## 0.5.0 / 2018-12-17
185 |
186 | - Added support for testing source files in TypeScript using `nyc`.
187 |
188 | ## 0.4.0 / 2018-11-27
189 |
190 | - Added support for testing source files in JavaScript using `nyc`.
191 |
192 | ## 0.3.0 / 2018-11-23
193 |
194 | - Added support for TypeScript.
195 | - Upgraded to Babel 7.
196 | - Added support for test coverage.
197 | - Added emojis to documentation.
198 |
199 | ## 0.2.0 / 2018-3-10
200 |
201 | - Added `banner` support.
202 | - Added `es5-shim`.
203 |
204 | ## 0.1.0 / 2018-3-1
205 |
206 | - Source code written in ES6 and compiled for production.
207 | - Automatic injection of third-party dependencies.
208 | - Supported native browser usage.
209 | - Supported AMD, CMD.
210 | - Compatible with Webpack, Rollup, and Fis.
211 | - Node.js support.
212 | - Integrated unit testing environment.
213 | - Integrated `eslint`.
214 | - Integrated [Travis CI](https://www.travis-ci.org/).
215 |
--------------------------------------------------------------------------------
/packages/cli/util/copy.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-prototype-builtins */
2 | const fs = require('fs');
3 | const path = require('path');
4 |
5 | const copydir = require('copy-dir');
6 | const template = require('template_js');
7 | const { extendDeep } = require('@jsmini/extend');
8 |
9 | function isTemplate(pathname) {
10 | return path.extname(pathname) === '.tmpl';
11 | }
12 |
13 | function deleteFile(filePath) {
14 | if (fs.existsSync(filePath)) {
15 | fs.unlinkSync(filePath);
16 | }
17 | }
18 |
19 | function deleteDir(dirPath) {
20 | if (fs.existsSync(dirPath)) {
21 | try {
22 | fs.rmSync(dirPath, { recursive: true, force: true });
23 | } catch (e) {
24 | // rmSync is not supported in node 12
25 | fs.rmdirSync(dirPath, { recursive: true });
26 | }
27 | } else {
28 | console.log('deleteDir: Directory path ' + dirPath + ' not found!');
29 | }
30 | }
31 |
32 | function copyDir(from, to, options) {
33 | copydir.sync(from, to, options);
34 | }
35 |
36 | function mkdirSyncGuard(target) {
37 | try {
38 | fs.mkdirSync(target, { recursive: true });
39 | } catch (e) {
40 | mkdirp(target);
41 | // eslint-disable-next-line no-inner-declarations
42 | function mkdirp(dir) {
43 | if (fs.existsSync(dir)) {
44 | return true;
45 | }
46 | const dirname = path.dirname(dir);
47 | mkdirp(dirname);
48 | fs.mkdirSync(dir);
49 | }
50 | }
51 | }
52 |
53 | function copyFile(from, to, opt = { cover: true }) {
54 | // 不覆盖时,检测文件是否存在
55 | if (!opt.cover && fs.existsSync(to)) {
56 | return;
57 | }
58 |
59 | const buffer = fs.readFileSync(from);
60 | const parentPath = path.dirname(to);
61 |
62 | if (!fs.existsSync(parentPath)) {
63 | mkdirSyncGuard(parentPath);
64 | }
65 |
66 | fs.writeFileSync(to, buffer);
67 | }
68 |
69 | function readTmpl(from, data = {}) {
70 | const text = fs.readFileSync(from, { encoding: 'utf8' });
71 | return template(text, data);
72 | }
73 |
74 | function readJSON(from) {
75 | const txt = fs.readFileSync(from, { encoding: 'utf8' });
76 | const json = JSON.parse(txt);
77 | return json;
78 | }
79 |
80 | function copyTmpl(from, to, data = {}, opt = { cover: true }) {
81 | // 不覆盖时,检测文件是否存在
82 | if (!opt.cover && fs.existsSync(to)) {
83 | return;
84 | }
85 |
86 | if (!isTemplate(from)) {
87 | return copyFile(from, to);
88 | }
89 |
90 | const parentPath = path.dirname(to);
91 |
92 | mkdirSyncGuard(parentPath);
93 |
94 | fs.writeFileSync(to, readTmpl(from, data), { encoding: 'utf8' });
95 | }
96 |
97 | function mergeObj2JSON(object, to) {
98 | const json = JSON.parse(fs.readFileSync(to, { encoding: 'utf8' }));
99 |
100 | extendDeep(json, object);
101 |
102 | fs.writeFileSync(to, JSON.stringify(json, null, ' '), { encoding: 'utf8' });
103 | }
104 |
105 | function deleteKeys(obj, keysObj) {
106 | for (let key in keysObj) {
107 | if (typeof keysObj[key] === 'object' && keysObj[key] !== null) {
108 | if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') {
109 | deleteKeys(obj[key], keysObj[key]);
110 | }
111 | } else if (obj.hasOwnProperty(key)) {
112 | delete obj[key];
113 | }
114 | }
115 | return obj;
116 | }
117 |
118 | function deleteJSONKeys(keysObj, to) {
119 | const obj = JSON.parse(fs.readFileSync(to, { encoding: 'utf8' }));
120 | deleteKeys(obj, keysObj);
121 | fs.writeFileSync(to, JSON.stringify(obj, null, ' '), { encoding: 'utf8' });
122 | }
123 |
124 | function mergeJSON2JSON(from, to) {
125 | const json = JSON.parse(fs.readFileSync(from, { encoding: 'utf8' }));
126 |
127 | mergeObj2JSON(json, to);
128 | }
129 |
130 | function mergeTmpl2JSON(from, to, data = {}) {
131 | const json = JSON.parse(readTmpl(from, data));
132 | mergeObj2JSON(json, to);
133 | }
134 |
135 | function replaceFileLine(filepath, match, to) {
136 | let file = fs.readFileSync(filepath, { encoding: 'utf8' });
137 | let count = 0;
138 |
139 | // file 按行分隔,如果匹配match,则替换为to
140 | file = file
141 | .split('\n')
142 | .map(function (line) {
143 | if (match.test(line)) {
144 | count += 1;
145 | return to;
146 | }
147 | return line;
148 | })
149 | .join('\n');
150 |
151 | if (count) {
152 | fs.writeFileSync(filepath, file);
153 | }
154 | }
155 |
156 | // 参考replaceFileLine 写一个删除行的方法
157 | function deleteFileLine(filepath, match) {
158 | let file = fs.readFileSync(filepath, { encoding: 'utf8' });
159 | let count = 0;
160 |
161 | // file 按行分隔,如果匹配match,则删除
162 | file = file
163 | .split('\n')
164 | .filter(function (line) {
165 | if (match.test(line)) {
166 | count += 1;
167 | return false;
168 | }
169 | return true;
170 | })
171 | .join('\n');
172 |
173 | if (count) {
174 | fs.writeFileSync(filepath, file);
175 | }
176 | }
177 |
178 | function replaceFileText(filepath, replacerList) {
179 | let file = fs.readFileSync(filepath, { encoding: 'utf8' });
180 | let count = 0;
181 |
182 | // 对文件内容进行替换
183 | replacerList.forEach(function (replacer) {
184 | var res;
185 | // 支持字符串和正则的替换
186 | while ((res = file.match(replacer.from))) {
187 | count += 1;
188 |
189 | // 支持函数,支持替换中的正则引用 $0 $1 $2
190 | var to =
191 | typeof replacer.to === 'function'
192 | ? replacer.to
193 | : replacer.to.replace(/\$(\d+)/g, function (match, p1) {
194 | return res[p1] || '';
195 | });
196 |
197 | file = file.replace(replacer.from, to);
198 | }
199 | });
200 |
201 | if (count) {
202 | fs.writeFileSync(filepath, file);
203 | }
204 | }
205 |
206 | /**
207 | * 将文本插入到文件,文件不存在会自动创建
208 | */
209 | function insertText2File(text, filepath, line = -1) {
210 | const lines = fs.existsSync(filepath)
211 | ? fs.readFileSync(filepath, { encoding: 'utf8' }).split('\n')
212 | : [];
213 |
214 | if (line === -1) {
215 | lines.push(text);
216 | } else {
217 | lines.splice(line, 0, text);
218 | }
219 |
220 | const parentPath = path.dirname(filepath);
221 |
222 | if (!fs.existsSync(parentPath)) {
223 | mkdirSyncGuard(parentPath);
224 | }
225 |
226 | fs.writeFileSync(filepath, lines.join('\n'), {
227 | encoding: 'utf8',
228 | });
229 | }
230 |
231 | exports.copyDir = copyDir;
232 | exports.copyFile = copyFile;
233 | exports.readTmpl = readTmpl;
234 | exports.readJSON = readJSON;
235 | exports.copyTmpl = copyTmpl;
236 | exports.mergeObj2JSON = mergeObj2JSON;
237 | exports.deleteJSONKeys = deleteJSONKeys;
238 | exports.mergeJSON2JSON = mergeJSON2JSON;
239 | exports.mergeTmpl2JSON = mergeTmpl2JSON;
240 | exports.replaceFileText = replaceFileText;
241 | exports.insertText2File = insertText2File;
242 | exports.replaceFileLine = replaceFileLine;
243 | exports.deleteFileLine = deleteFileLine;
244 | exports.deleteFile = deleteFile;
245 | exports.deleteDir = deleteDir;
246 |
--------------------------------------------------------------------------------
/packages/cli/module-ts/template/base/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "include": ["src/**/*.ts"],
3 | "exclude": ["node_modules", "**.d.ts"],
4 | "compilerOptions": {
5 | /* Visit https://aka.ms/tsconfig to read more about this file */
6 |
7 | /* Projects */
8 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
9 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
10 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
11 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
12 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
13 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
14 |
15 | /* Language and Environment */
16 | "target": "ES2015" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
17 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
18 | // "jsx": "preserve", /* Specify what JSX code is generated. */
19 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
20 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
21 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
22 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
23 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
24 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
25 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
26 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
27 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
28 |
29 | /* Modules */
30 | "module": "CommonJS" /* Specify what module code is generated. */,
31 | // "rootDir": "./", /* Specify the root folder within your source files. */
32 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
33 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
34 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
35 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
36 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
37 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */
38 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
39 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
40 | // "resolveJsonModule": true, /* Enable importing .json files. */
41 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */
42 |
43 | /* JavaScript Support */
44 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
45 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
46 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
47 |
48 | /* Emit */
49 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
50 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */
51 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
52 | "sourceMap": true, /* Create source map files for emitted JavaScript files. */
53 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
54 | // "outDir": "./", /* Specify an output folder for all emitted files. */
55 | // "removeComments": true, /* Disable emitting comments. */
56 | // "noEmit": true, /* Disable emitting files from a compilation. */
57 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
58 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
59 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
60 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
61 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
62 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
63 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
64 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
65 | // "newLine": "crlf", /* Set the newline character for emitting files. */
66 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
67 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
68 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
69 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
70 | // "declarationDir": "./types" /* Specify the output directory for generated declaration files. */,
71 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
72 |
73 | /* Interop Constraints */
74 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
75 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
76 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
77 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
78 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
79 |
80 | /* Type Checking */
81 | "strict": true /* Enable all strict type-checking options. */,
82 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
83 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
84 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
85 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
86 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
87 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
88 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
89 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
90 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
91 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
92 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
93 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
94 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
95 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
96 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
97 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
98 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
99 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
100 |
101 | /* Completeness */
102 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
103 | "skipLibCheck": true /* Skip type checking all .d.ts files. */
104 | }
105 | }
106 |
--------------------------------------------------------------------------------