@farris/cli 1.0.24 → 1.0.27

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.
Files changed (2) hide show
  1. package/ci/cli.js +97 -33
  2. 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 sence last commit ${lastCommit}.`)
171
+ console.log(`${packageName} has changed since latest tag ${lastCommit}.`)
172
172
  } else {
173
173
  console.log(`${packageName} has not changed.`)
174
174
  }
@@ -241,16 +241,17 @@ function updateMonoWorkspaceVersion(monoWorkspace, updateVersionType, commitUrl)
241
241
  monoWorkspace.version = packageConfig.version;
242
242
  // 向git缓冲区中添加变更
243
243
  childProcess.execSync('git', ['add', '.']);
244
- // // 提交变更记录
244
+ // 提交变更记录
245
245
  childProcess.execSync('git', ['commit', '-m', `Update MonoWorkspace version to v${packageConfig.version}. [skip ci]`]);
246
246
  console.log(`Update MonoWorkspace version to v${packageConfig.version}`);
247
247
  const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
248
- console.log(`executing git push ${branch}`);
249
248
  // 提交变更集
250
249
  if (commitUrl) {
251
- childProcess.execSync("git", ["push", commitUrl]);
250
+ console.log(`executing git push ${branch} to ${commitUrl}`);
251
+ return childProcess.exec("git", ["push", commitUrl]);
252
252
  } else {
253
- childProcess.execSync('git', ['push']);
253
+ console.log(`executing git push ${branch}`);
254
+ return childProcess.exec('git', ['push']);
254
255
  }
255
256
  }
256
257
 
@@ -266,24 +267,51 @@ function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
266
267
  return `${versionMessage} ${suffix}`;
267
268
  }
268
269
 
269
- function commitVersionChanges(updatedVersions, commitUrl) {
270
- const commitMessage = builderVersionChangeMessage('Update', updatedVersions, '. [skip ci]');
271
-
270
+ function commitVersionChanges(updatedVersions, commitUrl, monoWorkspace, updateVersionType) {
271
+ const commitMessage = builderVersionChangeMessage('update', updatedVersions, '');
272
272
  if (commitMessage) {
273
+ const updateWorkspaceVersion = ['version', '--force', '--no-git-tag-version', updateVersionType];
274
+ if (updateVersionType === 'prerelease') {
275
+ updateWorkspaceVersion.push('--preid=beta');
276
+ }
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
+ console.log(`executing npm ${updateWorkspaceVersion.join(' ')} in root directory.`)
292
+ childProcess.execSync('npm', updateWorkspaceVersion);
293
+
294
+ const packageJsonFilePath = `./package.json`;
295
+ const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
296
+ monoWorkspace.version = packageConfig.version;
297
+
273
298
  // 向git缓冲区中添加变更
274
299
  childProcess.execSync('git', ['add', '.']);
275
- // // 提交变更记录
276
- childProcess.execSync('git', ['commit', '-m', `${commitMessage}`]);
277
-
278
- console.log(commitMessage);
300
+ // 提交变更记录
301
+ childProcess.execSync('git', ['commit', '-m', `Update workspace version to v${packageConfig.version} for ${commitMessage}. [skip ci]`]);
279
302
 
303
+ // // 向git缓冲区中添加变更
304
+ // childProcess.execSync('git', ['add', '.']);
305
+ // // // 提交变更记录
306
+ // childProcess.execSync('git', ['commit', '-m', `${commitMessage}`]);
280
307
  const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
281
- console.log(`executing git push ${branch}`);
282
308
  // 提交变更集
283
309
  if (commitUrl) {
284
- childProcess.execSync("git", ["push", commitUrl]);
310
+ console.log(`executing git push ${branch} to ${commitUrl}`);
311
+ return childProcess.exec("git", ["push", commitUrl]);
285
312
  } else {
286
- childProcess.execSync('git', ['push']);
313
+ console.log(`executing git push ${branch}`);
314
+ return childProcess.exec('git', ['push']);
287
315
  }
288
316
  }
289
317
  }
@@ -294,9 +322,6 @@ function buildWorkspace(workspace) {
294
322
  }
295
323
 
296
324
  function addTagToMonoWorkspace(monoWorkspace, commitUrl) {
297
- // const tagMessage = builderVersionChangeMessage('Publish npm packages ', monoWorkspace.updateResult, '.');
298
- // const date = moment(new Date());
299
- // const tagVersion = `v${date.format('YYYYMMDDHHmmss')}`;
300
325
  const monoWorkspaceVersion = monoWorkspace.version;
301
326
  childProcess.execSync('git', ['tag', monoWorkspaceVersion, '-m', 'Publish npm packages. [skip ci]']);
302
327
  // 提交变更集
@@ -371,9 +396,9 @@ function publish(commitUrl, updateVersionType) {
371
396
  // 3. 检查代码提交记录,获取自上次发布以来所有发生变化的Angular工程
372
397
  chain = chain.then(monoWorkspace => {
373
398
  const projects = monoWorkspace.projects;
399
+ const lastCommit = getLastCommit();
400
+ console.log(`last commit ${lastCommit}`);
374
401
  const checkProjects = projects.map((projectInfo) => {
375
- const lastCommit = getLastCommit();
376
- console.log(`last commit ${lastCommit}`);
377
402
  let checkPromise = checkProjectChanges(projectInfo, lastCommit);
378
403
  let changedPromise = checkPromise.then(hasChanged => {
379
404
  projectInfo.hasChanged = hasChanged;
@@ -399,9 +424,30 @@ function publish(commitUrl, updateVersionType) {
399
424
  return workspace;
400
425
  }, monoWorkspace);
401
426
  const updatedVersions = monoWorkspace.updateResult;
402
- commitVersionChanges(updatedVersions, commitUrl);
403
- updateMonoWorkspaceVersion(monoWorkspace, updateVersionType, commitUrl);
404
- return Promise.resolve(monoWorkspace);
427
+ if (updatedVersions) {
428
+ 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
+ .then((result) => {
439
+ if (result.stderr) {
440
+ console.log(result.stderr);
441
+ }
442
+ if (result.stdout) {
443
+ console.log(result.stdout);
444
+ }
445
+ return Promise.resolve(monoWorkspace);
446
+ });
447
+ } else {
448
+ return Promise.resolve(monoWorkspace);
449
+ }
450
+
405
451
  });
406
452
  });
407
453
  // 5. 编译所有Angular工作区
@@ -409,20 +455,38 @@ function publish(commitUrl, updateVersionType) {
409
455
  const buildPromises = monoWorkspace.workspaces
410
456
  .filter(workspace => workspace.hasChanged)
411
457
  .map((workspace) => buildWorkspace(workspace));
412
- return Promise.all(buildPromises)
413
- .then((results) => {
414
- console.log(results.stdout);
415
- return Promise.resolve(monoWorkspace);
416
- });
458
+ if (buildPromises.length) {
459
+ return Promise.all(buildPromises)
460
+ .then((results) => {
461
+ if (results) {
462
+ results.map((result) => {
463
+ if (result.stderr) {
464
+ console.log(result.stderr);
465
+ }
466
+ if (result.stdout) {
467
+ console.log(result.stdout);
468
+ }
469
+ });
470
+ }
471
+ return Promise.resolve(monoWorkspace);
472
+ });
473
+ } else {
474
+ return Promise.resolve(monoWorkspace);
475
+ }
417
476
  });
418
477
  // 6. 将变更项目的内容发布为npm包,并增加发布Tag标签
419
478
  chain = chain.then(monoWorkspace => {
420
479
  const changedProjects = monoWorkspace.changedProjects;
421
- const publishPromises = changedProjects.map(projectInfo => publishToNpmRepository(projectInfo.project.path));
422
- Promise.all(publishPromises)
423
- .then(() => {
424
- return addTagToMonoWorkspace(monoWorkspace, commitUrl);
425
- });
480
+ if (changedProjects.length) {
481
+ const publishPromises = changedProjects.map(projectInfo => publishToNpmRepository(projectInfo.project.path));
482
+ Promise.all(publishPromises)
483
+ .then(() => {
484
+ return addTagToMonoWorkspace(monoWorkspace, commitUrl);
485
+ });
486
+ } else {
487
+ return Promise.resolve(monoWorkspace);
488
+ }
489
+
426
490
  });
427
491
  }
428
492
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farris/cli",
3
- "version": "1.0.24",
3
+ "version": "1.0.27",
4
4
  "description": "Farris command line interface",
5
5
  "main": "index.js",
6
6
  "scripts": {