ljr-cli 1.0.0
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/lib/index.js +23 -0
- package/package.json +19 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 第一行固定写法,指定脚本的解释器路径(注意:第一行不要添加注释啥的,不然运行不起来)
|
|
3
|
+
|
|
4
|
+
const { program } = require("commander")
|
|
5
|
+
|
|
6
|
+
// 获取包的版本
|
|
7
|
+
const version = require("../package.json").version
|
|
8
|
+
|
|
9
|
+
program.version(version, "-v, --version")
|
|
10
|
+
|
|
11
|
+
program
|
|
12
|
+
.command("init <name>") // 定义命令和参数
|
|
13
|
+
.description("创建项目") // 命令描述
|
|
14
|
+
.option("-l, --local", "从本地模板创建目录") // 定义选项
|
|
15
|
+
.option("-g, --git", "从git地址创建目录") // 定义选项
|
|
16
|
+
// 命令的回调函数
|
|
17
|
+
.action((name, options) => {
|
|
18
|
+
console.log("项目名=====>", name)
|
|
19
|
+
console.log("选项=====>", options)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
// 让commander解析process.argv的参数
|
|
23
|
+
program.parse(process.argv)
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ljr-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ljr": "lib/index.js",
|
|
8
|
+
"ljr-cli": "lib/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"发布": "npm publish"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"commander": "^14.0.2"
|
|
18
|
+
}
|
|
19
|
+
}
|