yzkit 1.0.1 → 1.0.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 +5 -7
- package/bin/index.js +37 -73
- package/package.json +3 -4
package/README.md
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# yzkit
|
2
2
|
|
3
|
-
|
3
|
+
一个从 GitHub 拉取组件/模块模板并自动生成到本地项目的工具。
|
4
4
|
|
5
|
-
|
5
|
+
## 快速开始
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
无需安装,使用 `pnpm dlx` 直接运行:
|
7
|
+
使用 `pnpm dlx` 快速执行(无需安装):
|
10
8
|
|
11
9
|
```bash
|
12
|
-
pnpm dlx yzkit
|
10
|
+
pnpm dlx yzkit templates/ui/Button my-button
|
package/bin/index.js
CHANGED
@@ -1,88 +1,52 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const inquirer = require("inquirer");
|
7
|
-
const degit = require("degit");
|
3
|
+
import { existsSync } from "fs";
|
4
|
+
import { resolve } from "path";
|
5
|
+
import { execSync } from "child_process";
|
8
6
|
|
9
|
-
const
|
10
|
-
|
11
|
-
|
7
|
+
const args = process.argv.slice(2);
|
8
|
+
|
9
|
+
if (args.length !== 1) {
|
10
|
+
console.error("❌ 请传入模块路径,例如:ui/Button 或 module/Task");
|
11
|
+
process.exit(1);
|
12
|
+
}
|
13
|
+
|
14
|
+
const inputPath = args[0]; // 例如 ui/Button
|
15
|
+
const [type, name] = inputPath.split("/");
|
16
|
+
|
17
|
+
if (!type || !name) {
|
18
|
+
console.error("❌ 输入格式错误,正确格式为 ui/ComponentName 或 module/ModuleName");
|
19
|
+
process.exit(1);
|
20
|
+
}
|
12
21
|
|
13
22
|
const TYPE_MAP = {
|
14
23
|
ui: {
|
15
|
-
label: "
|
16
|
-
|
17
|
-
destDir: "src/components"
|
24
|
+
label: "UI 组件",
|
25
|
+
repo: "youzi20/yz-cli/templates/ui",
|
26
|
+
destDir: "src/components",
|
18
27
|
},
|
19
28
|
module: {
|
20
|
-
label: "
|
21
|
-
|
22
|
-
destDir: "src/modules"
|
23
|
-
}
|
29
|
+
label: "业务模块",
|
30
|
+
repo: "youzi20/yz-cli/templates/modules",
|
31
|
+
destDir: "src/modules",
|
32
|
+
},
|
24
33
|
};
|
25
34
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
const emitter = degit(`${GITHUB_REPO}/${subdir}`, {
|
31
|
-
cache: true,
|
32
|
-
force: true,
|
33
|
-
verbose: false
|
34
|
-
});
|
35
|
-
await emitter.clone(cachePath);
|
36
|
-
}
|
37
|
-
return cachePath;
|
35
|
+
const config = TYPE_MAP[type];
|
36
|
+
if (!config) {
|
37
|
+
console.error(`❌ 不支持的类型:${type},支持 ui 或 module`);
|
38
|
+
process.exit(1);
|
38
39
|
}
|
39
40
|
|
40
|
-
|
41
|
-
const { type } = await inquirer.prompt([
|
42
|
-
{
|
43
|
-
type: "list",
|
44
|
-
name: "type",
|
45
|
-
message: "请选择要添加的类型:",
|
46
|
-
choices: Object.entries(TYPE_MAP).map(([key, value]) => ({
|
47
|
-
name: value.label,
|
48
|
-
value: key
|
49
|
-
}))
|
50
|
-
}
|
51
|
-
]);
|
52
|
-
|
53
|
-
const config = TYPE_MAP[type];
|
41
|
+
const dest = resolve(process.cwd(), config.destDir, name);
|
54
42
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
const available = fs.readdirSync(templateDir).filter((f) =>
|
59
|
-
fs.statSync(path.join(templateDir, f)).isDirectory()
|
60
|
-
);
|
61
|
-
|
62
|
-
if (available.length === 0) {
|
63
|
-
console.error(`❌ 没有可用模板`);
|
64
|
-
process.exit(1);
|
65
|
-
}
|
66
|
-
|
67
|
-
const { selected } = await inquirer.prompt([
|
68
|
-
{
|
69
|
-
type: "list",
|
70
|
-
name: "selected",
|
71
|
-
message: `请选择要添加的${config.label}:`,
|
72
|
-
choices: available
|
73
|
-
}
|
74
|
-
]);
|
75
|
-
|
76
|
-
const src = path.join(templateDir, selected);
|
77
|
-
const dest = path.resolve(process.cwd(), config.destDir, selected);
|
78
|
-
|
79
|
-
if (fs.existsSync(dest)) {
|
80
|
-
console.error(`❌ 目标目录已存在: ${dest}`);
|
81
|
-
process.exit(1);
|
82
|
-
}
|
83
|
-
|
84
|
-
copySync(src, dest);
|
85
|
-
console.log(`✅ 已成功添加 ${config.label}:${selected} 到 ${dest}`);
|
43
|
+
if (existsSync(dest)) {
|
44
|
+
console.error(`❌ 目标目录已存在: ${dest}`);
|
45
|
+
process.exit(1);
|
86
46
|
}
|
87
47
|
|
88
|
-
|
48
|
+
const remotePath = `${config.repo}/${name}`;
|
49
|
+
console.log(`🚀 正在从 GitHub 拉取模板: ${remotePath}`);
|
50
|
+
execSync(`npx degit ${remotePath} "${dest}"`, { stdio: "inherit" });
|
51
|
+
|
52
|
+
console.log(`✅ 成功复制 ${config.label}:${name} 到 ${dest}`);
|
package/package.json
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "yzkit",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.4",
|
4
4
|
"description": "A CLI tool to scaffold modules and components",
|
5
|
+
"type": "module",
|
5
6
|
"bin": {
|
6
7
|
"yzkit": "./bin/index.js"
|
7
8
|
},
|
@@ -12,8 +13,6 @@
|
|
12
13
|
"node": ">=14"
|
13
14
|
},
|
14
15
|
"dependencies": {
|
15
|
-
"
|
16
|
-
"inquirer": "^12。6.0",
|
17
|
-
"degit": "^2.8.0"
|
16
|
+
"degit": "^2.8.4"
|
18
17
|
}
|
19
18
|
}
|