@farris/cli 1.0.25 → 1.0.28
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/ci/cli.js +67 -85
- package/package.json +1 -1
package/ci/cli.js
CHANGED
@@ -168,7 +168,7 @@ function checkProjectChanges(projectInfo, lastCommit) {
|
|
168
168
|
const hasChanges = changedFiles.length > 0;
|
169
169
|
if (hasChanges) {
|
170
170
|
projectInfo.workspace.hasChanged = hasChanges;
|
171
|
-
console.log(`${packageName} has changed
|
171
|
+
console.log(`${packageName} has changed since latest tag ${lastCommit}.`)
|
172
172
|
} else {
|
173
173
|
console.log(`${packageName} has not changed.`)
|
174
174
|
}
|
@@ -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];
|
@@ -267,19 +219,26 @@ function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
|
|
267
219
|
return `${versionMessage} ${suffix}`;
|
268
220
|
}
|
269
221
|
|
270
|
-
function commitVersionChanges(updatedVersions, commitUrl) {
|
271
|
-
const commitMessage = builderVersionChangeMessage('
|
272
|
-
|
222
|
+
function commitVersionChanges(updatedVersions, commitUrl, monoWorkspace, updateVersionType) {
|
223
|
+
const commitMessage = builderVersionChangeMessage('update', updatedVersions, '');
|
273
224
|
if (commitMessage) {
|
225
|
+
const updateWorkspaceVersion = ['version', '--force', '--no-git-tag-version', updateVersionType];
|
226
|
+
if (updateVersionType === 'prerelease') {
|
227
|
+
updateWorkspaceVersion.push('--preid=beta');
|
228
|
+
}
|
229
|
+
console.log(`executing npm ${updateWorkspaceVersion.join(' ')} in root directory.`)
|
230
|
+
childProcess.execSync('npm', updateWorkspaceVersion);
|
231
|
+
|
232
|
+
const packageJsonFilePath = `./package.json`;
|
233
|
+
const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
|
234
|
+
monoWorkspace.version = packageConfig.version;
|
235
|
+
|
274
236
|
// 向git缓冲区中添加变更
|
275
237
|
childProcess.execSync('git', ['add', '.']);
|
276
|
-
//
|
277
|
-
childProcess.execSync('git', ['commit', '-m',
|
278
|
-
|
279
|
-
console.log(commitMessage);
|
238
|
+
// 提交变更记录
|
239
|
+
childProcess.execSync('git', ['commit', '-m', `Update workspace version to v${packageConfig.version} for ${commitMessage}. [skip ci]`]);
|
280
240
|
|
281
241
|
const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
|
282
|
-
|
283
242
|
// 提交变更集
|
284
243
|
if (commitUrl) {
|
285
244
|
console.log(`executing git push ${branch} to ${commitUrl}`);
|
@@ -297,10 +256,7 @@ function buildWorkspace(workspace) {
|
|
297
256
|
}
|
298
257
|
|
299
258
|
function addTagToMonoWorkspace(monoWorkspace, commitUrl) {
|
300
|
-
|
301
|
-
// const date = moment(new Date());
|
302
|
-
// const tagVersion = `v${date.format('YYYYMMDDHHmmss')}`;
|
303
|
-
const monoWorkspaceVersion = monoWorkspace.version;
|
259
|
+
const monoWorkspaceVersion = `v${monoWorkspace.version}`;
|
304
260
|
childProcess.execSync('git', ['tag', monoWorkspaceVersion, '-m', 'Publish npm packages. [skip ci]']);
|
305
261
|
// 提交变更集
|
306
262
|
if (commitUrl) {
|
@@ -374,9 +330,9 @@ function publish(commitUrl, updateVersionType) {
|
|
374
330
|
// 3. 检查代码提交记录,获取自上次发布以来所有发生变化的Angular工程
|
375
331
|
chain = chain.then(monoWorkspace => {
|
376
332
|
const projects = monoWorkspace.projects;
|
333
|
+
const lastCommit = getLastCommit();
|
334
|
+
console.log(`last commit ${lastCommit}`);
|
377
335
|
const checkProjects = projects.map((projectInfo) => {
|
378
|
-
const lastCommit = getLastCommit();
|
379
|
-
console.log(`last commit ${lastCommit}`);
|
380
336
|
let checkPromise = checkProjectChanges(projectInfo, lastCommit);
|
381
337
|
let changedPromise = checkPromise.then(hasChanged => {
|
382
338
|
projectInfo.hasChanged = hasChanged;
|
@@ -402,13 +358,21 @@ function publish(commitUrl, updateVersionType) {
|
|
402
358
|
return workspace;
|
403
359
|
}, monoWorkspace);
|
404
360
|
const updatedVersions = monoWorkspace.updateResult;
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
361
|
+
if (updatedVersions) {
|
362
|
+
return commitVersionChanges(updatedVersions, commitUrl, monoWorkspace, updateVersionType)
|
363
|
+
.then((result) => {
|
364
|
+
if (result.stderr) {
|
365
|
+
console.log(result.stderr);
|
366
|
+
}
|
367
|
+
if (result.stdout) {
|
368
|
+
console.log(result.stdout);
|
369
|
+
}
|
370
|
+
return Promise.resolve(monoWorkspace);
|
371
|
+
});
|
372
|
+
} else {
|
373
|
+
return Promise.resolve(monoWorkspace);
|
374
|
+
}
|
375
|
+
|
412
376
|
});
|
413
377
|
});
|
414
378
|
// 5. 编译所有Angular工作区
|
@@ -416,20 +380,38 @@ function publish(commitUrl, updateVersionType) {
|
|
416
380
|
const buildPromises = monoWorkspace.workspaces
|
417
381
|
.filter(workspace => workspace.hasChanged)
|
418
382
|
.map((workspace) => buildWorkspace(workspace));
|
419
|
-
|
420
|
-
.
|
421
|
-
|
422
|
-
|
423
|
-
|
383
|
+
if (buildPromises.length) {
|
384
|
+
return Promise.all(buildPromises)
|
385
|
+
.then((results) => {
|
386
|
+
if (results) {
|
387
|
+
results.map((result) => {
|
388
|
+
if (result.stderr) {
|
389
|
+
console.log(result.stderr);
|
390
|
+
}
|
391
|
+
if (result.stdout) {
|
392
|
+
console.log(result.stdout);
|
393
|
+
}
|
394
|
+
});
|
395
|
+
}
|
396
|
+
return Promise.resolve(monoWorkspace);
|
397
|
+
});
|
398
|
+
} else {
|
399
|
+
return Promise.resolve(monoWorkspace);
|
400
|
+
}
|
424
401
|
});
|
425
402
|
// 6. 将变更项目的内容发布为npm包,并增加发布Tag标签
|
426
403
|
chain = chain.then(monoWorkspace => {
|
427
404
|
const changedProjects = monoWorkspace.changedProjects;
|
428
|
-
|
429
|
-
|
430
|
-
.
|
431
|
-
|
432
|
-
|
405
|
+
if (changedProjects.length) {
|
406
|
+
const publishPromises = changedProjects.map(projectInfo => publishToNpmRepository(projectInfo.project.path));
|
407
|
+
Promise.all(publishPromises)
|
408
|
+
.then(() => {
|
409
|
+
return addTagToMonoWorkspace(monoWorkspace, commitUrl);
|
410
|
+
});
|
411
|
+
} else {
|
412
|
+
return Promise.resolve(monoWorkspace);
|
413
|
+
}
|
414
|
+
|
433
415
|
});
|
434
416
|
}
|
435
417
|
|