@tanyueran/cli 0.0.17 → 0.0.20
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
CHANGED
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:"
|
|
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.20"),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)};
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanyueran/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "一个cli工具",
|
|
5
|
-
"main": "index.ts",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
6
|
"bin": {
|
|
7
7
|
"tx-cli": "./bin/tx-cli"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
|
11
11
|
"dist",
|
|
12
|
-
"template"
|
|
13
|
-
"README.md"
|
|
12
|
+
"template"
|
|
14
13
|
],
|
|
15
14
|
"scripts": {
|
|
16
15
|
"dev": "pnpm run build && ./bin/tx-cli",
|
|
17
16
|
"build": "rollup --config rollup.config.js",
|
|
18
|
-
"publish-pkg": "node ./script/publish.cjs"
|
|
17
|
+
"publish-pkg": "node ./script/publish.cjs",
|
|
18
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"cli"
|
|
@@ -29,19 +29,20 @@
|
|
|
29
29
|
"handlebars": "4.7.7",
|
|
30
30
|
"picocolors": "1.1.1",
|
|
31
31
|
"prompts": "2.4.2",
|
|
32
|
-
"table": "6.8.
|
|
32
|
+
"table": "6.8.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@rollup/plugin-commonjs": "
|
|
36
|
-
"@rollup/plugin-json": "
|
|
37
|
-
"@rollup/plugin-typescript": "
|
|
38
|
-
"@types/fs-extra": "
|
|
35
|
+
"@rollup/plugin-commonjs": "28.0.6",
|
|
36
|
+
"@rollup/plugin-json": "6.1.0",
|
|
37
|
+
"@rollup/plugin-typescript": "12.1.4",
|
|
38
|
+
"@types/fs-extra": "11.0.4",
|
|
39
39
|
"@types/prompts": "2.4.2",
|
|
40
|
+
"conventional-changelog-cli": "5.0.0",
|
|
40
41
|
"rollup": "4.46.2",
|
|
41
|
-
"rollup-plugin-terser": "
|
|
42
|
+
"rollup-plugin-terser": "7.0.2",
|
|
43
|
+
"simple-git": "3.28.0",
|
|
42
44
|
"ts-node": "10.9.1",
|
|
43
|
-
"tslib": "
|
|
44
|
-
"typescript": "5.
|
|
45
|
-
"simple-git": "3.28.0"
|
|
45
|
+
"tslib": "2.8.1",
|
|
46
|
+
"typescript": "5.9.2"
|
|
46
47
|
}
|
|
47
|
-
}
|
|
48
|
+
}
|
package/index.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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>
|