jjb-cmd 2.5.3 → 2.5.4
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/SECURITY.md +71 -0
- package/bin/command.js +6 -0
- package/build.js +20 -0
- package/obf.config.json +3 -0
- package/package.json +4 -2
- package/src/ai-pull.js +675 -0
- package/src/auth.js +71 -1
- package/src/code-optimization.js +46 -1
- package/src/config.js +122 -1
- package/src/crypto-utils.js +183 -1
- package/src/password-input.js +79 -1
- package/src/publish.js +307 -1
- package/src/push.js +417 -1
- package/src/rm-rf.js +49 -1
- package/src/utils.js +228 -1
package/src/utils.js
CHANGED
|
@@ -1 +1,228 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const child_process = require('child_process');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
|
|
6
|
+
// 常量定义
|
|
7
|
+
const CONSTANTS = {
|
|
8
|
+
MAX_BUFFER_SIZE: 1000000000, // 1GB
|
|
9
|
+
SYNC_DELAY: 1000, // 1秒
|
|
10
|
+
DEFAULT_BRANCH: 'master',
|
|
11
|
+
CONFIG_FILE_NAME: 'jjb.config.js',
|
|
12
|
+
BUILD_OUTPUT_DIR: 'dist',
|
|
13
|
+
TEMPLATES_PATH: 'start/src/main/resources/templates'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
// 日志函数
|
|
18
|
+
function logInfo(message, path = '') {
|
|
19
|
+
const prefix = chalk.blue('ℹ');
|
|
20
|
+
const output = path ? `${prefix} ${message} ${path}` : `${prefix} ${message}`;
|
|
21
|
+
console.log(output);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function logSuccess(message) {
|
|
25
|
+
console.log(chalk.green(`✓ ${message}`));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function logWarning(message) {
|
|
29
|
+
console.log(chalk.yellow(`⚠ ${message}`));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function logError(message) {
|
|
33
|
+
console.log(chalk.red(`✗ ${message}`));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 统一的命令执行函数
|
|
37
|
+
function executeCommand(command, cwd, options = {}) {
|
|
38
|
+
logInfo(`执行命令: ${command}`, cwd ? `[工作目录: ${cwd}]` : '');
|
|
39
|
+
return child_process.execSync(command, { cwd, ...options });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 文件处理函数
|
|
43
|
+
function deleteFolderRecursive(folderPath) {
|
|
44
|
+
if (fs.existsSync(folderPath)) {
|
|
45
|
+
fs.readdirSync(folderPath).forEach((file) => {
|
|
46
|
+
const curPath = path.join(folderPath, file);
|
|
47
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
|
48
|
+
// 递归删除子文件夹
|
|
49
|
+
deleteFolderRecursive(curPath);
|
|
50
|
+
} else {
|
|
51
|
+
// 删除文件
|
|
52
|
+
fs.unlinkSync(curPath);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
// 删除空文件夹
|
|
56
|
+
fs.rmdirSync(folderPath);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 检查文件是否存在
|
|
61
|
+
function fileExists(filePath) {
|
|
62
|
+
return fs.existsSync(filePath);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 读取文件内容
|
|
66
|
+
function readFile(filePath, encoding = 'utf8') {
|
|
67
|
+
return fs.readFileSync(filePath, encoding);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 写入文件内容
|
|
71
|
+
function writeFile(filePath, content, encoding = 'utf8') {
|
|
72
|
+
fs.writeFileSync(filePath, content, encoding);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 创建目录
|
|
76
|
+
function createDir(dirPath) {
|
|
77
|
+
if (!fs.existsSync(dirPath)) {
|
|
78
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 检查是否为 Vite 项目
|
|
83
|
+
function isViteProject(rootPath) {
|
|
84
|
+
return fileExists(path.join(rootPath, 'vite.config.js')) ||
|
|
85
|
+
fileExists(path.join(rootPath, 'vite.config.ts')) ||
|
|
86
|
+
fileExists(path.join(rootPath, 'vite.config.mjs'));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 验证配置对象
|
|
90
|
+
function validateConfig(config, requiredFields) {
|
|
91
|
+
const missingFields = requiredFields.filter(field => !config[field]);
|
|
92
|
+
return {
|
|
93
|
+
isValid: missingFields.length === 0,
|
|
94
|
+
missingFields
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 验证环境配置
|
|
99
|
+
function validateEnvironment(config, environment) {
|
|
100
|
+
return config.environment && config.environment[environment];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @description 清空当前目录
|
|
105
|
+
* @param filePath
|
|
106
|
+
* @param callback
|
|
107
|
+
* @constructor
|
|
108
|
+
*/
|
|
109
|
+
function DeleteDirAllFile(filePath, callback) {
|
|
110
|
+
let files = [];
|
|
111
|
+
if (fs.existsSync(filePath)) {
|
|
112
|
+
files = fs.readdirSync(filePath);
|
|
113
|
+
files.forEach(function (file, index) {
|
|
114
|
+
let curPath = path.join(filePath, file);
|
|
115
|
+
if (fs.statSync(curPath).isDirectory()) {
|
|
116
|
+
DeleteDirAllFile(curPath);
|
|
117
|
+
} else {
|
|
118
|
+
fs.unlinkSync(curPath);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
fs.rmdirSync(filePath);
|
|
122
|
+
callback && callback();
|
|
123
|
+
} else {
|
|
124
|
+
callback && callback();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @description 复制单个文件
|
|
130
|
+
* @param srcFile
|
|
131
|
+
* @param tarFile
|
|
132
|
+
* @param cb
|
|
133
|
+
*/
|
|
134
|
+
function CopyFile(srcFile, tarFile, cb) {
|
|
135
|
+
// 确保目标目录存在
|
|
136
|
+
const tarDir = path.dirname(tarFile);
|
|
137
|
+
if (!fs.existsSync(tarDir)) {
|
|
138
|
+
fs.mkdirSync(tarDir, { recursive: true });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const rs = fs.createReadStream(srcFile);
|
|
142
|
+
const ws = fs.createWriteStream(tarFile);
|
|
143
|
+
|
|
144
|
+
rs.pipe(ws);
|
|
145
|
+
|
|
146
|
+
ws.on('close', function() {
|
|
147
|
+
cb && cb();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
ws.on('error', function(err) {
|
|
151
|
+
logError(`文件复制失败: ${err.message}`);
|
|
152
|
+
cb && cb();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @description 复制文件夹及子目录文件
|
|
158
|
+
* @param srcDir
|
|
159
|
+
* @param tarDir
|
|
160
|
+
* @param cb
|
|
161
|
+
*/
|
|
162
|
+
function CopyFolder(srcDir, tarDir, cb) {
|
|
163
|
+
// 确保目标目录存在
|
|
164
|
+
if (!fs.existsSync(tarDir)) {
|
|
165
|
+
fs.mkdirSync(tarDir, { recursive: true });
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
fs.readdir(srcDir, function (err, files) {
|
|
169
|
+
|
|
170
|
+
let count = 0;
|
|
171
|
+
const checkEnd = function () {
|
|
172
|
+
++count === files.length && cb && cb();
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
if (err) {
|
|
176
|
+
checkEnd();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
files.forEach(function (file) {
|
|
181
|
+
const srcPath = path.join(srcDir, file);
|
|
182
|
+
const tarPath = path.join(tarDir, file);
|
|
183
|
+
|
|
184
|
+
fs.stat(srcPath, function (err, stats) {
|
|
185
|
+
if (stats.isDirectory()) {
|
|
186
|
+
fs.mkdir(tarPath, { recursive: true }, function (err) {
|
|
187
|
+
if (err) {
|
|
188
|
+
logError(`创建目录失败: ${err.message}`);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
CopyFolder(srcPath, tarPath, checkEnd);
|
|
193
|
+
});
|
|
194
|
+
} else {
|
|
195
|
+
// 复制文件
|
|
196
|
+
const rs = fs.createReadStream(srcPath);
|
|
197
|
+
const ws = fs.createWriteStream(tarPath);
|
|
198
|
+
rs.pipe(ws);
|
|
199
|
+
ws.on('close', checkEnd);
|
|
200
|
+
ws.on('error', checkEnd);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
//为空时直接回调
|
|
205
|
+
files.length === 0 && cb && cb();
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
module.exports = {
|
|
211
|
+
CONSTANTS,
|
|
212
|
+
logInfo,
|
|
213
|
+
logSuccess,
|
|
214
|
+
logWarning,
|
|
215
|
+
logError,
|
|
216
|
+
executeCommand,
|
|
217
|
+
deleteFolderRecursive,
|
|
218
|
+
fileExists,
|
|
219
|
+
readFile,
|
|
220
|
+
writeFile,
|
|
221
|
+
createDir,
|
|
222
|
+
isViteProject,
|
|
223
|
+
validateConfig,
|
|
224
|
+
validateEnvironment,
|
|
225
|
+
DeleteDirAllFile,
|
|
226
|
+
CopyFile,
|
|
227
|
+
CopyFolder
|
|
228
|
+
};
|