standards-cli 1.0.2 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "standards-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "一键初始化前端项目提交规范链路(cz-git + commitlint + husky + lint-staged)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,5 +1,8 @@
1
1
  import readline from "node:readline/promises";
2
2
  import { stdin as input, stdout as output } from "process";
3
+ import { readFileSync } from "fs";
4
+ import { fileURLToPath } from "url";
5
+ import { dirname, join } from "path";
3
6
  import {
4
7
  exists,
5
8
  readJson,
@@ -18,6 +21,9 @@ import {
18
21
  } from "../lib/pm.js";
19
22
  import { execLive } from "../lib/exec.js";
20
23
 
24
+ const __filename = fileURLToPath(import.meta.url);
25
+ const __dirname = dirname(__filename);
26
+
21
27
  const rl = readline.createInterface({ input, output });
22
28
 
23
29
  /**
@@ -113,10 +119,24 @@ function hasLintTools(pkg) {
113
119
  async function generateConfigFiles(pkg) {
114
120
  console.log("\n📝 生成配置文件...");
115
121
 
122
+ // 读取模板文件
123
+ const commitlintConfig = readFileSync(
124
+ join(__dirname, "../../templates/commitlint/config.cjs"),
125
+ "utf-8"
126
+ );
127
+ const lintstagedConfigFull = readFileSync(
128
+ join(__dirname, "../../templates/lint-staged/config.cjs"),
129
+ "utf-8"
130
+ );
131
+ const lintstagedConfigSimple = readFileSync(
132
+ join(__dirname, "../../templates/lint-staged/config-simple.cjs"),
133
+ "utf-8"
134
+ );
135
+
116
136
  // commitlint.config.cjs
117
137
  const commitlintCreated = await writeFileIfMissing(
118
138
  "commitlint.config.cjs",
119
- `module.exports = require('standards-cli/templates/commitlint/config.cjs');\n`
139
+ commitlintConfig
120
140
  );
121
141
  if (commitlintCreated) {
122
142
  console.log(" ✔ commitlint.config.cjs");
@@ -124,25 +144,14 @@ async function generateConfigFiles(pkg) {
124
144
  console.log(" ⚠ commitlint.config.cjs (已存在,跳过)");
125
145
  }
126
146
 
127
- // cz.config.cjs
128
- const czConfigCreated = await writeFileIfMissing(
129
- "cz.config.cjs",
130
- `module.exports = require('standards-cli/templates/commitlint/cz.config.cjs');\n`
131
- );
132
- if (czConfigCreated) {
133
- console.log(" ✔ cz.config.cjs");
134
- } else {
135
- console.log(" ⚠ cz.config.cjs (已存在,跳过)");
136
- }
137
-
138
147
  // .lintstagedrc.cjs - 根据是否有 eslint/prettier 选择模板
139
148
  const hasLintToolsInstalled = hasLintTools(pkg);
140
- const lintstagedTemplate = hasLintToolsInstalled
141
- ? "require('standards-cli/templates/lint-staged/config.cjs')"
142
- : "require('standards-cli/templates/lint-staged/config-simple.cjs')";
149
+ const lintstagedContent = hasLintToolsInstalled
150
+ ? lintstagedConfigFull
151
+ : lintstagedConfigSimple;
143
152
  const lintstagedrcCreated = await writeFileIfMissing(
144
153
  ".lintstagedrc.cjs",
145
- `module.exports = ${lintstagedTemplate};\n`
154
+ lintstagedContent
146
155
  );
147
156
  if (lintstagedrcCreated) {
148
157
  console.log(" ✔ .lintstagedrc.cjs");
@@ -154,18 +163,14 @@ async function generateConfigFiles(pkg) {
154
163
  await ensureDir(".husky");
155
164
 
156
165
  // .husky/pre-commit
157
- const preCommitContent = `#!/bin/sh
158
- . "$(dirname "$0")/_/husky.sh"
159
- npx --no-install lint-staged
166
+ const preCommitContent = `npx --no-install lint-staged
160
167
  `;
161
168
  await writeFile(".husky/pre-commit", preCommitContent);
162
169
  await chmodSafe(".husky/pre-commit");
163
170
  console.log(" ✔ .husky/pre-commit");
164
171
 
165
172
  // .husky/commit-msg
166
- const commitMsgContent = `#!/bin/sh
167
- . "$(dirname "$0")/_/husky.sh"
168
- npx --no-install commitlint --edit "$1"
173
+ const commitMsgContent = `npx --no-install commitlint --edit "$1"
169
174
  `;
170
175
  await writeFile(".husky/commit-msg", commitMsgContent);
171
176
  await chmodSafe(".husky/commit-msg");
@@ -369,8 +374,8 @@ export async function init(args) {
369
374
  await runHuskyInstall(pm);
370
375
 
371
376
  // 7. 打印成功信息
372
- const hasLintTools = hasLintTools(pkg);
373
- printSuccess(pm, hasLintTools);
377
+ const hasLintToolsInstalled = hasLintTools(pkg);
378
+ printSuccess(pm, hasLintToolsInstalled);
374
379
  } else {
375
380
  printInstallCommand(missingDeps, "pnpm");
376
381
  }
@@ -391,8 +396,8 @@ export async function init(args) {
391
396
  }
392
397
 
393
398
  // 打印成功信息
394
- const hasLintTools = hasLintTools(pkg);
395
- printSuccess(pm, hasLintTools);
399
+ const hasLintToolsInstalled = hasLintTools(pkg);
400
+ printSuccess(pm, hasLintToolsInstalled);
396
401
  }
397
402
 
398
403
  rl.close();
package/src/lib/pm.js CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  import { exists } from "./fs.js";
3
2
 
4
3
  /**
@@ -60,7 +59,7 @@ export function getExecCommand(pm, command) {
60
59
  case "bun":
61
60
  return `bunx ${command}`;
62
61
  case "yarn":
63
- return `yarn ${command}`;
62
+ return `yarn exec ${command}`;
64
63
  case "npm":
65
64
  return `npx ${command}`;
66
65
  default:
@@ -1,25 +1,37 @@
1
-
2
1
  module.exports = {
3
2
  extends: ["@commitlint/config-conventional"],
4
3
  rules: {
5
- "type-enum": [
6
- 2,
7
- "always",
8
- [
9
- "feat", // 新功能
10
- "fix", // 修复 bug
11
- "docs", // 文档更新
12
- "style", // 代码格式调整(不影响功能)
13
- "refactor", // 重构
14
- "perf", // 性能优化
15
- "test", // 测试相关
16
- "build", // 构建系统或外部依赖变动
17
- "ci", // CI 配置变动
18
- "chore", // 其他杂项
19
- "revert", // 回滚提交
20
- ],
21
- ],
4
+ "scope-enum": [0],
5
+ "type-enum": [2, "always", ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"]],
6
+ "scope-empty": [2, "never"],
22
7
  "subject-empty": [2, "never"],
23
8
  "subject-max-length": [2, "always", 72],
24
9
  },
10
+ prompt: {
11
+ messages: {
12
+ type: "选择你要提交的类型:",
13
+ scope: "填写 scope (必填,如: auth, login, user):",
14
+ subject: "填写简短描述 (必填,最多 72 字符):",
15
+ confirmCommit: "确认提交?",
16
+ },
17
+ types: [
18
+ { value: "feat", name: "feat: 新功能" },
19
+ { value: "fix", name: "fix: 修复 bug" },
20
+ { value: "docs", name: "docs: 文档更新" },
21
+ { value: "style", name: "style: 代码格式调整" },
22
+ { value: "refactor", name: "refactor: 重构" },
23
+ { value: "perf", name: "perf: 性能优化" },
24
+ { value: "test", name: "test: 测试相关" },
25
+ { value: "build", name: "build: 构建系统或外部依赖变动" },
26
+ { value: "ci", name: "ci: CI 配置变动" },
27
+ { value: "chore", name: "chore: 其他杂项" },
28
+ { value: "revert", name: "revert: 回滚提交" },
29
+ ],
30
+ useEmoji: false,
31
+ scopes: [],
32
+ enableMultipleScopes: false,
33
+ scopeEnumSeparator: ",",
34
+ allowCustomScopes: true,
35
+ allowEmptyScopes: false,
36
+ },
25
37
  };
@@ -1,12 +1,4 @@
1
1
  #!/bin/sh
2
- ###
3
- # @Author: ChenYu ycyplus@gmail.com
4
- # @Date: 2026-01-11 22:50:56
5
- # @LastEditors: ChenYu ycyplus@gmail.com
6
- # @LastEditTime: 2026-01-11 22:50:58
7
- # @FilePath: \frontend-standards\templates\husky\commit-msg.sh
8
- # @Description:
9
- # Copyright (c) 2026 by CHENY, All Rights Reserved 😎.
10
- ###
2
+
11
3
  . "$(dirname "$0")/_/husky.sh"
12
4
  npx --no-install commitlint --edit "$1"
@@ -1,12 +1,3 @@
1
1
  #!/bin/sh
2
- ###
3
- # @Author: ChenYu ycyplus@gmail.com
4
- # @Date: 2026-01-11 22:50:49
5
- # @LastEditors: ChenYu ycyplus@gmail.com
6
- # @LastEditTime: 2026-01-11 22:50:52
7
- # @FilePath: \frontend-standards\templates\husky\pre-commit.sh
8
- # @Description:
9
- # Copyright (c) 2026 by CHENY, All Rights Reserved 😎.
10
- ###
11
2
  . "$(dirname "$0")/_/husky.sh"
12
3
  npx --no-install lint-staged
@@ -1,12 +1,5 @@
1
- /*
2
- * @Author: ChenYu ycyplus@gmail.com
3
- * @Date: 2026-01-11 22:50:42
4
- * @LastEditors: ChenYu ycyplus@gmail.com
5
- * @LastEditTime: 2026-01-11 22:50:45
6
- * @FilePath: \frontend-standards\templates\lint-staged\config.cjs
7
- * @Description:
8
- * Copyright (c) 2026 by CHENY, All Rights Reserved 😎.
9
- */
1
+
2
+
10
3
  module.exports = {
11
4
  "*.{js,jsx,ts,tsx,vue}": ["eslint --fix"],
12
5
  "*.{js,jsx,ts,tsx,vue,css,scss,less,md,json,yml,yaml}": ["prettier --write"],
@@ -1,45 +0,0 @@
1
- module.exports = {
2
- types: [
3
- { value: "feat", name: "feat: 新功能 (feature)" },
4
- { value: "fix", name: "fix: 修复 bug (fix)" },
5
- { value: "docs", name: "docs: 文档更新 (documentation)" },
6
- { value: "style", name: "style: 代码格式调整(不影响功能)(style)" },
7
- { value: "refactor", name: "refactor: 重构 (refactor)" },
8
- { value: "perf", name: "perf: 性能优化 (performance)" },
9
- { value: "test", name: "test: 测试相关 (test)" },
10
- { value: "build", name: "build: 构建系统或外部依赖变动 (build)" },
11
- { value: "ci", name: "ci: CI 配置变动 (ci)" },
12
- { value: "chore", name: "chore: 其他杂项 (chore)" },
13
- { value: "revert", name: "revert: 回滚提交 (revert)" },
14
- ],
15
-
16
- // 交互提示信息
17
- messages: {
18
- type: "选择你要提交的类型:",
19
- scope: "填写 scope (对应代码模块):",
20
- customScope: "请输入自定义 scope:",
21
- subject: "填写简短描述 (必填):",
22
- confirmCommit: "确认提交?",
23
- },
24
-
25
- // 是否允许自定义 scope
26
- allowCustomScopes: true,
27
-
28
- // 是否允许空 scope(false 表示必须填写)
29
- allowEmptyScopes: false,
30
-
31
- // scope 是否从枚举列表选择(false 表示手动输入)
32
- scopeEnum: false,
33
-
34
- // 是否允许自定义 type
35
- allowCustomTypes: false,
36
-
37
- // 是否允许空 subject
38
- allowEmptySubject: false,
39
-
40
- // subject 最大长度
41
- subjectMaxLength: 72,
42
-
43
- // 是否允许 breaking 变更
44
- allowBreakingChanges: ["feat", "fix"],
45
- };