Skip to content

Commit

Permalink
feat: v3
Browse files Browse the repository at this point in the history
1. 提示文案迁移为英文
2. 去除 lang 参数
3. 将 module 架构,调整为 template 架构
  • Loading branch information
yanhaijing committed Jan 4, 2025
1 parent 6de5337 commit a39077e
Show file tree
Hide file tree
Showing 117 changed files with 33,694 additions and 90 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
问题的具体描述,尽量详细

### 环境
- 系统:mac 10.14.1
- node版本:10.12.1
- npm版本:6.5.1
- 系统:mac 12.7.6
- node版本:18.20.5
- npm版本:10.8.2
- 其他版本信息

### 在线例子
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
node_modules
package-lock.json
packages/*/package-lock.json
.DS_Store
.eslintcache
temp
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The best `JS|TS` third-party library scaffold, quickly setup the basic framework

## :rocket: User Guide

To create a new project, it is recommended to use Node.js version 16 or higher.
To create a new project, it is recommended to use Node.js version 18 or higher.

```bash
$ npx @js-lib/cli new mylib
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

## :rocket: 使用者指南

新建一个项目,推荐使用 Node.js 16 及以上版本。
新建一个项目,推荐使用 Node.js 18 及以上版本。

```bash
$ npx @js-lib/cli new mylib
Expand Down
36 changes: 16 additions & 20 deletions packages/cli/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const yargs = require('yargs');

const log = require('../util/log');

const { runUpdatePrompts, runInitPrompts } = require('./run-prompts');
const { runInitPrompts } = require('./run-prompts');
const { checkProjectExists } = require('../util/file');
const { init } = require('./init');
const { update } = require('./update');
Expand All @@ -15,45 +15,41 @@ log.init();
yargs
.usage('usage: jslib [options]')
.usage('usage: jslib <command> [options]')
.example('jslib new myproject', '新建一个项目 myproject')
.example('jslib new myproject', 'Create a new project myproject')
.alias('h', 'help')
.alias('v', 'version')
.command(
['new', 'n'],
'新建一个项目',
'Create a new project',
function (yargs) {
return yargs
.option('force', {
alias: 'f',
describe: '强制新建',
describe: 'Force create',
})
.option('config', {
alias: 'c',
describe: '仅初始化配置文件',
describe: 'Initialize only the configuration file',
})
.option('npmname', {
alias: 'n',
describe: '仅初始化 npm 项目名称',
describe: 'Initialize the npm package name',
})
.option('umdname', {
alias: 'umd',
describe: '仅初始化打包时umd name',
describe: 'Initialize the UMD name for package',
})
.option('username', {
alias: 'u',
describe: '仅初始化用户名称',
describe: 'Initialize the username',
})
.option('type', {
alias: 't',
describe: '仅初始化 js/ts 选择',
})
.option('lang', {
alias: 'l',
describe: '仅初始化中英文选择',
describe: 'Initialize the js/ts selection',
})
.option('manager', {
alias: 'm',
describe: '选择仓库包管理方式',
describe: 'Select the package management method',
});
},
function (argv) {
Expand All @@ -62,9 +58,11 @@ yargs
});
},
)
.command(['update', 'u'], '更新一个项目', function (_yargs) {
.command(['update', 'u'], 'Update a project', function (_yargs) {
if (!checkProjectExists(process.cwd(), 'jslib.json')) {
console.error('error: 这不是一个jslib库,缺少jslib.json文件');
console.error(
'error: This is not a jslib library, missing jslib.json file',
);
return;
}

Expand All @@ -74,9 +72,7 @@ yargs
}),
);

runUpdatePrompts().then(function (answers) {
update(json, answers);
});
update(json);
})
.demandCommand()
.epilog('copyright 2018-2023').argv;
.epilog('copyright 2018-2025').argv;
17 changes: 12 additions & 5 deletions packages/cli/bin/init.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const config = require('../module/config');
const cli = require('../index.js');
const modulejs = require('../module-js');
const modulets = require('../module-ts');
const pkg = require('../package.json');
const { checkProjectExists } = require('../util/file');

function init(argv, answers) {
const cmdPath = process.cwd();
const { name, npmname, umdname, username, type, lang, manager } =
Object.assign({}, argv, answers);
const { name, npmname, umdname, username, type, manager } = Object.assign(
{},
argv,
answers,
);
const pathname = String(typeof argv._[1] !== 'undefined' ? argv._[1] : name);

const option = {
Expand All @@ -16,7 +20,6 @@ function init(argv, answers) {
umdname: String(umdname),
username: String(username),
type,
lang,
manager,
version: pkg.version,
};
Expand All @@ -40,7 +43,11 @@ function init(argv, answers) {
return;
}

cli.init(cmdPath, option);
if (option.type === 'js') {
modulejs.init(cmdPath, option);
} else if (option.type === 'ts') {
modulets.init(cmdPath, option);
}
}

exports.init = init;
59 changes: 4 additions & 55 deletions packages/cli/bin/run-prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function prompts(promptList) {
let promptList = [];

function runInitPrompts(pathname, argv) {
const { npmname, umdname, username, type, lang, manager } = argv;
const { npmname, umdname, username, type, manager } = argv;

promptList.push({
type: 'input',
Expand All @@ -30,7 +30,7 @@ function runInitPrompts(pathname, argv) {
if (!npmname) {
promptList.push({
type: 'input',
message: 'publish to npm name:',
message: 'npm package name:',
name: 'npmname',
default: pathname,
validate: function (val) {
Expand All @@ -44,7 +44,7 @@ function runInitPrompts(pathname, argv) {
if (!umdname) {
promptList.push({
type: 'input',
message: 'publish to umd name:',
message: 'UMD name for package:',
name: 'umdname',
default: pathname,
validate: function (val) {
Expand All @@ -71,7 +71,7 @@ function runInitPrompts(pathname, argv) {
if (!type) {
promptList.push({
type: 'list',
message: 'use JavaScript|TypeScript:',
message: 'select template:',
name: 'type',
choices: ['JavaScript', 'TypeScript'],
filter: function (value) {
Expand All @@ -82,20 +82,6 @@ function runInitPrompts(pathname, argv) {
},
});
}
if (!lang) {
promptList.push({
type: 'list',
message: 'project language:',
name: 'lang',
choices: ['Chinese', 'English'],
filter: function (value) {
return {
Chinese: 'zh',
English: 'en',
}[value];
},
});
}
if (!manager) {
promptList.push({
type: 'list',
Expand All @@ -113,41 +99,4 @@ function runInitPrompts(pathname, argv) {
return prompts(promptList);
}

function runUpdatePrompts() {
const promptList = [
{
type: 'confirm',
message: '是否更新<root>插件:',
name: 'root',
default: false,
},
{
type: 'confirm',
message: '是否更新<package>插件:',
name: 'package',
default: false,
},
{
type: 'confirm',
message: '是否更新<lint>插件:',
name: 'lint',
default: false,
},
{
type: 'confirm',
message: '是否更新<build>插件:',
name: 'build',
default: false,
},
{
type: 'confirm',
message: '是否更新<test>插件:',
name: 'test',
default: false,
},
];
return prompts(promptList);
}

exports.runInitPrompts = runInitPrompts;
exports.runUpdatePrompts = runUpdatePrompts;
11 changes: 8 additions & 3 deletions packages/cli/bin/update.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const cli = require('../index.js');
const pkg = require('../package.json');
const modulejs = require('../module-js');
const modulets = require('../module-ts');

function update(option, answers) {
function update(option) {
const cmdPath = process.cwd();
option.version = pkg.version;
cli.update(cmdPath, option, answers);
if (option.type === 'js') {
modulejs.update(cmdPath, option);
} else if (option.type === 'ts') {
modulets.update(cmdPath, option);
}
}

exports.update = update;
56 changes: 56 additions & 0 deletions packages/cli/module-js/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const path = require('path');
const util = require('../util/copy');

function init(cmdPath, name, option) {
console.log('build: init');

util.copyTmpl(
path.resolve(__dirname, `./template/build-rollup.cjs.tmpl`),
path.resolve(cmdPath, name, 'config/rollup.cjs'),
option,
);
}

function update(cmdPath, option) {
console.log('build: update');

// 删除 1.x 版本的无用数据
util.deleteJSONKeys(
{
scripts: {
'build:aio.min': undefined,
},
dependencies: {
'@babel/runtime': undefined,
},
devDependencies: {
'babel-core': undefined,
'babel-preset-env': undefined,
'rollup-plugin-babel': undefined,
'rollup-plugin-commonjs': undefined,
'rollup-plugin-node-resolve': undefined,
'@babel/cli': undefined,
'@babel/core': undefined,
'rollup-plugin-uglify': undefined,
},
},
path.resolve(cmdPath, './package.json'),
);
util.deleteDir(path.resolve(cmdPath, './config'));

util.copyDir(
path.resolve(__dirname, `./template/base/config`),
path.resolve(cmdPath, 'config'),
);

util.copyTmpl(
path.resolve(__dirname, `./template/build-rollup.cjs.tmpl`),
path.resolve(cmdPath, 'config/rollup.cjs'),
option,
);
}

module.exports = {
init: init,
update: update,
};
21 changes: 21 additions & 0 deletions packages/cli/module-js/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require('path');
const util = require('../util/copy');

function init(cmdPath, name, option) {
console.log('config: init');

util.copyTmpl(
path.resolve(__dirname, `./template/jslib.json.tmpl`),
path.resolve(cmdPath, name, 'jslib.json'),
option,
);
}

function update() {
console.log('config: update');
}

module.exports = {
init: init,
update: update,
};
21 changes: 21 additions & 0 deletions packages/cli/module-js/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require('path');
const util = require('../util/copy');

function init(cmdPath, name, option) {
console.log('demo: init');

util.copyTmpl(
path.resolve(__dirname, `./template/demo-global.html.tmpl`),
path.resolve(cmdPath, name, 'demo/demo-global.html'),
option,
);
}

function update(_cmdPath, _option) {
console.log('demo: update');
}

module.exports = {
init: init,
update: update,
};
Loading

0 comments on commit a39077e

Please sign in to comment.