the-cli-demo 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +53 -3
- package/package.json +5 -2
- package/readme.md +1 -0
package/bin/index.js
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// 上面一行是在 `用户环境变量中查找 node 可执行文件`,然后用node执行当前脚本
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
console.log(
|
|
3
|
+
|
|
4
|
+
const lib = require('the-cli-demo-lib')
|
|
5
|
+
// console.log('lib=>>',lib)
|
|
6
|
+
// console.log("Hello, welcome to the CLI demo!");
|
|
7
|
+
// console.log("This is a simple command-line interface application.!3332");
|
|
8
|
+
|
|
9
|
+
// 注册一个命令 the-demo init
|
|
10
|
+
// const args = require('process');
|
|
11
|
+
// console.log('args=>>',args);
|
|
12
|
+
// console.log('process=>>',process);
|
|
13
|
+
|
|
14
|
+
const args = process.argv;
|
|
15
|
+
const command = args[2];
|
|
16
|
+
const options = args.slice(3);
|
|
17
|
+
// console.log('command=>>',command);
|
|
18
|
+
// console.log('options=>>',options);
|
|
19
|
+
let [option, param] = options || [];
|
|
20
|
+
option = (option || '').replace('--', '');
|
|
21
|
+
if (option) {
|
|
22
|
+
if (command) {
|
|
23
|
+
if (lib[command] && typeof lib[command] === 'function') {
|
|
24
|
+
lib[command]({ option, param });
|
|
25
|
+
} else {
|
|
26
|
+
console.log(`未知命令: ${command}`);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
console.log('请输入命令: the-cli-demo <command> [options]');
|
|
30
|
+
}
|
|
31
|
+
}else{
|
|
32
|
+
console.log('option is null');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (command.startsWith('--') || command.startsWith('-')) {
|
|
36
|
+
|
|
37
|
+
const globalOption = command.replace(/^-+/, '');
|
|
38
|
+
if(globalOption === 'version' || globalOption === 'V'){
|
|
39
|
+
console.log('the-cli-demo version 1.0.0');
|
|
40
|
+
}
|
|
41
|
+
// 处理 --version 和 --help
|
|
42
|
+
// if (command === '--version') {
|
|
43
|
+
// console.log('the-cli-demo version 1.0.0');
|
|
44
|
+
// } else if (command === '--help') {
|
|
45
|
+
// console.log('Usage: the-cli-demo <command> [options]');
|
|
46
|
+
// console.log('Commands:');
|
|
47
|
+
// console.log(' init [options] - Initialize a new project');
|
|
48
|
+
// console.log('Options:');
|
|
49
|
+
// console.log(' --name <name> - Name of the project');
|
|
50
|
+
// }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// console.log('args=>>',args);
|
|
54
|
+
|
|
55
|
+
// 实现参数解析 --version --help 和 init --name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "the-cli-demo",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,5 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"keywords": [],
|
|
13
13
|
"author": "",
|
|
14
|
-
"license": "ISC"
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"the-cli-demo-lib": "^1.1.0"
|
|
17
|
+
}
|
|
15
18
|
}
|
package/readme.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!-- 当前关联的是本地的 the-cli-demo-lib ,方便调试,后面需要关联npm仓库的,再 npm unlink 和npm install the-cli-demo-lib -S 等操作 -->
|