commit-pack 1.0.19 → 1.0.20
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 +66 -0
- package/lib/index.mjs +50 -0
- package/package.json +1 -1
package/bin/index.mjs
CHANGED
|
@@ -59,6 +59,72 @@ if (fs.existsSync(initFlagPath)) {
|
|
|
59
59
|
process.exit(0)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// 确保 devDependencies 存在
|
|
63
|
+
if (!packageJson.devDependencies) {
|
|
64
|
+
packageJson.devDependencies = {}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const devDependenciesWithVersion = {
|
|
68
|
+
commitizen: '4.2.4',
|
|
69
|
+
eslint: '8.57.1'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const devDependencies = [
|
|
73
|
+
'@typescript-eslint/parser',
|
|
74
|
+
'@typescript-eslint/eslint-plugin',
|
|
75
|
+
'prettier',
|
|
76
|
+
'eslint-config-prettier',
|
|
77
|
+
'eslint-plugin-prettier',
|
|
78
|
+
'husky',
|
|
79
|
+
'lint-staged',
|
|
80
|
+
'@commitlint/cli',
|
|
81
|
+
'@commitlint/config-conventional',
|
|
82
|
+
'commitlint-config-cz',
|
|
83
|
+
'cz-customizable',
|
|
84
|
+
'cz-custom'
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
let dependenciesToInstall = []
|
|
88
|
+
|
|
89
|
+
// 检查并收集需要安装的依赖
|
|
90
|
+
for (const dep of devDependencies) {
|
|
91
|
+
if (!packageJson.devDependencies[dep]) {
|
|
92
|
+
dependenciesToInstall.push(dep)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (const [dep, version] of Object.entries(devDependenciesWithVersion)) {
|
|
97
|
+
if (!packageJson.devDependencies[dep]) {
|
|
98
|
+
dependenciesToInstall.push(`${dep}@${version}`)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
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
|
+
}
|
|
127
|
+
|
|
62
128
|
let isGitRepo = false
|
|
63
129
|
|
|
64
130
|
try {
|
package/lib/index.mjs
CHANGED
|
@@ -52,6 +52,56 @@ if (_fs.default.existsSync(initFlagPath)) {
|
|
|
52
52
|
console.log(_chalk.default.yellow('已检测到初始化标志文件,跳过初始化'));
|
|
53
53
|
process.exit(0);
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
// 确保 devDependencies 存在
|
|
57
|
+
if (!packageJson.devDependencies) {
|
|
58
|
+
packageJson.devDependencies = {};
|
|
59
|
+
}
|
|
60
|
+
const devDependenciesWithVersion = {
|
|
61
|
+
commitizen: '4.2.4',
|
|
62
|
+
eslint: '8.57.1'
|
|
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'];
|
|
65
|
+
let dependenciesToInstall = [];
|
|
66
|
+
|
|
67
|
+
// 检查并收集需要安装的依赖
|
|
68
|
+
for (const dep of devDependencies) {
|
|
69
|
+
if (!packageJson.devDependencies[dep]) {
|
|
70
|
+
dependenciesToInstall.push(dep);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const [dep, version] of Object.entries(devDependenciesWithVersion)) {
|
|
74
|
+
if (!packageJson.devDependencies[dep]) {
|
|
75
|
+
dependenciesToInstall.push(`${dep}@${version}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
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
|
+
}
|
|
55
105
|
let isGitRepo = false;
|
|
56
106
|
try {
|
|
57
107
|
// 获取 Git 仓库的顶级目录
|