@tanyueran/cli 0.1.0 → 0.2.1
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/README.md +15 -13
- package/dist/index.js +1 -1
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -3,28 +3,30 @@
|
|
|
3
3
|
| 一个命令行工具,可以创建项目,添加模块
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
|
-
| npm install -g @tanyueran/cli
|
|
7
6
|
|
|
7
|
+
| npm install -g @tanyueran/cli
|
|
8
8
|
|
|
9
9
|
## 用法
|
|
10
|
+
|
|
10
11
|
```text
|
|
11
12
|
|
|
13
|
+
tx-cli [command] [options]
|
|
14
|
+
|
|
12
15
|
Options:
|
|
13
|
-
-V, --version
|
|
14
|
-
-
|
|
15
|
-
-p, --project-name <projectName> 项目名称
|
|
16
|
-
-h, --help display help for command
|
|
16
|
+
-V, --version output the version number
|
|
17
|
+
-h, --help display help for command
|
|
17
18
|
|
|
18
19
|
Commands:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
tx-cli create <project-name>
|
|
24
|
-
tx-cli add <module-name>
|
|
20
|
+
add [options] <module-name> 添加模块
|
|
21
|
+
create [options] <project-name> 创建项目
|
|
22
|
+
server [options] 启动一个本地HTTP服务器
|
|
23
|
+
help [command] display help for command
|
|
25
24
|
|
|
26
25
|
```
|
|
27
26
|
|
|
28
27
|
## TODO
|
|
29
|
-
|
|
30
|
-
- [x]
|
|
28
|
+
|
|
29
|
+
- [x] 创建项目 tx create <project-name>
|
|
30
|
+
- [x] 创建模块 tx add <module-name>
|
|
31
|
+
- [x] server 命令(启用一个本地服务器) tx server
|
|
32
|
+
- [ ] copy 命令(复制文件,支持过滤某些文件)tx-cli copy <src> <dest> --filter <filter>
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t,
|
|
1
|
+
"use strict";var e=require("prompts"),t=require("node:path"),o=require("fs-extra"),s=require("handlebars"),a=require("commander"),n=require("node:http"),r=require("connect"),c=require("serve-static"),l=require("open");var i,p;!function(e){e.ViteVueTs="vite-vue-ts",e.WebpackVueTs="webpack-vue-ts"}(i||(i={})),function(e){e.VueTsPageTemplate="vue-ts-page-template",e.VueTsDetailTemplate="vue-ts-detail-template",e.VueTsEmpty="vue-ts-empty"}(p||(p={}));const m=[{label:"vite + vue + ts项目",value:i.ViteVueTs,path:"../template/project/vue/vite-vue-ts"}],u=[{label:"vue-ts的空模板",value:p.VueTsEmpty,path:"../template/module/vue/vue-ts-empty"}];const d=require("node:path");function v(e){const{targetPath:t,sourcePath:a,templateData:n}=e;if(o.statSync(a).isDirectory()){o.mkdirSync(t,{recursive:!0}),o.readdirSync(a).forEach(e=>{v({targetPath:d.join(t,e),sourcePath:d.join(a,e),templateData:n})})}else if(a.endsWith(".hbs")){const e=o.readFileSync(a),r=s.compile(e.toString())(n);o.writeFileSync(t.replace(".hbs",""),r)}else o.copyFileSync(a,t)}function g(e){const{targetPath:t,sourcePath:s}=e;if(!o.statSync(s).isDirectory())throw new Error("源文件路劲必须是一个目录");o.existsSync(t)&&o.removeSync(t),o.mkdirSync(t,{recursive:!0}),v(e)}s.registerHelper("toPascalCase",function(e){return function(e){return e&&"string"==typeof e?e.split(/[\s-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(""):e}(e)});const h=new a.Command;h.name("tx cli").description("一个简单CLI 工具").version("0.2.1");const y=require("picocolors");h.command("add <module-name>").description("添加模块").option("-m, --module-name <moduleName>","模块名称").action(async o=>{console.log("模块名称:",o);let s=o||h.opts().moduleName;if(!s){const t=await e([{type:"text",name:"name",message:"请输入模块名"}]);s=t.name?t.name:"test-module-name"}const a=await e([{type:"select",name:"template",message:"请选择模板",choices:u.map(e=>({title:e.label,value:e.value}))}]);console.log(y.green("模板名称:"+s)),console.log(y.green("选择模板:"+a.template));const n=u.find(e=>e.value===a.template);g({targetPath:t.resolve(process.cwd(),s),sourcePath:t.resolve(__dirname,n.path),templateData:{name:s}})});const f=require("picocolors");h.command("create <project-name>").description("创建项目").option("-p, --project-name <projectName>","项目名称").action(async o=>{let s=o||h.opts().projectName;if(console.log("项目名称:",s),!s){const t=await e([{type:"text",name:"name",message:"请输入项目名称"}]);s=t.name?t.name:"test-project-name"}const a=await e([{type:"select",name:"template",message:"请选择模板",choices:m.map(e=>({title:e.label,value:e.value}))}]);console.log(f.green("项目名称:"+a.template)),console.log(f.green("选择模板:"+s));const n=m.find(e=>e.value===a.template);g({targetPath:t.resolve(process.cwd(),s),sourcePath:t.resolve(__dirname,n.path),templateData:{name:s}}),console.log(f.green("创建成功")),console.log(f.green(`cd ./${s} && pnpm install`))}),h.command("server").description("启动一个本地HTTP服务器").option("-p, --port <number>","端口号","8080").option("-h, --host <host>","主机地址","localhost").option("-d, --directory <path>","服务的目录",".").option("-o, --open","启动后自动打开浏览器").option("-s, --silent","静默模式,不输出信息").action(e=>{!function(e={}){const{port:o=8080,host:s="localhost",directory:a=process.cwd(),openBrowser:i=!1,silent:p=!1}=e,m=r();m.use(c(t.resolve(a))),m.use((e,t)=>{t.statusCode=404,t.end("Not Found")});const u=n.createServer(m);u.listen(o,s,()=>{const e=`http://${s}:${o}`;p||(console.log("> 本地开发服务器已启动"),console.log(`> 访问地址: ${e}`),console.log(`> 服务目录: ${a}`),console.log("> 按 Ctrl+C 停止服务器")),i&&l(e).catch(e=>{console.warn(`无法自动打开浏览器: ${e.message}`)})}),process.on("SIGINT",()=>{console.log("\n> 正在关闭服务器..."),u.close(()=>{console.log("> 服务器已停止。"),process.exit(0)})})}({...e,port:parseInt(e.port,10),openBrowser:!!e.open,silent:!!e.silent})}),exports.start=function(){h.parse(process.argv)};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanyueran/cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "一个cli工具,支持创建项目,添加模版",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"bin": {
|
|
@@ -25,18 +25,23 @@
|
|
|
25
25
|
"packageManager": "pnpm@10.5.2",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"commander": "12.1.0",
|
|
28
|
+
"connect": "^3.7.0",
|
|
28
29
|
"fs-extra": "11.1.1",
|
|
29
30
|
"handlebars": "4.7.7",
|
|
31
|
+
"open": "^10.2.0",
|
|
30
32
|
"picocolors": "1.1.1",
|
|
31
33
|
"prompts": "2.4.2",
|
|
34
|
+
"serve-static": "^2.2.0",
|
|
32
35
|
"table": "6.8.2"
|
|
33
36
|
},
|
|
34
37
|
"devDependencies": {
|
|
35
38
|
"@rollup/plugin-commonjs": "28.0.6",
|
|
36
39
|
"@rollup/plugin-json": "6.1.0",
|
|
37
40
|
"@rollup/plugin-typescript": "12.1.4",
|
|
41
|
+
"@types/connect": "^3.4.38",
|
|
38
42
|
"@types/fs-extra": "11.0.4",
|
|
39
43
|
"@types/prompts": "2.4.2",
|
|
44
|
+
"@types/serve-static": "^1.15.8",
|
|
40
45
|
"conventional-changelog-cli": "5.0.0",
|
|
41
46
|
"rollup": "4.46.2",
|
|
42
47
|
"rollup-plugin-terser": "7.0.2",
|
|
@@ -44,5 +49,9 @@
|
|
|
44
49
|
"ts-node": "10.9.1",
|
|
45
50
|
"tslib": "2.8.1",
|
|
46
51
|
"typescript": "5.9.2"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/tanyueran/tx-cli.git"
|
|
47
56
|
}
|
|
48
57
|
}
|