commit-pack 1.2.5 → 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 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 (!packageJson.scripts) {
281
- packageJson.scripts = {}
283
+ if (!updatedPackageJson.scripts) {
284
+ updatedPackageJson.scripts = {}
282
285
  console.log('🔥 创建或更新脚本...')
283
286
  }
284
287
 
285
288
  let modified = false
286
289
 
287
- if (!packageJson.scripts.lint) {
290
+ if (!updatedPackageJson.scripts.lint) {
288
291
  if (workspaceName) {
289
292
  // 为workspace项目使用工作空间命令
290
293
  if (packageManager === 'pnpm') {
291
- packageJson.scripts.lint = `pnpm -F ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`
294
+ updatedPackageJson.scripts.lint = `pnpm -F ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`
292
295
  } else if (packageManager === 'yarn') {
293
- packageJson.scripts.lint = `yarn workspace ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`
296
+ updatedPackageJson.scripts.lint = `yarn workspace ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`
294
297
  } else {
295
- packageJson.scripts.lint = 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0'
298
+ updatedPackageJson.scripts.lint =
299
+ 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0'
296
300
  }
297
301
  } else {
298
- packageJson.scripts.lint = 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0'
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 (!packageJson.scripts.format) {
311
+ if (!updatedPackageJson.scripts.format) {
307
312
  if (workspaceName) {
308
313
  // 为workspace项目使用工作空间命令
309
314
  if (packageManager === 'pnpm') {
310
- packageJson.scripts.format = `pnpm -F ${workspaceName} exec prettier --config .prettierrc '.' --write`
315
+ updatedPackageJson.scripts.format = `pnpm -F ${workspaceName} exec prettier --config .prettierrc '.' --write`
311
316
  } else if (packageManager === 'yarn') {
312
- packageJson.scripts.format = `yarn workspace ${workspaceName} exec prettier --config .prettierrc '.' --write`
317
+ updatedPackageJson.scripts.format = `yarn workspace ${workspaceName} exec prettier --config .prettierrc '.' --write`
313
318
  } else {
314
- packageJson.scripts.format = "prettier --config .prettierrc '.' --write"
319
+ updatedPackageJson.scripts.format = "prettier --config .prettierrc '.' --write"
315
320
  }
316
321
  } else {
317
- packageJson.scripts.format = "prettier --config .prettierrc '.' --write"
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
- packageJson.scripts.commit = `pnpm -F ${workspaceName} exec cz`
334
+ updatedPackageJson.scripts.commit = `pnpm -F ${workspaceName} exec cz`
330
335
  } else if (packageManager === 'yarn') {
331
- packageJson.scripts.commit = `yarn workspace ${workspaceName} exec cz`
336
+ updatedPackageJson.scripts.commit = `yarn workspace ${workspaceName} exec cz`
332
337
  } else {
333
- packageJson.scripts.commit = 'cz'
338
+ updatedPackageJson.scripts.commit = 'cz'
334
339
  }
335
340
  } else {
336
- packageJson.scripts.commit = 'cz'
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 (!packageJson.config) {
343
- packageJson.config = {}
347
+ if (!updatedPackageJson.config) {
348
+ updatedPackageJson.config = {}
344
349
  }
345
350
 
346
- packageJson.config.commitizen = {
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(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8')
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 (!packageJson.scripts) {
242
- packageJson.scripts = {};
244
+ if (!updatedPackageJson.scripts) {
245
+ updatedPackageJson.scripts = {};
243
246
  console.log('🔥 创建或更新脚本...');
244
247
  }
245
248
  let modified = false;
246
- if (!packageJson.scripts.lint) {
249
+ if (!updatedPackageJson.scripts.lint) {
247
250
  if (workspaceName) {
248
251
  // 为workspace项目使用工作空间命令
249
252
  if (packageManager === 'pnpm') {
250
- packageJson.scripts.lint = `pnpm -F ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`;
253
+ updatedPackageJson.scripts.lint = `pnpm -F ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`;
251
254
  } else if (packageManager === 'yarn') {
252
- packageJson.scripts.lint = `yarn workspace ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`;
255
+ updatedPackageJson.scripts.lint = `yarn workspace ${workspaceName} exec eslint ./ --ext .ts,.tsx,.json --max-warnings=0`;
253
256
  } else {
254
- packageJson.scripts.lint = 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0';
257
+ updatedPackageJson.scripts.lint = 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0';
255
258
  }
256
259
  } else {
257
- packageJson.scripts.lint = 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0';
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 (!packageJson.scripts.format) {
267
+ if (!updatedPackageJson.scripts.format) {
265
268
  if (workspaceName) {
266
269
  // 为workspace项目使用工作空间命令
267
270
  if (packageManager === 'pnpm') {
268
- packageJson.scripts.format = `pnpm -F ${workspaceName} exec prettier --config .prettierrc '.' --write`;
271
+ updatedPackageJson.scripts.format = `pnpm -F ${workspaceName} exec prettier --config .prettierrc '.' --write`;
269
272
  } else if (packageManager === 'yarn') {
270
- packageJson.scripts.format = `yarn workspace ${workspaceName} exec prettier --config .prettierrc '.' --write`;
273
+ updatedPackageJson.scripts.format = `yarn workspace ${workspaceName} exec prettier --config .prettierrc '.' --write`;
271
274
  } else {
272
- packageJson.scripts.format = "prettier --config .prettierrc '.' --write";
275
+ updatedPackageJson.scripts.format = "prettier --config .prettierrc '.' --write";
273
276
  }
274
277
  } else {
275
- packageJson.scripts.format = "prettier --config .prettierrc '.' --write";
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
- packageJson.scripts.commit = `pnpm -F ${workspaceName} exec cz`;
290
+ updatedPackageJson.scripts.commit = `pnpm -F ${workspaceName} exec cz`;
288
291
  } else if (packageManager === 'yarn') {
289
- packageJson.scripts.commit = `yarn workspace ${workspaceName} exec cz`;
292
+ updatedPackageJson.scripts.commit = `yarn workspace ${workspaceName} exec cz`;
290
293
  } else {
291
- packageJson.scripts.commit = 'cz';
294
+ updatedPackageJson.scripts.commit = 'cz';
292
295
  }
293
296
  } else {
294
- packageJson.scripts.commit = 'cz';
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 (!packageJson.config) {
301
- packageJson.config = {};
303
+ if (!updatedPackageJson.config) {
304
+ updatedPackageJson.config = {};
302
305
  }
303
- packageJson.config.commitizen = {
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(packageJson, null, 2), 'utf8');
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,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-pack",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "A setup package to automatly check project's style and commit configuration",
5
5
  "repository": {
6
6
  "type": "git",
@@ -72,6 +72,7 @@
72
72
  "inquirer": "^12.0.0",
73
73
  "lint-staged": "^15.2.10",
74
74
  "prettier": "^3.3.3",
75
+ "prettier-plugin-tailwindcss": "^0.7.2",
75
76
  "shelljs": "^0.8.5",
76
77
  "standard-version": "^9.5.0"
77
78
  },