@farris/cli 1.0.27 → 1.0.28
Sign up to get free protection for your applications and to get access to all the features.
- package/ci/cli.js +6 -81
- package/package.json +1 -1
package/ci/cli.js
CHANGED
@@ -183,78 +183,30 @@ function checkProjectChanges(projectInfo, lastCommit) {
|
|
183
183
|
* @returns 更新后的版本
|
184
184
|
*/
|
185
185
|
function updateProjectVersion(projectInfo, updateVersionType) {
|
186
|
-
let npmCommandArray = [];
|
187
186
|
const projectPath = projectInfo.project.path;
|
188
187
|
if (!projectPath) {
|
189
188
|
throw new Error(`update project version error: you must provide project path by project info object.`)
|
190
189
|
}
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
break;
|
195
|
-
case 'patch':
|
196
|
-
npmCommandArray = ['version', 'patch', '--prefix', projectPath];
|
197
|
-
break;
|
198
|
-
case 'minor':
|
199
|
-
npmCommandArray = ['version', 'minor', '--prefix', projectPath];
|
200
|
-
break;
|
201
|
-
case 'major':
|
202
|
-
npmCommandArray = ['version', 'major', '--prefix', projectPath];
|
203
|
-
break;
|
190
|
+
const updateProjectVersion = ['version', updateVersionType, '--force', '--no-git-tag-version', '--prefix', projectPath];
|
191
|
+
if (updateVersionType === 'prerelease') {
|
192
|
+
updateProjectVersion.push('--preid=beta');
|
204
193
|
}
|
205
194
|
return childProcess
|
206
195
|
// 使用 npm version prerelease 更新指定工程的预发布版本
|
207
|
-
.exec('npm',
|
196
|
+
.exec('npm', updateProjectVersion)
|
208
197
|
.then((returnValue) => {
|
209
198
|
// 读取目标工程的package.json文件
|
210
199
|
const packageJsonFilePath = `${projectPath}/package.json`;
|
211
200
|
const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
|
212
201
|
// 提取更新后的版本
|
213
202
|
const updatedVersion = returnValue.stdout;
|
214
|
-
console.log(`
|
203
|
+
console.log(`Update ${packageConfig.name} prerelease version to ${updatedVersion}.`);
|
215
204
|
const updateResult = {};
|
216
205
|
updateResult[packageConfig.name] = updatedVersion;
|
217
206
|
return updateResult;
|
218
207
|
})
|
219
208
|
}
|
220
209
|
|
221
|
-
function updateMonoWorkspaceVersion(monoWorkspace, updateVersionType, commitUrl) {
|
222
|
-
let npmCommandArray = [];
|
223
|
-
switch (updateVersionType) {
|
224
|
-
case 'prerelease':
|
225
|
-
npmCommandArray = ['version', 'prerelease', '--preid=beta'];
|
226
|
-
break;
|
227
|
-
case 'patch':
|
228
|
-
npmCommandArray = ['version', 'patch'];
|
229
|
-
break;
|
230
|
-
case 'minor':
|
231
|
-
npmCommandArray = ['version', 'minor'];
|
232
|
-
break;
|
233
|
-
case 'major':
|
234
|
-
npmCommandArray = ['version', 'major'];
|
235
|
-
break;
|
236
|
-
}
|
237
|
-
console.log(`executing npm version --${updateVersionType} in root directory.`)
|
238
|
-
childProcess.execSync('npm', npmCommandArray);
|
239
|
-
const packageJsonFilePath = `./package.json`;
|
240
|
-
const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
|
241
|
-
monoWorkspace.version = packageConfig.version;
|
242
|
-
// 向git缓冲区中添加变更
|
243
|
-
childProcess.execSync('git', ['add', '.']);
|
244
|
-
// 提交变更记录
|
245
|
-
childProcess.execSync('git', ['commit', '-m', `Update MonoWorkspace version to v${packageConfig.version}. [skip ci]`]);
|
246
|
-
console.log(`Update MonoWorkspace version to v${packageConfig.version}`);
|
247
|
-
const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
|
248
|
-
// 提交变更集
|
249
|
-
if (commitUrl) {
|
250
|
-
console.log(`executing git push ${branch} to ${commitUrl}`);
|
251
|
-
return childProcess.exec("git", ["push", commitUrl]);
|
252
|
-
} else {
|
253
|
-
console.log(`executing git push ${branch}`);
|
254
|
-
return childProcess.exec('git', ['push']);
|
255
|
-
}
|
256
|
-
}
|
257
|
-
|
258
210
|
function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
|
259
211
|
const versionMessage = Object.keys(updatedVersions).reduce((latestMessage, packageName, index, originalArray) => {
|
260
212
|
const version = updatedVersions[packageName];
|
@@ -274,20 +226,6 @@ function commitVersionChanges(updatedVersions, commitUrl, monoWorkspace, updateV
|
|
274
226
|
if (updateVersionType === 'prerelease') {
|
275
227
|
updateWorkspaceVersion.push('--preid=beta');
|
276
228
|
}
|
277
|
-
// switch (updateVersionType) {
|
278
|
-
// case 'prerelease':
|
279
|
-
// updateWorkspaceVersion = ['version', 'prerelease', '--preid=beta', '--force', '--no-git-tag-version'];
|
280
|
-
// break;
|
281
|
-
// case 'patch':
|
282
|
-
// updateWorkspaceVersion = ['version', 'patch', '--force', '--no-git-tag-version'];
|
283
|
-
// break;
|
284
|
-
// case 'minor':
|
285
|
-
// updateWorkspaceVersion = ['version', 'minor', '--force', '--no-git-tag-version'];
|
286
|
-
// break;
|
287
|
-
// case 'major':
|
288
|
-
// updateWorkspaceVersion = ['version', 'major', '--force', '--no-git-tag-version'];
|
289
|
-
// break;
|
290
|
-
// }
|
291
229
|
console.log(`executing npm ${updateWorkspaceVersion.join(' ')} in root directory.`)
|
292
230
|
childProcess.execSync('npm', updateWorkspaceVersion);
|
293
231
|
|
@@ -300,10 +238,6 @@ function commitVersionChanges(updatedVersions, commitUrl, monoWorkspace, updateV
|
|
300
238
|
// 提交变更记录
|
301
239
|
childProcess.execSync('git', ['commit', '-m', `Update workspace version to v${packageConfig.version} for ${commitMessage}. [skip ci]`]);
|
302
240
|
|
303
|
-
// // 向git缓冲区中添加变更
|
304
|
-
// childProcess.execSync('git', ['add', '.']);
|
305
|
-
// // // 提交变更记录
|
306
|
-
// childProcess.execSync('git', ['commit', '-m', `${commitMessage}`]);
|
307
241
|
const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
|
308
242
|
// 提交变更集
|
309
243
|
if (commitUrl) {
|
@@ -322,7 +256,7 @@ function buildWorkspace(workspace) {
|
|
322
256
|
}
|
323
257
|
|
324
258
|
function addTagToMonoWorkspace(monoWorkspace, commitUrl) {
|
325
|
-
const monoWorkspaceVersion = monoWorkspace.version
|
259
|
+
const monoWorkspaceVersion = `v${monoWorkspace.version}`;
|
326
260
|
childProcess.execSync('git', ['tag', monoWorkspaceVersion, '-m', 'Publish npm packages. [skip ci]']);
|
327
261
|
// 提交变更集
|
328
262
|
if (commitUrl) {
|
@@ -426,15 +360,6 @@ function publish(commitUrl, updateVersionType) {
|
|
426
360
|
const updatedVersions = monoWorkspace.updateResult;
|
427
361
|
if (updatedVersions) {
|
428
362
|
return commitVersionChanges(updatedVersions, commitUrl, monoWorkspace, updateVersionType)
|
429
|
-
// .then((result) => {
|
430
|
-
// if (result.stderr) {
|
431
|
-
// console.log(result.stderr);
|
432
|
-
// }
|
433
|
-
// if (result.stdout) {
|
434
|
-
// console.log(result.stdout);
|
435
|
-
// }
|
436
|
-
// return updateMonoWorkspaceVersion(monoWorkspace, updateVersionType, commitUrl);
|
437
|
-
// })
|
438
363
|
.then((result) => {
|
439
364
|
if (result.stderr) {
|
440
365
|
console.log(result.stderr);
|