@tanyueran/cli 0.4.2 → 0.4.4
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 +3 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tanyueran/cli
|
|
2
2
|
|
|
3
|
-
|
|
|
3
|
+
| 一个命令行工具,可以创建项目,添加模块,以及支持一些简单的工具操作命令
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
@@ -20,9 +20,8 @@ Commands:
|
|
|
20
20
|
add [options] <module-name> 添加模块
|
|
21
21
|
create [options] <project-name> 创建项目
|
|
22
22
|
server [options] 启动一个本地HTTP服务器
|
|
23
|
+
git-rename <old-name> <new-name> git重命名模块名称(主要用于git跟踪的文件的名称大小写的转换)
|
|
23
24
|
help [command] display help for command
|
|
24
|
-
git-rename [options] <old-name> <new-name> git重命名模块名称
|
|
25
|
-
|
|
26
25
|
```
|
|
27
26
|
|
|
28
27
|
## TODO
|
|
@@ -30,4 +29,5 @@ Commands:
|
|
|
30
29
|
- [x] 创建项目 tx create <project-name>
|
|
31
30
|
- [x] 创建模块 tx add <module-name>
|
|
32
31
|
- [x] server 命令(启用一个本地服务器) tx server
|
|
32
|
+
- [x] git-rename 命令(git 重命名模块名称) tx-cli git-rename <old-name> <new-name>
|
|
33
33
|
- [ ] copy 命令(复制文件,支持过滤某些文件)tx-cli copy <src> <dest> --filter <filter>
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("prompts"),t=require("node:path"),
|
|
1
|
+
"use strict";var e=require("prompts"),t=require("picocolors"),o=require("node:path"),s=require("fs-extra"),n=require("handlebars"),r=require("commander"),a=require("node:http"),c=require("connect"),i=require("serve-static"),l=require("open"),p=require("node:process"),m=require("node:fs"),u=require("simple-git");var d,v;!function(e){e.ViteVueTs="vite-vue-ts",e.WebpackVueTs="webpack-vue-ts"}(d||(d={})),function(e){e.VueTsPageTemplate="vue-ts-page-template",e.VueTsDetailTemplate="vue-ts-detail-template",e.VueTsEmpty="vue-ts-empty"}(v||(v={}));const h=[{label:"vite + vue + ts项目",value:d.ViteVueTs,path:"../template/project/vue/vite-vue-ts"}],g=[{label:"vue-ts的空模板",value:v.VueTsEmpty,path:"../template/module/vue/vue-ts-empty"}];function w(e){const{targetPath:t,sourcePath:r,templateData:a}=e;if(s.statSync(r).isDirectory()){s.mkdirSync(t,{recursive:!0}),s.readdirSync(r).forEach(e=>{w({targetPath:o.join(t,e),sourcePath:o.join(r,e),templateData:a})})}else if(r.endsWith(".hbs")){const e=s.readFileSync(r),o=n.compile(e.toString())(a);s.writeFileSync(t.replace(".hbs",""),o)}else s.copyFileSync(r,t)}function y(e){const{targetPath:t,sourcePath:o}=e;if(!s.statSync(o).isDirectory())throw new Error("源文件路劲必须是一个目录");s.existsSync(t)&&s.removeSync(t),s.mkdirSync(t,{recursive:!0}),w(e)}n.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 f=new r.Command;function S(e={}){const{port:t=8080,host:s="localhost",directory:n=process.cwd(),openBrowser:r=!1,silent:p=!1,header:m={}}=e,u=c();u.use(i(o.resolve(n),{setHeaders:(...e)=>function(e,t,o,s){for(const[t,o]of Object.entries(s))e.setHeader(t,o)}(...e,m)})),u.use((e,t)=>{t.statusCode=404,t.end("Not Found")});const d=a.createServer(u);return d.listen(t,s,()=>{const e=`http://${s}:${t}`;p||(console.log("> 本地开发服务器已启动"),console.log(`> 访问地址: ${e}`),console.log(`> 服务目录: ${n}`),console.log("> 按 Ctrl+C 停止服务器")),r&&l(e).catch(e=>{console.warn(`无法自动打开浏览器: ${e.message}`)})}),process.on("SIGINT",()=>{console.log("\n> 正在关闭服务器..."),d.close(()=>{console.log("> 服务器已停止。"),process.exit(0)})}),d}function P(e){if(!m.existsSync(e))return!1;const t=o.dirname(e),s=o.basename(e);return m.readdirSync(t).includes(s)}f.name("tx cli").description("一个简单CLI 工具").version("0.4.4"),f.command("add <module-name>").description("添加模块").option("-m, --module-name <moduleName>","模块名称").action(async s=>{console.log("模块名称:",s);let n=s||f.opts().moduleName;if(!n){const t=await e([{type:"text",name:"name",message:"请输入模块名"}]);n=t.name?t.name:"test-module-name"}const r=await e([{type:"select",name:"template",message:"请选择模板",choices:g.map(e=>({title:e.label,value:e.value}))}]);console.log(t.green("模板名称:"+n)),console.log(t.green("选择模板:"+r.template));const a=g.find(e=>e.value===r.template);y({targetPath:o.resolve(process.cwd(),n),sourcePath:o.resolve(__dirname,a.path),templateData:{name:n}})}),f.command("create <project-name>").description("创建项目").option("-p, --project-name <projectName>","项目名称").action(async s=>{let n=s||f.opts().projectName;if(console.log("项目名称:",n),!n){const t=await e([{type:"text",name:"name",message:"请输入项目名称"}]);n=t.name?t.name:"test-project-name"}const r=await e([{type:"select",name:"template",message:"请选择模板",choices:h.map(e=>({title:e.label,value:e.value}))}]);console.log(t.green("项目名称:"+r.template)),console.log(t.green("选择模板:"+n));const a=h.find(e=>e.value===r.template);y({targetPath:o.resolve(process.cwd(),n),sourcePath:o.resolve(__dirname,a.path),templateData:{name:n}}),console.log(t.green("创建成功")),console.log(t.green(`cd ./${n} && pnpm install`))}),f.command("server").description("启动一个本地HTTP服务器").option("-p, --port <number>","端口号","8080").option("-h, --host <host>","主机地址","localhost").option("-d, --directory <path>","服务的目录",".").option("-o, --open","启动后自动打开浏览器").option("-s, --silent","静默模式,不输出信息").option("--header <json>","启动服务设置的HTTP相应头","{}").action(e=>{S({...e,port:parseInt(e.port,10),openBrowser:!!e.open,silent:!!e.silent,header:JSON.parse(e.header)})}),P("./fileUtils.ts");const T=u.simpleGit();f.command("git-rename <old-model-url> <new-model-url>").description("git重命名模块").action(async(e,t)=>{const s=p.cwd(),n=o.resolve(s,e),r=o.resolve(s,t);if(!P(n))throw new Error(`${n}文件不存在`);if(P(r))throw new Error(`${r}文件已存在`);const a=await T.status(),c=await T.revparse(["--show-toplevel"]);if(a.not_added.map(e=>o.resolve(c,e)).includes(n)||(a.ignored||[]).map(e=>o.resolve(c,e)).includes(n))throw new Error(`文件${n}未被git跟踪`);const i=o.basename(n),l=`___${i}`,m=n.replace(i,l);await T.mv(n,m),await T.mv(m,r)}),exports.start=function(){f.parse(process.argv)};
|