commit-pack 1.2.3 → 1.2.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/bin/index.mjs +29 -20
- package/lib/index.mjs +23 -20
- package/package.json +6 -1
package/bin/index.mjs
CHANGED
|
@@ -276,26 +276,31 @@ try {
|
|
|
276
276
|
execSync(`sh ${scriptPath}`, { stdio: 'inherit', cwd: actualProjectRoot })
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
+
// 重新读取 package.json,保留 installWithProgress 写入的依赖
|
|
280
|
+
const updatedPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
|
281
|
+
|
|
279
282
|
// 创建或更新脚本
|
|
280
|
-
if (!
|
|
281
|
-
|
|
283
|
+
if (!updatedPackageJson.scripts) {
|
|
284
|
+
updatedPackageJson.scripts = {}
|
|
282
285
|
console.log('🔥 创建或更新脚本...')
|
|
283
286
|
}
|
|
284
287
|
|
|
285
288
|
let modified = false
|
|
286
289
|
|
|
287
|
-
if (!
|
|
290
|
+
if (!updatedPackageJson.scripts.lint) {
|
|
288
291
|
if (workspaceName) {
|
|
289
292
|
// 为workspace项目使用工作空间命令
|
|
290
293
|
if (packageManager === 'pnpm') {
|
|
291
|
-
|
|
294
|
+
updatedPackageJson.scripts.lint = `pnpm -F ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`
|
|
292
295
|
} else if (packageManager === 'yarn') {
|
|
293
|
-
|
|
296
|
+
updatedPackageJson.scripts.lint = `yarn workspace ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`
|
|
294
297
|
} else {
|
|
295
|
-
|
|
298
|
+
updatedPackageJson.scripts.lint =
|
|
299
|
+
'eslint ./ --ext .ts,.tsx,.json --max-warnings=0'
|
|
296
300
|
}
|
|
297
301
|
} else {
|
|
298
|
-
|
|
302
|
+
updatedPackageJson.scripts.lint =
|
|
303
|
+
'eslint ./ --ext .ts,.tsx,.json --max-warnings=0'
|
|
299
304
|
}
|
|
300
305
|
console.log(log.success('✅ 已添加 "lint" 至 package.json'))
|
|
301
306
|
modified = true
|
|
@@ -303,18 +308,18 @@ try {
|
|
|
303
308
|
console.log(log.warn('⚠️ package.json 中已存在 "lint" 未作修改'))
|
|
304
309
|
}
|
|
305
310
|
|
|
306
|
-
if (!
|
|
311
|
+
if (!updatedPackageJson.scripts.format) {
|
|
307
312
|
if (workspaceName) {
|
|
308
313
|
// 为workspace项目使用工作空间命令
|
|
309
314
|
if (packageManager === 'pnpm') {
|
|
310
|
-
|
|
315
|
+
updatedPackageJson.scripts.format = `pnpm -F ${workspaceName} exec prettier --config .prettierrc '.' --write`
|
|
311
316
|
} else if (packageManager === 'yarn') {
|
|
312
|
-
|
|
317
|
+
updatedPackageJson.scripts.format = `yarn workspace ${workspaceName} exec prettier --config .prettierrc '.' --write`
|
|
313
318
|
} else {
|
|
314
|
-
|
|
319
|
+
updatedPackageJson.scripts.format = "prettier --config .prettierrc '.' --write"
|
|
315
320
|
}
|
|
316
321
|
} else {
|
|
317
|
-
|
|
322
|
+
updatedPackageJson.scripts.format = "prettier --config .prettierrc '.' --write"
|
|
318
323
|
}
|
|
319
324
|
console.log(log.success('✅ 已添加 "format" 至 package.json'))
|
|
320
325
|
modified = true
|
|
@@ -326,31 +331,35 @@ try {
|
|
|
326
331
|
if (workspaceName) {
|
|
327
332
|
// 为workspace项目使用工作空间命令
|
|
328
333
|
if (packageManager === 'pnpm') {
|
|
329
|
-
|
|
334
|
+
updatedPackageJson.scripts.commit = `pnpm -F ${workspaceName} exec cz`
|
|
330
335
|
} else if (packageManager === 'yarn') {
|
|
331
|
-
|
|
336
|
+
updatedPackageJson.scripts.commit = `yarn workspace ${workspaceName} exec cz`
|
|
332
337
|
} else {
|
|
333
|
-
|
|
338
|
+
updatedPackageJson.scripts.commit = 'cz'
|
|
334
339
|
}
|
|
335
340
|
} else {
|
|
336
|
-
|
|
341
|
+
updatedPackageJson.scripts.commit = 'cz'
|
|
337
342
|
}
|
|
338
343
|
console.log(log.success('✅ 已添加 "commit" 至 package.json'))
|
|
339
344
|
modified = true
|
|
340
345
|
|
|
341
346
|
// 添加或更新 "config.commitizen" 配置
|
|
342
|
-
if (!
|
|
343
|
-
|
|
347
|
+
if (!updatedPackageJson.config) {
|
|
348
|
+
updatedPackageJson.config = {}
|
|
344
349
|
}
|
|
345
350
|
|
|
346
|
-
|
|
351
|
+
updatedPackageJson.config.commitizen = {
|
|
347
352
|
path: 'node_modules/cz-customizable'
|
|
348
353
|
}
|
|
349
354
|
modified = true
|
|
350
355
|
|
|
351
356
|
// 写入修改后的 package.json
|
|
352
357
|
if (modified) {
|
|
353
|
-
fs.writeFileSync(
|
|
358
|
+
fs.writeFileSync(
|
|
359
|
+
packageJsonPath,
|
|
360
|
+
JSON.stringify(updatedPackageJson, null, 2),
|
|
361
|
+
'utf8'
|
|
362
|
+
)
|
|
354
363
|
console.log(chalk.green('✅ 已更新 package.json'))
|
|
355
364
|
console.log('')
|
|
356
365
|
console.log('')
|
package/lib/index.mjs
CHANGED
|
@@ -237,42 +237,45 @@ try {
|
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
+
// 重新读取 package.json,保留 installWithProgress 写入的依赖
|
|
241
|
+
const updatedPackageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf8'));
|
|
242
|
+
|
|
240
243
|
// 创建或更新脚本
|
|
241
|
-
if (!
|
|
242
|
-
|
|
244
|
+
if (!updatedPackageJson.scripts) {
|
|
245
|
+
updatedPackageJson.scripts = {};
|
|
243
246
|
console.log('🔥 创建或更新脚本...');
|
|
244
247
|
}
|
|
245
248
|
let modified = false;
|
|
246
|
-
if (!
|
|
249
|
+
if (!updatedPackageJson.scripts.lint) {
|
|
247
250
|
if (workspaceName) {
|
|
248
251
|
// 为workspace项目使用工作空间命令
|
|
249
252
|
if (packageManager === 'pnpm') {
|
|
250
|
-
|
|
253
|
+
updatedPackageJson.scripts.lint = `pnpm -F ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`;
|
|
251
254
|
} else if (packageManager === 'yarn') {
|
|
252
|
-
|
|
255
|
+
updatedPackageJson.scripts.lint = `yarn workspace ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`;
|
|
253
256
|
} else {
|
|
254
|
-
|
|
257
|
+
updatedPackageJson.scripts.lint = 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0';
|
|
255
258
|
}
|
|
256
259
|
} else {
|
|
257
|
-
|
|
260
|
+
updatedPackageJson.scripts.lint = 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0';
|
|
258
261
|
}
|
|
259
262
|
console.log(_chalkColor.log.success('✅ 已添加 "lint" 至 package.json'));
|
|
260
263
|
modified = true;
|
|
261
264
|
} else {
|
|
262
265
|
console.log(_chalkColor.log.warn('⚠️ package.json 中已存在 "lint" 未作修改'));
|
|
263
266
|
}
|
|
264
|
-
if (!
|
|
267
|
+
if (!updatedPackageJson.scripts.format) {
|
|
265
268
|
if (workspaceName) {
|
|
266
269
|
// 为workspace项目使用工作空间命令
|
|
267
270
|
if (packageManager === 'pnpm') {
|
|
268
|
-
|
|
271
|
+
updatedPackageJson.scripts.format = `pnpm -F ${workspaceName} exec prettier --config .prettierrc '.' --write`;
|
|
269
272
|
} else if (packageManager === 'yarn') {
|
|
270
|
-
|
|
273
|
+
updatedPackageJson.scripts.format = `yarn workspace ${workspaceName} exec prettier --config .prettierrc '.' --write`;
|
|
271
274
|
} else {
|
|
272
|
-
|
|
275
|
+
updatedPackageJson.scripts.format = "prettier --config .prettierrc '.' --write";
|
|
273
276
|
}
|
|
274
277
|
} else {
|
|
275
|
-
|
|
278
|
+
updatedPackageJson.scripts.format = "prettier --config .prettierrc '.' --write";
|
|
276
279
|
}
|
|
277
280
|
console.log(_chalkColor.log.success('✅ 已添加 "format" 至 package.json'));
|
|
278
281
|
modified = true;
|
|
@@ -284,30 +287,30 @@ try {
|
|
|
284
287
|
if (workspaceName) {
|
|
285
288
|
// 为workspace项目使用工作空间命令
|
|
286
289
|
if (packageManager === 'pnpm') {
|
|
287
|
-
|
|
290
|
+
updatedPackageJson.scripts.commit = `pnpm -F ${workspaceName} exec cz`;
|
|
288
291
|
} else if (packageManager === 'yarn') {
|
|
289
|
-
|
|
292
|
+
updatedPackageJson.scripts.commit = `yarn workspace ${workspaceName} exec cz`;
|
|
290
293
|
} else {
|
|
291
|
-
|
|
294
|
+
updatedPackageJson.scripts.commit = 'cz';
|
|
292
295
|
}
|
|
293
296
|
} else {
|
|
294
|
-
|
|
297
|
+
updatedPackageJson.scripts.commit = 'cz';
|
|
295
298
|
}
|
|
296
299
|
console.log(_chalkColor.log.success('✅ 已添加 "commit" 至 package.json'));
|
|
297
300
|
modified = true;
|
|
298
301
|
|
|
299
302
|
// 添加或更新 "config.commitizen" 配置
|
|
300
|
-
if (!
|
|
301
|
-
|
|
303
|
+
if (!updatedPackageJson.config) {
|
|
304
|
+
updatedPackageJson.config = {};
|
|
302
305
|
}
|
|
303
|
-
|
|
306
|
+
updatedPackageJson.config.commitizen = {
|
|
304
307
|
path: 'node_modules/cz-customizable'
|
|
305
308
|
};
|
|
306
309
|
modified = true;
|
|
307
310
|
|
|
308
311
|
// 写入修改后的 package.json
|
|
309
312
|
if (modified) {
|
|
310
|
-
_fs.default.writeFileSync(packageJsonPath, JSON.stringify(
|
|
313
|
+
_fs.default.writeFileSync(packageJsonPath, JSON.stringify(updatedPackageJson, null, 2), 'utf8');
|
|
311
314
|
console.log(_chalk.default.green('✅ 已更新 package.json'));
|
|
312
315
|
console.log('');
|
|
313
316
|
console.log('');
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commit-pack",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "A setup package to automatly check project's style and commit configuration",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/jett191/commit-pack.git"
|
|
8
|
+
},
|
|
5
9
|
"main": "lib/index.js",
|
|
6
10
|
"bin": {
|
|
7
11
|
"commit-pack-init": "bin/index.mjs"
|
|
@@ -68,6 +72,7 @@
|
|
|
68
72
|
"inquirer": "^12.0.0",
|
|
69
73
|
"lint-staged": "^15.2.10",
|
|
70
74
|
"prettier": "^3.3.3",
|
|
75
|
+
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
71
76
|
"shelljs": "^0.8.5",
|
|
72
77
|
"standard-version": "^9.5.0"
|
|
73
78
|
},
|