feng3d-cli 0.0.11 → 0.1.0

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.
@@ -0,0 +1,182 @@
1
+ # feng3d Skill
2
+
3
+ You are helping users create and manage feng3d projects using the feng3d-cli tool.
4
+
5
+ ## Overview
6
+
7
+ feng3d-cli is a command-line tool that provides:
8
+ - Unified code standards (ESLint configuration)
9
+ - Unified dependency version management
10
+ - Project templates (LICENSE, .gitignore, tsconfig.json, vite.config.js, etc.)
11
+ - GitHub Actions workflows (CI/CD, GitHub Pages deployment, OSS upload)
12
+ - Git pre-commit hooks (code linting + unit tests)
13
+
14
+ ## Commands
15
+
16
+ ### 1. Create New Project
17
+
18
+ **Command**: `npx feng3d-cli create <project-name> [options]`
19
+
20
+ **Description**: Creates a new project following feng3d standards.
21
+
22
+ **Options**:
23
+ - `-d, --directory <dir>` - Project directory (default: current directory)
24
+ - `--no-examples` - Do not create examples directory
25
+ - `--no-vitest` - Do not include vitest test configuration
26
+
27
+ **Examples**:
28
+ ```bash
29
+ # Create a new project in current directory
30
+ npx feng3d-cli create my-project
31
+
32
+ # Create project in specific directory
33
+ npx feng3d-cli create my-project -d ./packages
34
+
35
+ # Create without examples
36
+ npx feng3d-cli create my-project --no-examples
37
+
38
+ # Create without vitest
39
+ npx feng3d-cli create my-project --no-vitest
40
+ ```
41
+
42
+ **What it creates**:
43
+ - `package.json` with unified dependencies
44
+ - `LICENSE` (MIT in Chinese)
45
+ - `.gitignore`
46
+ - `.cursorrules`
47
+ - `tsconfig.json`
48
+ - `vite.config.js`
49
+ - `vitest.config.ts` (unless --no-vitest)
50
+ - `eslint.config.js`
51
+ - `typedoc.json`
52
+ - `.vscode/settings.json`
53
+ - `.husky/pre-commit` hook
54
+ - `scripts/prepublish.js`, `scripts/postpublish.js`, `scripts/postdocs.js`
55
+ - `.github/workflows/` (pull-request.yml, publish.yml, pages.yml, upload-oss.yml)
56
+ - `src/index.ts`
57
+ - `test/_.test.ts`
58
+ - `examples/` directory (unless --no-examples)
59
+
60
+ ### 2. Update Existing Project
61
+
62
+ **Command**: `npx feng3d-cli update [options]`
63
+
64
+ **Description**: Updates all standard configuration files in an existing project.
65
+
66
+ **Options**:
67
+ - `-d, --directory <dir>` - Project directory (default: current directory)
68
+
69
+ **Examples**:
70
+ ```bash
71
+ # Update current project
72
+ npx feng3d-cli update
73
+
74
+ # Update specific project
75
+ npx feng3d-cli update -d ./my-project
76
+ ```
77
+
78
+ **What it updates**:
79
+ - All configuration files (ESLint, TypeScript, Vite, etc.)
80
+ - GitHub Actions workflows
81
+ - Scripts
82
+ - Dependencies versions in package.json
83
+ - If `examples` directory exists, automatically adds `examples:dev` and `postdocs` scripts
84
+
85
+ ## Usage Guidelines
86
+
87
+ ### When to use CREATE command:
88
+ - User wants to start a new feng3d project
89
+ - User needs a project with feng3d standards
90
+ - Setting up a new package in a monorepo
91
+
92
+ ### When to use UPDATE command:
93
+ - User wants to sync with latest feng3d standards
94
+ - Project configuration is outdated
95
+ - User wants to adopt new feng3d conventions
96
+ - After feng3d-cli version update
97
+
98
+ ### Important Notes:
99
+ 1. **Always use npx**: Run commands with `npx feng3d-cli` to ensure the latest version
100
+ 2. **Check directory**: Verify the target directory before creating/updating
101
+ 3. **Backup warning**: Warn users that UPDATE will overwrite configuration files
102
+ 4. **Git status**: Recommend checking git status before UPDATE
103
+ 5. **Examples directory**: If project has `examples/`, UPDATE will automatically configure related scripts
104
+
105
+ ## Code Standards
106
+
107
+ When working with feng3d projects, follow these standards:
108
+
109
+ ### Indentation
110
+ - Use 4 spaces
111
+
112
+ ### Quotes
113
+ - Use single quotes
114
+
115
+ ### Naming Conventions
116
+ - Variables and functions: camelCase
117
+ - Classes and interfaces: PascalCase
118
+ - Constants: UPPER_SNAKE_CASE
119
+
120
+ ### Git Commit Conventions
121
+ - Use Simplified Chinese
122
+ - Follow Conventional Commits format
123
+ - Types: feat, fix, refactor, perf, style, docs, test, chore, build, ci
124
+
125
+ ### Pre-commit Checks
126
+ Before committing, the project automatically runs:
127
+ 1. ESLint code style check
128
+ 2. Unit tests via vitest
129
+
130
+ ## Unified Versions
131
+
132
+ The tool maintains unified versions for:
133
+ - TypeScript: 5.8.3
134
+ - ESLint: 9.26.0
135
+ - Vitest: ^3.1.3
136
+ - Vite: ^6.3.5
137
+ - TypeDoc: ^0.28.4
138
+
139
+ ## Implementation
140
+
141
+ When the user invokes this skill:
142
+
143
+ 1. **Understand the request**: Determine if they want to create or update
144
+ 2. **Confirm details**: Ask for project name (for create) or confirm directory
145
+ 3. **Execute command**: Use the Bash tool to run `npx feng3d-cli <command>`
146
+ 4. **Handle output**: Show the command output to the user
147
+ 5. **Next steps**: Suggest running `npm install` after creation, or checking git diff after update
148
+
149
+ ## Example Interactions
150
+
151
+ ### Example 1: Creating a new project
152
+ ```
153
+ User: Create a new feng3d project called "my-lib"
154
+ Assistant: I'll create a new feng3d project for you.
155
+ [Uses Bash tool to run: npx feng3d-cli create my-lib]
156
+ [Shows output]
157
+ Assistant: Project created successfully! Next steps:
158
+ 1. cd my-lib
159
+ 2. npm install
160
+ 3. npm run dev
161
+ ```
162
+
163
+ ### Example 2: Updating existing project
164
+ ```
165
+ User: Update my project to latest feng3d standards
166
+ Assistant: I'll update your project configuration. This will overwrite your configuration files. Make sure you've committed any important changes.
167
+ [Uses Bash tool to run: npx feng3d-cli update]
168
+ [Shows output]
169
+ Assistant: Configuration updated! Review the changes with `git diff` and test your project.
170
+ ```
171
+
172
+ ## Error Handling
173
+
174
+ - If the command fails, show the error message and suggest solutions
175
+ - If directory doesn't exist, suggest creating it or checking the path
176
+ - If package.json is missing for update, suggest running create instead
177
+ - If npm/node is not installed, guide user to install them first
178
+
179
+ ## Additional Resources
180
+
181
+ - Repository: https://github.com/feng3d-labs/feng3d-cli
182
+ - Documentation: https://feng3d.com/feng3d-cli/
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "feng3d",
3
+ "version": "0.1.0",
4
+ "description": "创建或更新符合 feng3d 规范的项目",
5
+ "author": "feng",
6
+ "commands": {
7
+ "create": {
8
+ "description": "创建新的 feng3d 项目",
9
+ "usage": "/feng3d create <project-name> [options]"
10
+ },
11
+ "update": {
12
+ "description": "更新当前项目的 feng3d 规范配置",
13
+ "usage": "/feng3d update [options]"
14
+ }
15
+ },
16
+ "repository": "https://github.com/feng3d-labs/feng3d-cli",
17
+ "cli": {
18
+ "command": "npx feng3d-cli",
19
+ "package": "feng3d-cli"
20
+ }
21
+ }
package/README.md CHANGED
@@ -11,12 +11,46 @@ feng3d 命令行工具,包含项目规范、配置模板等功能。
11
11
 
12
12
  ## 使用方式
13
13
 
14
+ ### CLI 命令行使用
15
+
14
16
  推荐使用 `npx` 直接运行,无需安装:
15
17
 
16
18
  ```bash
17
19
  npx feng3d-cli <command>
18
20
  ```
19
21
 
22
+ 或全局安装:
23
+
24
+ ```bash
25
+ npm install -g feng3d-cli
26
+ feng3d-cli <command>
27
+ ```
28
+
29
+ ### Claude Code Skill 使用
30
+
31
+ 如果你使用 [Claude Code](https://github.com/anthropics/claude-code),只需一条命令即可安装:
32
+
33
+ ```bash
34
+ npx feng3d-cli skill
35
+ ```
36
+
37
+ 手动安装:
38
+ ```bash
39
+ mkdir -p ~/.claude/skills
40
+ cp -r .claude-skill ~/.claude/skills/feng3d
41
+ ```
42
+
43
+ 安装后,在 Claude Code 中可以直接使用:
44
+
45
+ ```bash
46
+ /feng3d create my-project
47
+ /feng3d update
48
+ ```
49
+
50
+ 或者直接对话:"用 feng3d 创建一个新项目"
51
+
52
+ 详细说明见 [.claude-skill/README.md](./.claude-skill/README.md)
53
+
20
54
  ## CLI 命令
21
55
 
22
56
  ### 创建新项目
@@ -37,6 +71,14 @@ npx feng3d-cli update
37
71
  npx feng3d-cli update -d ./my-project # 指定项目目录
38
72
  ```
39
73
 
74
+ ### 安装 Claude Code Skill
75
+
76
+ ```bash
77
+ npx feng3d-cli skill
78
+ ```
79
+
80
+ > 💡 提示:也可以使用完整命令 `npx feng3d-cli install-skill`
81
+
40
82
  更新项目的所有规范配置文件,包括 ESLint、TypeScript、Vite、GitHub Actions 等。
41
83
 
42
84
  > 注意:如果项目中存在 `examples` 目录,会自动添加 `examples:dev` 和 `postdocs` 脚本。
package/bin/cli.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { Command } from 'commander';
8
8
  import chalk from 'chalk';
9
- import { createProject, updateProject } from '../dist/index.js';
9
+ import { createProject, updateProject, installSkill } from '../dist/index.js';
10
10
 
11
11
  const program = new Command();
12
12
 
@@ -55,4 +55,21 @@ program
55
55
  }
56
56
  });
57
57
 
58
+ program
59
+ .command('install-skill')
60
+ .alias('skill')
61
+ .description('安装 feng3d Claude Code Skill')
62
+ .action(async () =>
63
+ {
64
+ try
65
+ {
66
+ await installSkill();
67
+ }
68
+ catch (error)
69
+ {
70
+ console.error(chalk.red(`\n❌ 安装失败: ${error}\n`));
71
+ process.exit(1);
72
+ }
73
+ });
74
+
58
75
  program.parse();
package/dist/index.js CHANGED
@@ -2,8 +2,9 @@ import fs from "fs-extra";
2
2
  import path from "path";
3
3
  import { fileURLToPath } from "url";
4
4
  import chalk from "chalk";
5
- const __dirname$2 = path.dirname(fileURLToPath(import.meta.url));
6
- const TEMPLATES_DIR$1 = path.resolve(__dirname$2, "../templates");
5
+ import os from "os";
6
+ const __dirname$3 = path.dirname(fileURLToPath(import.meta.url));
7
+ const TEMPLATES_DIR$1 = path.resolve(__dirname$3, "../templates");
7
8
  function loadVersionsFromTemplate() {
8
9
  const packageJsonPath = path.join(TEMPLATES_DIR$1, "package.json");
9
10
  const packageJson = fs.readJsonSync(packageJsonPath);
@@ -23,8 +24,8 @@ function getDevDependencies(options = {}) {
23
24
  }
24
25
  return deps;
25
26
  }
26
- const __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
27
- const TEMPLATES_DIR = path.resolve(__dirname$1, "../templates");
27
+ const __dirname$2 = path.dirname(fileURLToPath(import.meta.url));
28
+ const TEMPLATES_DIR = path.resolve(__dirname$2, "../templates");
28
29
  function getGitignoreTemplate() {
29
30
  return fs.readFileSync(path.join(TEMPLATES_DIR, "gitignore"), "utf-8");
30
31
  }
@@ -202,7 +203,8 @@ const PACKAGE_JSON_FIELD_ORDER = [
202
203
  "devDependencies",
203
204
  "dependencies",
204
205
  "peerDependencies",
205
- "lint-staged"
206
+ "lint-staged",
207
+ "workspaces"
206
208
  ];
207
209
  const SCRIPTS_ORDER = [
208
210
  "examples:dev",
@@ -287,10 +289,10 @@ async function updateDependencies(projectDir) {
287
289
  standardScripts.postdocs = "node scripts/postdocs.js && cd examples && vite build --outDir ../public";
288
290
  }
289
291
  for (const [key, value] of Object.entries(standardScripts)) {
290
- if (packageJson.scripts[key] !== value) {
292
+ if (!(key in packageJson.scripts)) {
291
293
  packageJson.scripts[key] = value;
292
294
  updated = true;
293
- console.log(chalk.gray(` 更新: scripts.${key}`));
295
+ console.log(chalk.gray(` 添加: scripts.${key}`));
294
296
  }
295
297
  }
296
298
  if (packageJson.type !== "module") {
@@ -322,6 +324,17 @@ async function updateDependencies(projectDir) {
322
324
  updated = true;
323
325
  console.log(chalk.gray(" 更新: exports"));
324
326
  }
327
+ if (!packageJson.workspaces) {
328
+ packageJson.workspaces = [
329
+ ".",
330
+ "./examples",
331
+ "./test_web",
332
+ "packages/*",
333
+ "packages/*/examples"
334
+ ];
335
+ updated = true;
336
+ console.log(chalk.gray(" 添加: workspaces"));
337
+ }
325
338
  if (updated) {
326
339
  const orderedPackageJson = reorderPackageJson(packageJson);
327
340
  let newContent = JSON.stringify(orderedPackageJson, null, indent);
@@ -477,6 +490,71 @@ function createPackageJson(name, options) {
477
490
  })
478
491
  };
479
492
  }
493
+ const __filename$1 = fileURLToPath(import.meta.url);
494
+ const __dirname$1 = path.dirname(__filename$1);
495
+ async function installSkill() {
496
+ try {
497
+ const homeDir = os.homedir();
498
+ const claudeSkillsDir = path.join(homeDir, ".claude", "skills", "feng3d");
499
+ const possiblePaths = [
500
+ // 从当前文件位置向上查找(开发环境)
501
+ path.resolve(__dirname$1, "../../.claude-skill"),
502
+ path.resolve(__dirname$1, "../../../.claude-skill"),
503
+ path.resolve(__dirname$1, "../.claude-skill"),
504
+ // 从 package.json 所在目录查找
505
+ path.resolve(process.cwd(), ".claude-skill"),
506
+ // 从 node_modules 查找(全局安装)
507
+ path.resolve(__dirname$1, "../../../../feng3d-cli/.claude-skill")
508
+ ];
509
+ let sourceDir = "";
510
+ for (const tryPath of possiblePaths) {
511
+ if (fs.existsSync(path.join(tryPath, "skill.json"))) {
512
+ sourceDir = tryPath;
513
+ break;
514
+ }
515
+ }
516
+ if (!sourceDir) {
517
+ console.error(chalk.red("❌ 错误:找不到 .claude-skill 目录"));
518
+ console.log(chalk.yellow("尝试的路径:"));
519
+ possiblePaths.forEach((p) => console.log(` - ${p}`));
520
+ console.log(chalk.yellow("\n请确保 feng3d-cli 已正确安装"));
521
+ process.exit(1);
522
+ }
523
+ if (!fs.existsSync(path.join(sourceDir, "skill.json"))) {
524
+ console.error(chalk.red("❌ 错误:.claude-skill/skill.json 不存在"));
525
+ process.exit(1);
526
+ }
527
+ console.log(chalk.blue("\n📦 开始安装 feng3d Claude Code Skill...\n"));
528
+ if (fs.existsSync(claudeSkillsDir)) {
529
+ console.log(chalk.yellow("⚠️ 检测到已安装的 skill,将进行覆盖更新..."));
530
+ await fs.remove(claudeSkillsDir);
531
+ }
532
+ await fs.ensureDir(path.dirname(claudeSkillsDir));
533
+ console.log(chalk.blue("📂 复制 skill 文件..."));
534
+ await fs.copy(sourceDir, claudeSkillsDir, {
535
+ overwrite: true,
536
+ errorOnExist: false
537
+ });
538
+ if (fs.existsSync(path.join(claudeSkillsDir, "skill.json"))) {
539
+ console.log(chalk.green("\n✅ feng3d Skill 安装成功!\n"));
540
+ console.log(chalk.cyan(`安装位置: ${claudeSkillsDir}
541
+ `));
542
+ console.log(chalk.yellow("使用方法:"));
543
+ console.log(" /feng3d create my-project");
544
+ console.log(" /feng3d update\n");
545
+ console.log(chalk.yellow('或直接对话: "用 feng3d 创建一个新项目"\n'));
546
+ console.log(chalk.cyan("💡 提示: 可能需要重启 Claude Code 使 skill 生效\n"));
547
+ } else {
548
+ console.error(chalk.red("\n❌ 安装失败:无法验证安装结果\n"));
549
+ process.exit(1);
550
+ }
551
+ } catch (error) {
552
+ console.error(chalk.red(`
553
+ ❌ 安装失败: ${error}
554
+ `));
555
+ process.exit(1);
556
+ }
557
+ }
480
558
  export {
481
559
  VERSIONS,
482
560
  createProject,
@@ -502,6 +580,7 @@ export {
502
580
  getViteConfigTemplate,
503
581
  getVitestConfigTemplate,
504
582
  getVscodeSettingsTemplate,
583
+ installSkill,
505
584
  updateProject
506
585
  };
507
586
  //# sourceMappingURL=index.js.map