commit-pack 1.0.21 → 1.1.2

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,7 @@
1
+ import chalk from 'chalk'
2
+
3
+ export const log = {
4
+ success: chalk.hex('#CCFF99'),
5
+ error: chalk.hex('#FF6666'),
6
+ warn: chalk.hex('#FFFF66')
7
+ }
package/bin/index.mjs CHANGED
@@ -7,6 +7,8 @@ import chalk from 'chalk'
7
7
  import { execSync } from 'child_process'
8
8
  import path from 'path'
9
9
  import { fileURLToPath } from 'url'
10
+ import { log } from './chalkColor.js'
11
+ import { installWithProgress } from './installWithProgress.js'
10
12
 
11
13
  // 模拟 CommonJS 的 __dirname
12
14
  const __filename = fileURLToPath(import.meta.url)
@@ -30,7 +32,7 @@ function findProjectRootWithLockFile() {
30
32
  }
31
33
 
32
34
  const projectRoot = findProjectRootWithLockFile()
33
- console.log(chalk.green(`检测到项目根目录:${projectRoot}`))
35
+ console.log(`📁 根目录:${projectRoot}`)
34
36
 
35
37
  function detectPackageManager() {
36
38
  if (fs.existsSync(path.join(projectRoot, 'pnpm-lock.yaml'))) {
@@ -44,10 +46,8 @@ function detectPackageManager() {
44
46
  }
45
47
  }
46
48
 
47
- console.log('执行 postinstall 脚本:bin/index.js')
48
-
49
49
  const packageManager = detectPackageManager()
50
- console.log(chalk.green(`检测到使用的包管理器:${packageManager}`))
50
+ console.log(`🍀 包管理器:${packageManager}`)
51
51
 
52
52
  const packageJsonPath = path.join(projectRoot, 'package.json')
53
53
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
@@ -55,7 +55,6 @@ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
55
55
  // 检查是否已经初始化过
56
56
  const initFlagPath = path.join(projectRoot, '.commit-pack-init')
57
57
  if (fs.existsSync(initFlagPath)) {
58
- console.log(chalk.yellow('已检测到初始化标志文件,跳过初始化'))
59
58
  process.exit(0)
60
59
  }
61
60
 
@@ -81,7 +80,8 @@ const devDependencies = [
81
80
  '@commitlint/config-conventional',
82
81
  'commitlint-config-cz',
83
82
  'cz-customizable',
84
- 'cz-custom'
83
+ 'cz-custom',
84
+ 'prettier-plugin-tailwindcss'
85
85
  ]
86
86
 
87
87
  let dependenciesToInstall = []
@@ -99,31 +99,31 @@ for (const [dep, version] of Object.entries(devDependenciesWithVersion)) {
99
99
  }
100
100
  }
101
101
 
102
- // 安装缺失的依赖
103
- if (dependenciesToInstall.length > 0) {
104
- let installCommand = ''
105
-
106
- switch (packageManager) {
107
- case 'pnpm':
108
- installCommand = `pnpm add -D ${dependenciesToInstall.join(' ')}`
109
- break
110
- case 'yarn':
111
- installCommand = `yarn add ${dependenciesToInstall.join(' ')} --dev`
112
- break
113
- case 'bun':
114
- installCommand = `bun add -d ${dependenciesToInstall.join(' ')}`
115
- break
116
- default:
117
- installCommand = `npm install ${dependenciesToInstall.join(' ')} --save-dev`
118
- break
119
- }
120
-
121
- console.log(chalk.green(`正在安装开发依赖:${dependenciesToInstall.join(', ')}`))
122
- console.log(chalk.green(`执行命令:${installCommand}`))
123
- execSync(installCommand, { stdio: 'inherit', cwd: projectRoot })
124
- } else {
125
- console.log(chalk.yellow('所有开发依赖已安装,无需安装'))
126
- }
102
+ installWithProgress(dependenciesToInstall, packageManager, projectRoot)
103
+ // // 安装缺失的依赖
104
+ // if (dependenciesToInstall.length > 0) {
105
+ // let installCommand = ''
106
+
107
+ // switch (packageManager) {
108
+ // case 'pnpm':
109
+ // installCommand = `pnpm add -D ${dependenciesToInstall.join(' ')}`
110
+ // break
111
+ // case 'yarn':
112
+ // installCommand = `yarn add ${dependenciesToInstall.join(' ')} --dev`
113
+ // break
114
+ // case 'bun':
115
+ // installCommand = `bun add -d ${dependenciesToInstall.join(' ')}`
116
+ // break
117
+ // default:
118
+ // installCommand = `npm install ${dependenciesToInstall.join(' ')} --save-dev`
119
+ // break
120
+ // }
121
+
122
+ // console.log(chalk.green(`⬇️ 安装依赖:${dependenciesToInstall.join(', ')}`))
123
+ // execSync(installCommand, { stdio: 'inherit', cwd: projectRoot })
124
+ // } else {
125
+ // console.log(log.warn('已安装 跳过...'))
126
+ // }
127
127
 
128
128
  let isGitRepo = false
129
129
 
@@ -143,9 +143,9 @@ try {
143
143
  }
144
144
 
145
145
  if (isGitRepo) {
146
- console.log(chalk.yellow('当前已是一个 Git 仓库'))
146
+ console.log(log.success('👍 已初始化Git'))
147
147
  } else {
148
- console.log(chalk.red('未检测到 Git 仓库,正在初始化...'))
148
+ console.log(log.warn('👌 未检测到 Git 仓库,正在初始化...'))
149
149
  execSync('git init', { stdio: 'inherit', cwd: projectRoot })
150
150
  }
151
151
 
@@ -166,7 +166,7 @@ switch (packageManager) {
166
166
  break
167
167
  }
168
168
 
169
- console.log(chalk.green(`执行 Husky 初始化命令:${huskyInitCommand}`))
169
+ console.log(chalk.green(`🐶 Husky初始化`))
170
170
  execSync(huskyInitCommand, { stdio: 'inherit', cwd: projectRoot })
171
171
 
172
172
  // 执行 setup-script 中的所有文件
@@ -184,7 +184,7 @@ try {
184
184
 
185
185
  for (const script of setupScripts) {
186
186
  const scriptPath = path.join(__dirname, '..', 'setup-script', script)
187
- console.log(chalk.green(`执行脚本:${scriptPath}`))
187
+ console.log(chalk.green(`🚀 执行脚本`))
188
188
  execSync(`sh ${scriptPath}`, { stdio: 'inherit', cwd: projectRoot })
189
189
  }
190
190
  console.log(chalk.green('所有 setup-script 已执行完毕'))
@@ -0,0 +1,48 @@
1
+ /* eslint-env node */
2
+ import chalk from 'chalk'
3
+ import { execSync } from 'child_process'
4
+ import cliProgress from 'cli-progress'
5
+
6
+ export function installWithProgress(dependencies, packageManager, projectRoot) {
7
+ if (!dependencies || dependencies.length === 0) {
8
+ console.log(chalk.yellow('✅ 所有开发依赖已安装,跳过安装'))
9
+ return
10
+ }
11
+
12
+ console.log(chalk.cyan(`⬇️ 开始安装 ${dependencies.length} 个开发依赖...`))
13
+
14
+ const bar = new cliProgress.SingleBar({
15
+ format: `${chalk.green('📦 安装中')} {bar} {percentage}% | {value}/{total} | 正在安装: {dep}`,
16
+ barCompleteChar: '█',
17
+ barIncompleteChar: '░',
18
+ hideCursor: true
19
+ })
20
+
21
+ bar.start(dependencies.length, 0, { dep: '' })
22
+
23
+ try {
24
+ for (let i = 0; i < dependencies.length; i++) {
25
+ const dep = dependencies[i]
26
+
27
+ const installCommand = {
28
+ pnpm: `pnpm add -D ${dep}`,
29
+ yarn: `yarn add ${dep} --dev`,
30
+ bun: `bun add -d ${dep}`,
31
+ npm: `npm install ${dep} --save-dev`
32
+ }[packageManager]
33
+
34
+ bar.update(i, { dep })
35
+
36
+ execSync(installCommand, { cwd: projectRoot, stdio: 'ignore' })
37
+
38
+ bar.update(i + 1, { dep })
39
+ }
40
+
41
+ bar.stop()
42
+ console.log(chalk.green('✅ 所有开发依赖安装完成'))
43
+ } catch (err) {
44
+ bar.stop()
45
+ console.log(chalk.red('❌ 安装过程中出错'), err)
46
+ throw err
47
+ }
48
+ }
package/lib/index.mjs CHANGED
@@ -8,6 +8,8 @@ var _chalk = _interopRequireDefault(require("chalk"));
8
8
  var _child_process = require("child_process");
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
  var _url = require("url");
11
+ var _chalkColor = require("./chalkColor.js");
12
+ var _installWithProgress = require("./installWithProgress.js");
11
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
14
  // 模拟 CommonJS 的 __dirname
13
15
  const _filename = (0, _url.fileURLToPath)(import.meta.url);
@@ -28,7 +30,7 @@ function findProjectRootWithLockFile() {
28
30
  return process.cwd(); // fallback
29
31
  }
30
32
  const projectRoot = findProjectRootWithLockFile();
31
- console.log(_chalk.default.green(`检测到项目根目录:${projectRoot}`));
33
+ console.log(`📁 根目录:${projectRoot}`);
32
34
  function detectPackageManager() {
33
35
  if (_fs.default.existsSync(_path.default.join(projectRoot, 'pnpm-lock.yaml'))) {
34
36
  return 'pnpm';
@@ -40,16 +42,14 @@ function detectPackageManager() {
40
42
  return 'npm';
41
43
  }
42
44
  }
43
- console.log('执行 postinstall 脚本:bin/index.js');
44
45
  const packageManager = detectPackageManager();
45
- console.log(_chalk.default.green(`检测到使用的包管理器:${packageManager}`));
46
+ console.log(`🍀 包管理器:${packageManager}`);
46
47
  const packageJsonPath = _path.default.join(projectRoot, 'package.json');
47
48
  const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf8'));
48
49
 
49
50
  // 检查是否已经初始化过
50
51
  const initFlagPath = _path.default.join(projectRoot, '.commit-pack-init');
51
52
  if (_fs.default.existsSync(initFlagPath)) {
52
- console.log(_chalk.default.yellow('已检测到初始化标志文件,跳过初始化'));
53
53
  process.exit(0);
54
54
  }
55
55
 
@@ -61,7 +61,7 @@ const devDependenciesWithVersion = {
61
61
  commitizen: '4.2.4',
62
62
  eslint: '8.57.1'
63
63
  };
64
- const devDependencies = ['@typescript-eslint/parser', '@typescript-eslint/eslint-plugin', 'prettier', 'eslint-config-prettier', 'eslint-plugin-prettier', 'husky', 'lint-staged', '@commitlint/cli', '@commitlint/config-conventional', 'commitlint-config-cz', 'cz-customizable', 'cz-custom'];
64
+ const devDependencies = ['@typescript-eslint/parser', '@typescript-eslint/eslint-plugin', 'prettier', 'eslint-config-prettier', 'eslint-plugin-prettier', 'husky', 'lint-staged', '@commitlint/cli', '@commitlint/config-conventional', 'commitlint-config-cz', 'cz-customizable', 'cz-custom', 'prettier-plugin-tailwindcss'];
65
65
  let dependenciesToInstall = [];
66
66
 
67
67
  // 检查并收集需要安装的依赖
@@ -75,33 +75,32 @@ for (const [dep, version] of Object.entries(devDependenciesWithVersion)) {
75
75
  dependenciesToInstall.push(`${dep}@${version}`);
76
76
  }
77
77
  }
78
+ (0, _installWithProgress.installWithProgress)(dependenciesToInstall, packageManager, projectRoot);
79
+ // // 安装缺失的依赖
80
+ // if (dependenciesToInstall.length > 0) {
81
+ // let installCommand = ''
82
+
83
+ // switch (packageManager) {
84
+ // case 'pnpm':
85
+ // installCommand = `pnpm add -D ${dependenciesToInstall.join(' ')}`
86
+ // break
87
+ // case 'yarn':
88
+ // installCommand = `yarn add ${dependenciesToInstall.join(' ')} --dev`
89
+ // break
90
+ // case 'bun':
91
+ // installCommand = `bun add -d ${dependenciesToInstall.join(' ')}`
92
+ // break
93
+ // default:
94
+ // installCommand = `npm install ${dependenciesToInstall.join(' ')} --save-dev`
95
+ // break
96
+ // }
97
+
98
+ // console.log(chalk.green(`⬇️ 安装依赖:${dependenciesToInstall.join(', ')}`))
99
+ // execSync(installCommand, { stdio: 'inherit', cwd: projectRoot })
100
+ // } else {
101
+ // console.log(log.warn('已安装 跳过...'))
102
+ // }
78
103
 
79
- // 安装缺失的依赖
80
- if (dependenciesToInstall.length > 0) {
81
- let installCommand = '';
82
- switch (packageManager) {
83
- case 'pnpm':
84
- installCommand = `pnpm add -D ${dependenciesToInstall.join(' ')}`;
85
- break;
86
- case 'yarn':
87
- installCommand = `yarn add ${dependenciesToInstall.join(' ')} --dev`;
88
- break;
89
- case 'bun':
90
- installCommand = `bun add -d ${dependenciesToInstall.join(' ')}`;
91
- break;
92
- default:
93
- installCommand = `npm install ${dependenciesToInstall.join(' ')} --save-dev`;
94
- break;
95
- }
96
- console.log(_chalk.default.green(`正在安装开发依赖:${dependenciesToInstall.join(', ')}`));
97
- console.log(_chalk.default.green(`执行命令:${installCommand}`));
98
- (0, _child_process.execSync)(installCommand, {
99
- stdio: 'inherit',
100
- cwd: projectRoot
101
- });
102
- } else {
103
- console.log(_chalk.default.yellow('所有开发依赖已安装,无需安装'));
104
- }
105
104
  let isGitRepo = false;
106
105
  try {
107
106
  // 获取 Git 仓库的顶级目录
@@ -118,9 +117,9 @@ try {
118
117
  isGitRepo = false;
119
118
  }
120
119
  if (isGitRepo) {
121
- console.log(_chalk.default.yellow('当前已是一个 Git 仓库'));
120
+ console.log(_chalkColor.log.success('👍 已初始化Git'));
122
121
  } else {
123
- console.log(_chalk.default.red('未检测到 Git 仓库,正在初始化...'));
122
+ console.log(_chalkColor.log.warn('👌 未检测到 Git 仓库,正在初始化...'));
124
123
  (0, _child_process.execSync)('git init', {
125
124
  stdio: 'inherit',
126
125
  cwd: projectRoot
@@ -143,7 +142,7 @@ switch (packageManager) {
143
142
  huskyInitCommand = 'npx husky init';
144
143
  break;
145
144
  }
146
- console.log(_chalk.default.green(`执行 Husky 初始化命令:${huskyInitCommand}`));
145
+ console.log(_chalk.default.green(`🐶 Husky初始化`));
147
146
  (0, _child_process.execSync)(huskyInitCommand, {
148
147
  stdio: 'inherit',
149
148
  cwd: projectRoot
@@ -155,7 +154,7 @@ try {
155
154
  const setupScripts = ['prettier.sh', 'lintstagedrc.sh', 'eslint.sh', 'czrc.sh', 'husky.sh', 'cz-config.sh', 'commitlintrc.sh'];
156
155
  for (const script of setupScripts) {
157
156
  const scriptPath = _path.default.join(_dirname, '..', 'setup-script', script);
158
- console.log(_chalk.default.green(`执行脚本:${scriptPath}`));
157
+ console.log(_chalk.default.green(`🚀 执行脚本`));
159
158
  (0, _child_process.execSync)(`sh ${scriptPath}`, {
160
159
  stdio: 'inherit',
161
160
  cwd: projectRoot
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-pack",
3
- "version": "1.0.21",
3
+ "version": "1.1.2",
4
4
  "description": "A setup package to automatly check project's style and commit configuration",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -34,18 +34,19 @@
34
34
  "author": "jett191",
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "@typescript-eslint/parser": "^8.12.2",
37
+ "@commitlint/cli": "^19.5.0",
38
+ "@commitlint/config-conventional": "^19.5.0",
38
39
  "@typescript-eslint/eslint-plugin": "^8.12.2",
39
- "prettier": "^3.3.3",
40
+ "@typescript-eslint/parser": "^8.12.2",
41
+ "cli-progress": "^3.12.0",
42
+ "commitlint-config-cz": "^0.13.3",
43
+ "cz-custom": "^0.0.2",
44
+ "cz-customizable": "^7.2.1",
40
45
  "eslint-config-prettier": "^9.1.0",
41
46
  "eslint-plugin-prettier": "^5.2.1",
42
47
  "husky": "^9.1.6",
43
48
  "lint-staged": "^15.2.10",
44
- "@commitlint/cli": "^19.5.0",
45
- "@commitlint/config-conventional": "^19.5.0",
46
- "commitlint-config-cz": "^0.13.3",
47
- "cz-custom": "^0.0.2",
48
- "cz-customizable": "^7.2.1"
49
+ "prettier": "^3.3.3"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@babel/cli": "^7.25.9",
@@ -7,7 +7,8 @@ echo '
7
7
  "semi": false,
8
8
  "tabWidth": 2,
9
9
  "bracketSpacing": true,
10
- "trailingComma": "none"
10
+ "trailingComma": "none",
11
+ "plugins": ["prettier-plugin-tailwindcss"]
11
12
  }
12
13
  ' > .prettierrc
13
14