yzkit 1.0.3 → 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/bin/index.js +31 -18
- package/package.json +1 -1
package/bin/index.js
CHANGED
@@ -1,39 +1,52 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
3
|
import { existsSync } from "fs";
|
4
|
-
import {
|
5
|
-
import { dirname, resolve } from "path";
|
4
|
+
import { resolve } from "path";
|
6
5
|
import { execSync } from "child_process";
|
7
6
|
|
8
|
-
const
|
9
|
-
const __dirname = dirname(__filename);
|
7
|
+
const args = process.argv.slice(2);
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
if (args.length !== 1) {
|
10
|
+
console.error("❌ 请传入模块路径,例如:ui/Button 或 module/Task");
|
11
|
+
process.exit(1);
|
12
|
+
}
|
13
13
|
|
14
|
-
//
|
15
|
-
const [
|
14
|
+
const inputPath = args[0]; // 例如 ui/Button
|
15
|
+
const [type, name] = inputPath.split("/");
|
16
16
|
|
17
|
-
if (!
|
18
|
-
console.error("❌
|
17
|
+
if (!type || !name) {
|
18
|
+
console.error("❌ 输入格式错误,正确格式为 ui/ComponentName 或 module/ModuleName");
|
19
19
|
process.exit(1);
|
20
20
|
}
|
21
21
|
|
22
|
-
const
|
23
|
-
|
24
|
-
|
22
|
+
const TYPE_MAP = {
|
23
|
+
ui: {
|
24
|
+
label: "UI 组件",
|
25
|
+
repo: "youzi20/yz-cli/templates/ui",
|
26
|
+
destDir: "src/components",
|
27
|
+
},
|
28
|
+
module: {
|
29
|
+
label: "业务模块",
|
30
|
+
repo: "youzi20/yz-cli/templates/modules",
|
31
|
+
destDir: "src/modules",
|
32
|
+
},
|
33
|
+
};
|
34
|
+
|
35
|
+
const config = TYPE_MAP[type];
|
36
|
+
if (!config) {
|
37
|
+
console.error(`❌ 不支持的类型:${type},支持 ui 或 module`);
|
25
38
|
process.exit(1);
|
26
39
|
}
|
27
40
|
|
28
|
-
|
29
|
-
const dest = resolve(process.cwd(), "src", name);
|
41
|
+
const dest = resolve(process.cwd(), config.destDir, name);
|
30
42
|
|
31
43
|
if (existsSync(dest)) {
|
32
44
|
console.error(`❌ 目标目录已存在: ${dest}`);
|
33
45
|
process.exit(1);
|
34
46
|
}
|
35
47
|
|
36
|
-
|
37
|
-
|
48
|
+
const remotePath = `${config.repo}/${name}`;
|
49
|
+
console.log(`🚀 正在从 GitHub 拉取模板: ${remotePath}`);
|
50
|
+
execSync(`npx degit ${remotePath} "${dest}"`, { stdio: "inherit" });
|
38
51
|
|
39
|
-
console.log(`✅
|
52
|
+
console.log(`✅ 成功复制 ${config.label}:${name} 到 ${dest}`);
|