yzkit 1.0.1 → 1.0.3

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 (3) hide show
  1. package/README.md +5 -7
  2. package/bin/index.js +28 -77
  3. package/package.json +3 -4
package/README.md CHANGED
@@ -1,12 +1,10 @@
1
- # 🛠️ yzkit
1
+ # yzkit
2
2
 
3
- A CLI tool to scaffold **UI components** and **modules** for your project, inspired by `shadcn/ui`.
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,39 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { copySync } = require("fs-extra");
6
- const inquirer = require("inquirer");
7
- const degit = require("degit");
3
+ import { existsSync } from "fs";
4
+ import { fileURLToPath } from "url";
5
+ import { dirname, resolve } from "path";
6
+ import { execSync } from "child_process";
8
7
 
9
- const LOCAL_TEMPLATE_ROOT = path.resolve(__dirname, "../templates");
10
- const CACHE_DIR = path.resolve(__dirname, "../.cache/templates");
11
- const GITHUB_REPO = "youzi20/yz-cli/templates"; // 改成你的仓库地址
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
12
10
 
13
- const TYPE_MAP = {
14
- ui: {
15
- label: "基础 UI 组件",
16
- subdir: "ui",
17
- destDir: "src/components"
18
- },
19
- module: {
20
- label: "业务功能模块",
21
- subdir: "modules",
22
- destDir: "src/modules"
23
- }
24
- };
11
+ // 固定仓库地址
12
+ const GITHUB_REPO = "youzi20/yz-cli";
25
13
 
26
- async function ensureTemplatesFromGitHub(subdir) {
27
- const cachePath = path.join(CACHE_DIR, subdir);
28
- if (!fs.existsSync(cachePath)) {
29
- console.log(`🌐 正在从 GitHub 拉取模板 ${subdir} ...`);
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;
38
- }
39
-
40
- async function main() {
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];
54
-
55
- // 优先从 GitHub 获取远程模板
56
- const templateDir = await ensureTemplatesFromGitHub(config.subdir);
57
-
58
- const available = fs.readdirSync(templateDir).filter((f) =>
59
- fs.statSync(path.join(templateDir, f)).isDirectory()
60
- );
14
+ // 获取命令行参数
15
+ const [remotePath, localName] = process.argv.slice(2);
61
16
 
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
- ]);
17
+ if (!remotePath) {
18
+ console.error("❌ 缺少远程模板路径参数。例如:templates/ui/Button");
19
+ process.exit(1);
20
+ }
75
21
 
76
- const src = path.join(templateDir, selected);
77
- const dest = path.resolve(process.cwd(), config.destDir, selected);
22
+ const name = localName || remotePath.split("/").pop();
23
+ if (!name) {
24
+ console.error("❌ 无法识别目标文件夹名,请手动指定第二个参数");
25
+ process.exit(1);
26
+ }
78
27
 
79
- if (fs.existsSync(dest)) {
80
- console.error(`❌ 目标目录已存在: ${dest}`);
81
- process.exit(1);
82
- }
28
+ // 安装到当前项目的 src 目录
29
+ const dest = resolve(process.cwd(), "src", name);
83
30
 
84
- copySync(src, dest);
85
- console.log(`✅ 已成功添加 ${config.label}:${selected} 到 ${dest}`);
31
+ if (existsSync(dest)) {
32
+ console.error(`❌ 目标目录已存在: ${dest}`);
33
+ process.exit(1);
86
34
  }
87
35
 
88
- main();
36
+ console.log(`🚀 拉取模板: ${GITHUB_REPO}/${remotePath}`);
37
+ execSync(`npx degit ${GITHUB_REPO}/${remotePath} ${dest}`, { stdio: "inherit" });
38
+
39
+ console.log(`✅ 模板已成功拉取到 ${dest}`);
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "yzkit",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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
- "fs-extra": "^11.3.0",
16
- "inquirer": "^12。6.0",
17
- "degit": "^2.8.0"
16
+ "degit": "^2.8.4"
18
17
  }
19
18
  }