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.
Files changed (2) hide show
  1. package/bin/index.js +31 -18
  2. 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 { fileURLToPath } from "url";
5
- import { dirname, resolve } from "path";
4
+ import { resolve } from "path";
6
5
  import { execSync } from "child_process";
7
6
 
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = dirname(__filename);
7
+ const args = process.argv.slice(2);
10
8
 
11
- // 固定仓库地址
12
- const GITHUB_REPO = "youzi20/yz-cli";
9
+ if (args.length !== 1) {
10
+ console.error("❌ 请传入模块路径,例如:ui/Button module/Task");
11
+ process.exit(1);
12
+ }
13
13
 
14
- // 获取命令行参数
15
- const [remotePath, localName] = process.argv.slice(2);
14
+ const inputPath = args[0]; // 例如 ui/Button
15
+ const [type, name] = inputPath.split("/");
16
16
 
17
- if (!remotePath) {
18
- console.error("❌ 缺少远程模板路径参数。例如:templates/ui/Button");
17
+ if (!type || !name) {
18
+ console.error("❌ 输入格式错误,正确格式为 ui/ComponentName 或 module/ModuleName");
19
19
  process.exit(1);
20
20
  }
21
21
 
22
- const name = localName || remotePath.split("/").pop();
23
- if (!name) {
24
- console.error(" 无法识别目标文件夹名,请手动指定第二个参数");
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
- // 安装到当前项目的 src 目录
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
- console.log(`🚀 拉取模板: ${GITHUB_REPO}/${remotePath}`);
37
- execSync(`npx degit ${GITHUB_REPO}/${remotePath} ${dest}`, { stdio: "inherit" });
48
+ const remotePath = `${config.repo}/${name}`;
49
+ console.log(`🚀 正在从 GitHub 拉取模板: ${remotePath}`);
50
+ execSync(`npx degit ${remotePath} "${dest}"`, { stdio: "inherit" });
38
51
 
39
- console.log(`✅ 模板已成功拉取到 ${dest}`);
52
+ console.log(`✅ 成功复制 ${config.label}:${name} 到 ${dest}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yzkit",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A CLI tool to scaffold modules and components",
5
5
  "type": "module",
6
6
  "bin": {