@tanyueran/cli 0.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/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @tanyueran/cli
2
+
3
+ | 一个命令行工具
4
+
5
+ ## 安装
6
+ | npm install -g @tanyueran/cli
7
+
8
+
9
+ ## 用法
10
+ ```text
11
+
12
+ Options:
13
+ -V, --version output the version number
14
+ -m, --module-name <moduleName> 模块名称
15
+ -p, --project-name <projectName> 项目名称
16
+ -h, --help display help for command
17
+
18
+ Commands:
19
+ create 创建项目
20
+ add 添加模块
21
+ help [command] display help for command
22
+
23
+ tx-cli create <project-name>
24
+ tx-cli add <module-name>
25
+
26
+ ```
package/bin/tx-cli ADDED
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env node
2
+ const { start } = require("../dist/index.js");
3
+
4
+ start();
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e,t,a=require("commander"),s=require("prompts"),o=require("node:path"),l=require("fs-extra"),n=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 r=[{label:"vite + vue + ts项目",value:e.ViteVueTs,path:"../packages/template/project/vue/vite-vue-ts"},{label:"webpack + vue + ts项目",value:e.WebpackVueTs,path:"../packages/template/project/vue/webpack-vue-ts"}],c=[{label:"vue-ts的页面模板",value:t.VueTsPageTemplate,path:"../template/module/vue/vue-ts-page-template"},{label:"vue-ts的详情模板",value:t.VueTsDetailTemplate,path:"../template/module/vue/vue-ts-detail-template"},{label:"vue-ts的空模板",value:t.VueTsEmpty,path:"../template/module/vue/vue-ts-empty"}];const p=require("node:path");function i(e){const{targetPath:t,sourcePath:a,templateData:s}=e;if(l.statSync(a).isDirectory()){l.readdirSync(a).forEach(e=>{i({targetPath:p.join(t,e),sourcePath:p.join(a,e),templateData:s})})}else if(a.endsWith(".hbs")){const e=l.readFileSync(a),o=n.compile(e.toString())(s);l.writeFileSync(t.replace(".hbs",""),o)}else l.copyFileSync(a,t)}function m(e){const{targetPath:t,sourcePath:a}=e;if(!l.statSync(a).isDirectory())throw new Error("源文件路劲必须是一个目录");l.existsSync(t)&&l.removeSync(t),l.mkdirSync(t,{recursive:!0}),i(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 u=require("picocolors"),v=new a.Command;v.name("tx cli").description("一个简单CLI 工具").version("0.0.1"),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:r.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:c.map(e=>({title:e.label,value:e.value}))}]);console.log(u.green("模板名称:"+e)),console.log(u.green("选择模板:"+t.template));const a=c.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)};
package/index.ts ADDED
@@ -0,0 +1,115 @@
1
+ import { Command } from "commander";
2
+ import prompts from "prompts";
3
+ import * as pkg from "./package.json";
4
+ const pico = require("picocolors");
5
+ import path from "node:path";
6
+ import { ProjectTemplateData, ModuleTemplateData } from "./constant/template";
7
+ import { DefaultModuleName, DefaultProjectName } from "./constant/constant";
8
+ import { processor } from "./processor/index";
9
+
10
+ const program = new Command();
11
+
12
+ program.name("tx cli").description("一个简单CLI 工具").version(pkg.version);
13
+
14
+ // 定义命令后面的options
15
+ program
16
+ .option("-m, --module-name <moduleName>", "模块名称")
17
+ .option("-p, --project-name <projectName>", "项目名称");
18
+
19
+ /**
20
+ * 定义命令
21
+ * tx create <project-name> => 选择模板
22
+ * tx add <module-name> =》选择模板
23
+ */
24
+
25
+ // -创建项目
26
+ program
27
+ .command("create")
28
+ .description("创建项目")
29
+ .action(async () => {
30
+ let projectName = program.opts().projectName;
31
+ // option 中没有携带模块名称时,让用户自己在输入
32
+ if (!projectName) {
33
+ const result = await prompts([
34
+ {
35
+ type: "text",
36
+ name: "name",
37
+ message: "请输入模块名",
38
+ },
39
+ ]);
40
+ projectName = result.name ? result.name : DefaultProjectName;
41
+ }
42
+ // prompts
43
+ const response = await prompts([
44
+ {
45
+ type: "select",
46
+ name: "template",
47
+ message: "请选择模板",
48
+ choices: ProjectTemplateData.map((item) => {
49
+ return {
50
+ title: item.label,
51
+ value: item.value,
52
+ };
53
+ }),
54
+ },
55
+ ]);
56
+ console.log(pico.green());
57
+ console.log(pico.green(response.template));
58
+ // TODO
59
+ console.log(pico.red("项目模板正在建设中,请稍后"));
60
+ });
61
+
62
+ // -添加模块
63
+ program
64
+ .command("add")
65
+ .description("添加模块")
66
+ .action(async () => {
67
+ let moduleName = program.opts().moduleName;
68
+ // option 中没有携带模块名称时,让用户自己在输入
69
+ if (!moduleName) {
70
+ const result = await prompts([
71
+ {
72
+ type: "text",
73
+ name: "name",
74
+ message: "请输入模块名",
75
+ },
76
+ ]);
77
+ moduleName = result.name ? result.name : DefaultModuleName;
78
+ }
79
+ // 询问创建的 模板等
80
+ // prompts
81
+ const response = await prompts([
82
+ {
83
+ type: "select",
84
+ name: "template",
85
+ message: "请选择模板",
86
+ choices: ModuleTemplateData.map((item) => ({
87
+ title: item.label,
88
+ value: item.value,
89
+ })),
90
+ },
91
+ ]);
92
+ console.log(pico.green("模板名称:" + moduleName));
93
+ console.log(pico.green("选择模板:" + response.template));
94
+
95
+ const selectedTemplate = ModuleTemplateData.find(
96
+ (item) => item.value === response.template
97
+ );
98
+ const targetPath = path.resolve(process.cwd(), moduleName);
99
+ const sourcePath = path.resolve(__dirname, selectedTemplate!.path);
100
+
101
+ processor({
102
+ targetPath,
103
+ sourcePath,
104
+ templateData: {
105
+ name: moduleName,
106
+ },
107
+ });
108
+
109
+ // TODO
110
+ // 接入AI,通过AI去实现,你的描述表达的案例
111
+ });
112
+
113
+ export function start() {
114
+ program.parse(process.argv);
115
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@tanyueran/cli",
3
+ "version": "0.0.2",
4
+ "description": "一个cli工具",
5
+ "main": "index.ts",
6
+ "bin": {
7
+ "tx-cli": "./bin/tx-cli"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "dist",
12
+ "template",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "dev": "pnpm run build && ./bin/tx-cli",
17
+ "build": "rollup --config rollup.config.js"
18
+ },
19
+ "keywords": [
20
+ "cli"
21
+ ],
22
+ "author": "tanyueran",
23
+ "license": "ISC",
24
+ "packageManager": "pnpm@10.5.2",
25
+ "peerDependencies": {
26
+ "commander": "12.1.0",
27
+ "fs-extra": "11.1.1",
28
+ "handlebars": "4.7.7",
29
+ "picocolors": "1.1.1",
30
+ "prompts": "2.4.2",
31
+ "table": "6.8.1"
32
+ },
33
+ "dependencies": {
34
+ "commander": "12.1.0",
35
+ "fs-extra": "11.1.1",
36
+ "handlebars": "4.7.7",
37
+ "picocolors": "1.1.1",
38
+ "prompts": "2.4.2",
39
+ "table": "6.8.1"
40
+ },
41
+ "devDependencies": {
42
+ "@rollup/plugin-commonjs": "^28.0.6",
43
+ "@rollup/plugin-json": "^6.1.0",
44
+ "@rollup/plugin-typescript": "^12.1.4",
45
+ "@types/fs-extra": "^11.0.4",
46
+ "@types/prompts": "2.4.2",
47
+ "rollup": "4.46.2",
48
+ "rollup-plugin-terser": "^7.0.2",
49
+ "ts-node": "10.9.1",
50
+ "tslib": "^2.8.1",
51
+ "typescript": "5.2.2"
52
+ }
53
+ }
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <div></div>
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { ref } from "vue";
7
+
8
+ // #region Prop
9
+ //#endregion
10
+
11
+ // #region 变量
12
+ //#endregion
13
+
14
+ // #region 计算属性
15
+ //#endregion
16
+
17
+ // #region 监听器
18
+ //#endregion
19
+
20
+ // #region 方法
21
+ //#endregion
22
+
23
+ // #region 生命周期
24
+ //#endregion
25
+ </script>
@@ -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,25 @@
1
+ <template>
2
+ <div></div>
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { ref } from "vue";
7
+
8
+ // #region Prop
9
+ //#endregion
10
+
11
+ // #region 变量
12
+ //#endregion
13
+
14
+ // #region 计算属性
15
+ //#endregion
16
+
17
+ // #region 监听器
18
+ //#endregion
19
+
20
+ // #region 方法
21
+ //#endregion
22
+
23
+ // #region 生命周期
24
+ //#endregion
25
+ </script>