feng3d-cli 0.0.5 → 0.0.7
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 +65 -61
- package/bin/cli.js +2 -79
- package/dist/index.js +223 -512
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +225 -512
- package/dist/index.umd.cjs.map +1 -1
- package/lib/commands/create.d.ts.map +1 -1
- package/lib/commands/update.d.ts +2 -20
- package/lib/commands/update.d.ts.map +1 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/templates.d.ts +13 -7
- package/lib/templates.d.ts.map +1 -1
- package/lib/versions.d.ts +5 -19
- package/lib/versions.d.ts.map +1 -1
- package/package.json +5 -9
- package/templates/.github/workflows/pages.yml +11 -41
- package/templates/.github/workflows/pull-request.yml +3 -3
- package/templates/.github/workflows/upload-oss.yml +100 -0
- package/templates/.husky/pre-commit +32 -1
- package/templates/gitignore +0 -13
- package/templates/package.json +71 -0
- package/templates/scripts/postdocs.js +46 -0
- package/templates/src/index.ts +6 -0
- package/templates/vite.config.js +1 -0
- package/templates/vitest.config.ts +14 -0
- package/lib/commands/oss.d.ts +0 -11
- package/lib/commands/oss.d.ts.map +0 -1
- package/lib/types/config.d.ts +0 -113
- package/lib/types/config.d.ts.map +0 -1
- package/schemas/feng3d.schema.json +0 -196
- package/templates/feng3d.json +0 -43
package/README.md
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
feng3d
|
|
1
|
+
feng3d 命令行工具,包含项目规范、配置模板等功能。
|
|
2
2
|
|
|
3
3
|
## 功能特性
|
|
4
4
|
|
|
5
5
|
- 📋 统一的代码规范(ESLint 配置)
|
|
6
6
|
- 📦 统一的依赖版本管理
|
|
7
7
|
- 🛠️ CLI 工具支持创建和更新项目
|
|
8
|
-
- 📝
|
|
9
|
-
-
|
|
8
|
+
- 📝 项目模板(LICENSE, .gitignore, .cursorrules, tsconfig.json, vite.config.js 等)
|
|
9
|
+
- 🔄 GitHub Actions 工作流模板(CI/CD、GitHub Pages 部署、OSS 上传)
|
|
10
|
+
- ✅ Git pre-commit 钩子(代码规范检查 + 单元测试)
|
|
10
11
|
|
|
11
|
-
##
|
|
12
|
+
## 使用方式
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
npm install -g feng3d-cli
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
或作为开发依赖:
|
|
14
|
+
推荐使用 `npx` 直接运行,无需安装:
|
|
18
15
|
|
|
19
16
|
```bash
|
|
20
|
-
|
|
17
|
+
npx feng3d-cli <command>
|
|
21
18
|
```
|
|
22
19
|
|
|
23
|
-
## CLI
|
|
20
|
+
## CLI 命令
|
|
24
21
|
|
|
25
22
|
### 创建新项目
|
|
26
23
|
|
|
27
24
|
```bash
|
|
28
|
-
feng3d-cli create my-project
|
|
25
|
+
npx feng3d-cli create my-project
|
|
29
26
|
```
|
|
30
27
|
|
|
31
28
|
选项:
|
|
@@ -36,67 +33,70 @@ feng3d-cli create my-project
|
|
|
36
33
|
### 更新现有项目
|
|
37
34
|
|
|
38
35
|
```bash
|
|
39
|
-
feng3d-cli update
|
|
36
|
+
npx feng3d-cli update
|
|
37
|
+
npx feng3d-cli update -d ./my-project # 指定项目目录
|
|
40
38
|
```
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
- `-d, --directory <dir>` - 项目目录(默认:当前目录)
|
|
44
|
-
- `--eslint` - 仅更新 ESLint 配置
|
|
45
|
-
- `--gitignore` - 仅更新 .gitignore
|
|
46
|
-
- `--cursorrules` - 仅更新 .cursorrules
|
|
47
|
-
- `--deps` - 仅更新依赖版本
|
|
48
|
-
- `--all` - 更新所有配置
|
|
40
|
+
更新项目的所有规范配置文件,包括 ESLint、TypeScript、Vite、GitHub Actions 等。
|
|
49
41
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
feng3d-cli oss_upload_dir # 上传 ./public 目录
|
|
54
|
-
feng3d-cli oss_upload_dir -l ./dist # 指定本地目录
|
|
55
|
-
feng3d-cli oss_upload_dir -l ./public -o my-project # 指定 OSS 目录
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
选项:
|
|
59
|
-
- `-l, --local_dir <dir>` - 本地目录(默认:./public)
|
|
60
|
-
- `-o, --oss_dir <dir>` - OSS 目录(默认:从 package.json 的 name 获取)
|
|
61
|
-
|
|
62
|
-
> 注意:需要在 `C:/Users/Administrator/oss_config.json` 配置 OSS 访问密钥
|
|
42
|
+
> 注意:如果项目中存在 `examples` 目录,会自动添加 `examples:dev` 和 `postdocs` 脚本。
|
|
63
43
|
|
|
64
44
|
## 编程使用
|
|
65
45
|
|
|
66
|
-
### 获取统一版本
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { VERSIONS, getDevDependencies } from 'feng3d-cli';
|
|
70
|
-
|
|
71
|
-
// 获取特定依赖版本
|
|
72
|
-
console.log(VERSIONS.typescript); // '5.8.3'
|
|
73
|
-
console.log(VERSIONS.vitest); // '^3.1.3'
|
|
74
|
-
|
|
75
|
-
// 获取完整的 devDependencies
|
|
76
|
-
const deps = getDevDependencies({
|
|
77
|
-
includeVitest: true,
|
|
78
|
-
includeCoverage: true,
|
|
79
|
-
includeTypedoc: true,
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### 使用模板
|
|
84
|
-
|
|
85
46
|
```typescript
|
|
86
47
|
import {
|
|
48
|
+
// 版本管理
|
|
49
|
+
VERSIONS,
|
|
50
|
+
getDevDependencies,
|
|
51
|
+
// 模板
|
|
87
52
|
gitignoreTemplate,
|
|
88
53
|
cursorrrulesTemplate,
|
|
89
|
-
|
|
90
|
-
|
|
54
|
+
getTypedocConfig,
|
|
55
|
+
getLicenseTemplate,
|
|
56
|
+
getVscodeSettingsTemplate,
|
|
57
|
+
getTsconfigTemplate,
|
|
58
|
+
getViteConfigTemplate,
|
|
59
|
+
// 项目操作
|
|
60
|
+
createProject,
|
|
61
|
+
updateProject,
|
|
91
62
|
} from 'feng3d-cli';
|
|
92
|
-
|
|
93
|
-
// 创建 typedoc 配置
|
|
94
|
-
const config = createTypedocConfig({
|
|
95
|
-
name: '@feng3d/my-package',
|
|
96
|
-
repoName: 'my-package',
|
|
97
|
-
});
|
|
98
63
|
```
|
|
99
64
|
|
|
65
|
+
## 模板文件
|
|
66
|
+
|
|
67
|
+
| 文件 | 说明 |
|
|
68
|
+
|------|------|
|
|
69
|
+
| LICENSE | MIT 许可证(中文) |
|
|
70
|
+
| .gitignore | Git 忽略规则 |
|
|
71
|
+
| .cursorrules | Cursor AI 规则 |
|
|
72
|
+
| tsconfig.json | TypeScript 配置 |
|
|
73
|
+
| vite.config.js | Vite 构建配置 |
|
|
74
|
+
| eslint.config.js | ESLint 配置 |
|
|
75
|
+
| typedoc.json | TypeDoc 配置 |
|
|
76
|
+
| .vscode/settings.json | VS Code 设置 |
|
|
77
|
+
| .husky/pre-commit | Git pre-commit 钩子(代码规范 + 单元测试) |
|
|
78
|
+
| scripts/prepublish.js | 发布前脚本 |
|
|
79
|
+
| scripts/postpublish.js | 发布后脚本 |
|
|
80
|
+
| scripts/postdocs.js | 文档生成后处理脚本(移动到 public/doc) |
|
|
81
|
+
|
|
82
|
+
## GitHub Actions 工作流
|
|
83
|
+
|
|
84
|
+
| 工作流文件 | 说明 |
|
|
85
|
+
|------|------|
|
|
86
|
+
| pull-request.yml | 代码检查和测试(PR 或推送时触发) |
|
|
87
|
+
| publish.yml | 发布到 npm(创建 Release 时触发) |
|
|
88
|
+
| pages.yml | 部署文档到 GitHub Pages(发布成功后或手动触发) |
|
|
89
|
+
| upload-oss.yml | 上传到阿里云 OSS(发布成功后或手动触发) |
|
|
90
|
+
|
|
91
|
+
### OSS 上传配置
|
|
92
|
+
|
|
93
|
+
要启用 OSS 上传功能,需要在 GitHub 仓库的 Settings > Secrets and variables > Actions 中配置以下密钥:
|
|
94
|
+
|
|
95
|
+
- `OSS_REGION` - OSS 区域(如 `oss-cn-hangzhou`)
|
|
96
|
+
- `OSS_ACCESS_KEY_ID` - 阿里云 AccessKey ID
|
|
97
|
+
- `OSS_ACCESS_KEY_SECRET` - 阿里云 AccessKey Secret
|
|
98
|
+
- `OSS_BUCKET` - OSS Bucket 名称
|
|
99
|
+
|
|
100
100
|
## 统一版本
|
|
101
101
|
|
|
102
102
|
| 依赖 | 版本 |
|
|
@@ -125,7 +125,11 @@ const config = createTypedocConfig({
|
|
|
125
125
|
- 遵循 Conventional Commits 格式
|
|
126
126
|
- 类型:feat, fix, refactor, perf, style, docs, test, chore, build, ci
|
|
127
127
|
|
|
128
|
+
### Pre-commit 检查
|
|
129
|
+
提交代码前会自动执行:
|
|
130
|
+
1. **代码规范检查** - 使用 ESLint 检查代码风格
|
|
131
|
+
2. **单元测试** - 运行 vitest 确保测试通过
|
|
132
|
+
|
|
128
133
|
## 许可证
|
|
129
134
|
|
|
130
135
|
MIT
|
|
131
|
-
|
package/bin/cli.js
CHANGED
|
@@ -4,10 +4,9 @@
|
|
|
4
4
|
* feng3d 命令行工具,包含项目规范、OSS 上传等功能
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import fs from 'fs';
|
|
8
7
|
import { Command } from 'commander';
|
|
9
8
|
import chalk from 'chalk';
|
|
10
|
-
import { createProject, updateProject
|
|
9
|
+
import { createProject, updateProject } from '../dist/index.js';
|
|
11
10
|
|
|
12
11
|
const program = new Command();
|
|
13
12
|
|
|
@@ -41,28 +40,12 @@ program
|
|
|
41
40
|
.command('update')
|
|
42
41
|
.description('更新当前项目的规范配置')
|
|
43
42
|
.option('-d, --directory <dir>', '项目目录', '.')
|
|
44
|
-
.option('--config', '仅更新 feng3d.json 配置')
|
|
45
|
-
.option('--eslint', '仅更新 ESLint 配置')
|
|
46
|
-
.option('--gitignore', '仅更新 .gitignore')
|
|
47
|
-
.option('--cursorrules', '仅更新 .cursorrules')
|
|
48
|
-
.option('--publish', '仅更新 npm publish workflow')
|
|
49
|
-
.option('--pages', '仅更新 GitHub Pages workflow')
|
|
50
|
-
.option('--pull-request', '仅更新 Pull Request CI workflow')
|
|
51
|
-
.option('--typedoc', '仅更新 typedoc.json')
|
|
52
|
-
.option('--test', '仅更新 test/_.test.ts')
|
|
53
|
-
.option('--deps', '仅更新依赖版本')
|
|
54
|
-
.option('--husky', '仅更新 husky pre-commit hook')
|
|
55
|
-
.option('--license', '仅更新 LICENSE 文件')
|
|
56
|
-
.option('--vscode', '仅更新 .vscode/settings.json')
|
|
57
|
-
.option('--tsconfig', '仅更新 tsconfig.json')
|
|
58
|
-
.option('--vite', '仅更新 vite.config.js')
|
|
59
|
-
.option('--all', '更新所有配置')
|
|
60
43
|
.action(async (options) =>
|
|
61
44
|
{
|
|
62
45
|
console.log(chalk.blue('\n🔄 更新项目规范配置\n'));
|
|
63
46
|
try
|
|
64
47
|
{
|
|
65
|
-
await updateProject(options);
|
|
48
|
+
await updateProject(options.directory);
|
|
66
49
|
console.log(chalk.green('\n✅ 规范配置更新成功!\n'));
|
|
67
50
|
}
|
|
68
51
|
catch (error)
|
|
@@ -72,64 +55,4 @@ program
|
|
|
72
55
|
}
|
|
73
56
|
});
|
|
74
57
|
|
|
75
|
-
program
|
|
76
|
-
.command('check')
|
|
77
|
-
.description('检查当前项目是否符合 feng3d 规范')
|
|
78
|
-
.option('-d, --directory <dir>', '项目目录', '.')
|
|
79
|
-
.action(async () =>
|
|
80
|
-
{
|
|
81
|
-
console.log(chalk.blue('\n🔍 检查项目规范\n'));
|
|
82
|
-
// TODO: 实现规范检查
|
|
83
|
-
console.log(chalk.yellow('暂未实现'));
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
program
|
|
87
|
-
.command('oss_upload_dir')
|
|
88
|
-
.description('上传文件夹到阿里云 OSS')
|
|
89
|
-
.option('-l, --local_dir <string>', '本地目录', './public')
|
|
90
|
-
.option('-o, --oss_dir <string>', 'OSS 目录', '')
|
|
91
|
-
.action(async (options) =>
|
|
92
|
-
{
|
|
93
|
-
const localDir = options.local_dir;
|
|
94
|
-
let ossDir = options.oss_dir;
|
|
95
|
-
|
|
96
|
-
if (!fs.existsSync(localDir))
|
|
97
|
-
{
|
|
98
|
-
console.log(chalk.red(`\n❌ 本地目录 ${localDir} 不存在!\n`));
|
|
99
|
-
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!ossDir)
|
|
104
|
-
{
|
|
105
|
-
// 获取当前目录下 package.json 的 name 字段
|
|
106
|
-
try
|
|
107
|
-
{
|
|
108
|
-
const packageJson = fs.readFileSync('package.json', 'utf-8');
|
|
109
|
-
const packageJsonObj = JSON.parse(packageJson);
|
|
110
|
-
|
|
111
|
-
ossDir = packageJsonObj.name.split('/').pop();
|
|
112
|
-
}
|
|
113
|
-
catch
|
|
114
|
-
{
|
|
115
|
-
console.log(chalk.red('\n❌ 无法读取 package.json 获取项目名称\n'));
|
|
116
|
-
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
console.log(chalk.blue(`\n📤 上传文件夹到阿里云 OSS: ${localDir} -> ${ossDir}\n`));
|
|
122
|
-
|
|
123
|
-
try
|
|
124
|
-
{
|
|
125
|
-
await ossUploadDir(localDir, ossDir);
|
|
126
|
-
console.log(chalk.green('\n✅ 上传完成!\n'));
|
|
127
|
-
}
|
|
128
|
-
catch (error)
|
|
129
|
-
{
|
|
130
|
-
console.error(chalk.red(`\n❌ 上传失败: ${error}\n`));
|
|
131
|
-
process.exit(1);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
|
|
135
58
|
program.parse();
|