@tanyueran/cli 0.0.22-beta.0 → 0.2.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.
Files changed (28) hide show
  1. package/README.md +6 -7
  2. package/dist/index.js +1 -1
  3. package/package.json +6 -1
  4. package/template/module/vue/vue-ts-empty/index.module.scss.hbs +6 -0
  5. package/template/module/vue/vue-ts-empty/index.vue.hbs +55 -0
  6. package/template/project/vue/vite-vue-ts/.editorconfig +8 -0
  7. package/template/project/vue/vite-vue-ts/.env +0 -0
  8. package/template/project/vue/vite-vue-ts/.env.dev +1 -0
  9. package/template/project/vue/vite-vue-ts/.env.qa +1 -0
  10. package/template/project/vue/vite-vue-ts/.gitattributes +1 -0
  11. package/template/project/vue/vite-vue-ts/.prettierrc.json +6 -0
  12. package/template/project/vue/vite-vue-ts/.vscode/extensions.json +8 -0
  13. package/template/project/vue/vite-vue-ts/README.md +39 -0
  14. package/template/project/vue/vite-vue-ts/build/plugins/vite-plugin-html-replace-flag.js +13 -0
  15. package/template/project/vue/vite-vue-ts/env.d.ts +1 -0
  16. package/template/project/vue/vite-vue-ts/eslint.config.ts +22 -0
  17. package/template/project/vue/vite-vue-ts/index.html +13 -0
  18. package/template/project/vue/vite-vue-ts/package.json.hbs +40 -0
  19. package/template/project/vue/vite-vue-ts/pnpm-lock.yaml +3219 -0
  20. package/template/project/vue/vite-vue-ts/public/favicon.ico +0 -0
  21. package/template/project/vue/vite-vue-ts/src/App.vue +15 -0
  22. package/template/project/vue/vite-vue-ts/src/main.ts +12 -0
  23. package/template/project/vue/vite-vue-ts/src/router/index.ts +23 -0
  24. package/template/project/vue/vite-vue-ts/src/stores/counter.ts +12 -0
  25. package/template/project/vue/vite-vue-ts/src/views/about/index.vue +28 -0
  26. package/template/project/vue/vite-vue-ts/src/views/home/index.vue +28 -0
  27. package/template/project/vue/vite-vue-ts/tsconfig.json +22 -0
  28. package/template/project/vue/vite-vue-ts/vite.config.ts +45 -0
package/README.md CHANGED
@@ -16,15 +16,14 @@ Options:
16
16
  -h, --help display help for command
17
17
 
18
18
  Commands:
19
- create 创建项目
20
- add 添加模块
19
+ create <project-name> 创建项目
20
+ add <module-name> 添加模块
21
21
  help [command] display help for command
22
22
 
23
- tx-cli create <project-name>
24
- tx-cli add <module-name>
25
-
26
23
  ```
27
24
 
28
25
  ## TODO
29
- - [ ] 创建项目
30
- - [x] 创建模块
26
+ - [x] 创建项目
27
+ - [x] 创建模块
28
+ - [x] server 命令(启用一个本地服务器)
29
+ - [ ] copy 命令(复制文件,支持过滤某些文件)tx-cli copy <src> <dest> --filter <filter>
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t,a=require("commander"),s=require("prompts"),o=require("node:path"),n=require("fs-extra"),r=require("handlebars");!function(e){e.ViteVueTs="vite-vue-ts",e.WebpackVueTs="webpack-vue-ts"}(e||(e={})),function(e){e.VueTsPageTemplate="vue-ts-page-template",e.VueTsDetailTemplate="vue-ts-detail-template",e.VueTsEmpty="vue-ts-empty"}(t||(t={}));const c=[{label:"vite + vue + ts项目",value:e.ViteVueTs,path:"./src/template/project/vue/vite-vue-ts"},{label:"webpack + vue + ts项目",value:e.WebpackVueTs,path:"./src/template/project/vue/webpack-vue-ts"}],i=[{label:"vue-ts的空模板",value:t.VueTsEmpty,path:"./template/module/vue/vue-ts-empty"}];const l=require("node:path");function p(e){const{targetPath:t,sourcePath:a,templateData:s}=e;if(n.statSync(a).isDirectory()){n.readdirSync(a).forEach(e=>{p({targetPath:l.join(t,e),sourcePath:l.join(a,e),templateData:s})})}else if(a.endsWith(".hbs")){const e=n.readFileSync(a),o=r.compile(e.toString())(s);n.writeFileSync(t.replace(".hbs",""),o)}else n.copyFileSync(a,t)}function m(e){const{targetPath:t,sourcePath:a}=e;if(!n.statSync(a).isDirectory())throw new Error("源文件路劲必须是一个目录");n.existsSync(t)&&n.removeSync(t),n.mkdirSync(t,{recursive:!0}),p(e)}r.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 u=require("picocolors"),v=new a.Command;v.name("tx cli").description("一个简单CLI 工具").version("0.0.22-beta.0"),v.option("-m, --module-name <moduleName>","模块名称").option("-p, --project-name <projectName>","项目名称"),v.command("create").description("创建项目").action(async()=>{let e=v.opts().projectName;if(!e){const t=await s([{type:"text",name:"name",message:"请输入模块名"}]);e=t.name?t.name:"test-project-name"}const t=await s([{type:"select",name:"template",message:"请选择模板",choices:c.map(e=>({title:e.label,value:e.value}))}]);console.log(u.green()),console.log(u.green(t.template)),console.log(u.red("项目模板正在建设中,请稍后"))}),v.command("add").description("添加模块").action(async()=>{let e=v.opts().moduleName;if(!e){const t=await s([{type:"text",name:"name",message:"请输入模块名"}]);e=t.name?t.name:"test-module-name"}const t=await s([{type:"select",name:"template",message:"请选择模板",choices:i.map(e=>({title:e.label,value:e.value}))}]);console.log(u.green("模板名称:"+e)),console.log(u.green("选择模板:"+t.template));const a=i.find(e=>e.value===t.template);m({targetPath:o.resolve(process.cwd(),e),sourcePath:o.resolve(__dirname,a.path),templateData:{name:e}})}),exports.start=function(){v.parse(process.argv)};
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.0");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.0.22-beta.0",
3
+ "version": "0.2.0",
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",
@@ -0,0 +1,6 @@
1
+ .{{ name }}-wrapper {
2
+ width: 100%;
3
+ height: 100%;
4
+ :global {
5
+ }
6
+ }
@@ -0,0 +1,55 @@
1
+ <template>
2
+ <div :class="style['{{name}}-wrapper']">{{ name }}</div>
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { defineOptions } from "vue";
7
+ import style from "./index.module.scss";
8
+
9
+ defineOptions({
10
+ name: "{{ toPascalCase name}}",
11
+ });
12
+
13
+ // #region Props
14
+ // default
15
+ // const props = withDefaults(defineProps<{}>(), {});
16
+ // props
17
+ // const props = defineProps<{}>();
18
+ // #endregion
19
+
20
+ // #region Emits
21
+ // const emits = defineEmits<{
22
+ // // (e: 'eventName', 参数1: '', 参数2: '', ...): void;
23
+ // }>();
24
+ // #endregion
25
+
26
+ // #region Hooks
27
+ // #endregion
28
+
29
+ // #region Vars
30
+ // #endregion
31
+
32
+ // #region Computed
33
+ // #endregion
34
+
35
+ // #region Methods
36
+ // #endregion
37
+
38
+ // #region Public
39
+ // #endregion
40
+
41
+ // #region Event Handler
42
+ // #endregion
43
+
44
+ // #region Watch
45
+ // #endregion
46
+
47
+ // #region Life Cycle
48
+ // onBeforeMount(() => {});
49
+ // onMounted(() => {});
50
+ // onBeforeUpdate(() => {});
51
+ // onUpdated(() => {});
52
+ // onBeforeUnmount(() => {});
53
+ // onUnmounted(() => {});
54
+ // #endregion
55
+ </script>
@@ -0,0 +1,8 @@
1
+ [*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}]
2
+ charset = utf-8
3
+ indent_size = 2
4
+ indent_style = space
5
+ insert_final_newline = true
6
+ trim_trailing_whitespace = true
7
+ end_of_line = lf
8
+ max_line_length = 100
File without changes
@@ -0,0 +1 @@
1
+ MODE=dev
@@ -0,0 +1 @@
1
+ MODE=qa
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/prettierrc",
3
+ "semi": false,
4
+ "singleQuote": true,
5
+ "printWidth": 100
6
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "recommendations": [
3
+ "Vue.volar",
4
+ "dbaeumer.vscode-eslint",
5
+ "EditorConfig.EditorConfig",
6
+ "esbenp.prettier-vscode"
7
+ ]
8
+ }
@@ -0,0 +1,39 @@
1
+ # vite-vue-ts
2
+
3
+ This template should help get you started developing with Vue 3 in Vite.
4
+
5
+ ## Recommended IDE Setup
6
+
7
+ [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8
+
9
+ ## Type Support for `.vue` Imports in TS
10
+
11
+ TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
12
+
13
+ ## Customize configuration
14
+
15
+ See [Vite Configuration Reference](https://vite.dev/config/).
16
+
17
+ ## Project Setup
18
+
19
+ ```sh
20
+ pnpm install
21
+ ```
22
+
23
+ ### Compile and Hot-Reload for Development
24
+
25
+ ```sh
26
+ pnpm dev
27
+ ```
28
+
29
+ ### Type-Check, Compile and Minify for Production
30
+
31
+ ```sh
32
+ pnpm build
33
+ ```
34
+
35
+ ### Lint with [ESLint](https://eslint.org/)
36
+
37
+ ```sh
38
+ pnpm lint
39
+ ```
@@ -0,0 +1,13 @@
1
+ import pkg from '../../package.json'
2
+
3
+ export function VitePluginHtmlReplaceFlag() {
4
+ return {
5
+ name: 'vite-plugin-html-replace-flag',
6
+ transformIndexHtml(html) {
7
+ // 添加版本号
8
+ return html
9
+ .replace(`version="%version%"`, `version="${pkg.version}"`)
10
+ .replace(`build-time="%buildTime%"`, `build-time="${new Date().toLocaleString()}"`)
11
+ },
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,22 @@
1
+ import { globalIgnores } from 'eslint/config'
2
+ import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
3
+ import pluginVue from 'eslint-plugin-vue'
4
+ import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
5
+
6
+ // To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
7
+ // import { configureVueProject } from '@vue/eslint-config-typescript'
8
+ // configureVueProject({ scriptLangs: ['ts', 'tsx'] })
9
+ // More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup
10
+
11
+ export default defineConfigWithVueTs(
12
+ {
13
+ name: 'app/files-to-lint',
14
+ files: ['**/*.{ts,mts,tsx,vue}'],
15
+ },
16
+
17
+ globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),
18
+
19
+ pluginVue.configs['flat/essential'],
20
+ vueTsConfigs.recommended,
21
+ skipFormatting,
22
+ )
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="zh_CN" version="%version%" build-time="%buildTime%">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/src/main.ts"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "type": "module",
6
+ "engines": {
7
+ "node": "^20.19.0 || >=22.12.0"
8
+ },
9
+ "scripts": {
10
+ "dev": "vite --mode dev",
11
+ "preview": "vite preview",
12
+ "build": "vite build",
13
+ "type-check": "vue-tsc --build",
14
+ "lint": "eslint . --fix",
15
+ "format": "prettier --write src/"
16
+ },
17
+ "dependencies": {
18
+ "pinia": "^3.0.3",
19
+ "vue": "^3.5.18",
20
+ "vue-router": "^4.5.1"
21
+ },
22
+ "devDependencies": {
23
+ "@tsconfig/node22": "^22.0.2",
24
+ "@types/node": "^22.16.5",
25
+ "@vitejs/plugin-vue": "^6.0.1",
26
+ "@vitejs/plugin-vue-jsx": "^5.0.1",
27
+ "@vue/eslint-config-prettier": "^10.2.0",
28
+ "@vue/eslint-config-typescript": "^14.6.0",
29
+ "@vue/tsconfig": "^0.7.0",
30
+ "eslint": "^9.31.0",
31
+ "eslint-plugin-vue": "~10.3.0",
32
+ "jiti": "^2.4.2",
33
+ "npm-run-all2": "^8.0.4",
34
+ "prettier": "3.6.2",
35
+ "typescript": "~5.8.0",
36
+ "vite": "^7.0.6",
37
+ "vite-plugin-vue-devtools": "^8.0.0",
38
+ "vue-tsc": "^3.0.4"
39
+ }
40
+ }