@farris/cli 1.0.23 → 1.0.26

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 +80 -36
  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
  }
@@ -218,7 +218,7 @@ function updateProjectVersion(projectInfo, updateVersionType) {
218
218
  })
219
219
  }
220
220
 
221
- function updateMonoWorkspaceVersion(monoWorkspace, updateVersionType) {
221
+ function updateMonoWorkspaceVersion(monoWorkspace, updateVersionType, commitUrl) {
222
222
  let npmCommandArray = [];
223
223
  switch (updateVersionType) {
224
224
  case 'prerelease':
@@ -238,12 +238,21 @@ function updateMonoWorkspaceVersion(monoWorkspace, updateVersionType) {
238
238
  childProcess.execSync('npm', npmCommandArray);
239
239
  const packageJsonFilePath = `./package.json`;
240
240
  const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
241
+ monoWorkspace.version = packageConfig.version;
241
242
  // 向git缓冲区中添加变更
242
- childProcess.execSync('git', ['add', '.']);
243
+ // childProcess.execSync('git', ['add', '.']);
243
244
  // // 提交变更记录
244
- childProcess.execSync('git', ['commit', '-m', `Update MonoWorkspace version to v${packageConfig.version}`]);
245
- console.log(`Update MonoWorkspace version to v${packageConfig.version}`);
246
- monoWorkspace.version = packageConfig.version;
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
+ }
247
256
  }
248
257
 
249
258
  function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
@@ -258,8 +267,8 @@ function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
258
267
  return `${versionMessage} ${suffix}`;
259
268
  }
260
269
 
261
- function commitVersionChanges(updatedVersions) {
262
- const commitMessage = builderVersionChangeMessage('Update', updatedVersions, '. [skip ci]');
270
+ function commitVersionChanges(updatedVersions, commitUrl) {
271
+ const commitMessage = builderVersionChangeMessage('Update', updatedVersions, ' [skip ci]');
263
272
 
264
273
  if (commitMessage) {
265
274
  // 向git缓冲区中添加变更
@@ -267,25 +276,22 @@ function commitVersionChanges(updatedVersions) {
267
276
  // // 提交变更记录
268
277
  childProcess.execSync('git', ['commit', '-m', `${commitMessage}`]);
269
278
 
270
- console.log(commitMessage);
271
- }
272
- }
279
+ const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
273
280
 
274
- function pushCommits(commitUrl) {
275
- const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
276
- console.log(`executing git push ${branch}`);
277
- // 提交变更集
278
- if (commitUrl) {
279
- return childProcess.exec("git", ["push", commitUrl]);
280
- } else {
281
- return childProcess.exec('git', ['push']);
281
+ // 提交变更集
282
+ if (commitUrl) {
283
+ console.log(`executing git push ${branch} to ${commitUrl}`);
284
+ return childProcess.exec("git", ["push", commitUrl]);
285
+ } else {
286
+ console.log(`executing git push ${branch}`);
287
+ return childProcess.exec('git', ['push']);
288
+ }
282
289
  }
283
290
  }
284
291
 
285
292
  function buildWorkspace(workspace) {
286
293
  console.log(`executing lerna run build --scope=${workspace.packageName}`)
287
294
  return childProcess.exec('lerna', ['run', 'build', `--scope=${workspace.packageName}`]);
288
- // lerna run build --scope=@farris/ide-framework
289
295
  }
290
296
 
291
297
  function addTagToMonoWorkspace(monoWorkspace, commitUrl) {
@@ -366,9 +372,9 @@ function publish(commitUrl, updateVersionType) {
366
372
  // 3. 检查代码提交记录,获取自上次发布以来所有发生变化的Angular工程
367
373
  chain = chain.then(monoWorkspace => {
368
374
  const projects = monoWorkspace.projects;
375
+ const lastCommit = getLastCommit();
376
+ console.log(`last commit ${lastCommit}`);
369
377
  const checkProjects = projects.map((projectInfo) => {
370
- const lastCommit = getLastCommit();
371
- console.log(`last commit ${lastCommit}`);
372
378
  let checkPromise = checkProjectChanges(projectInfo, lastCommit);
373
379
  let changedPromise = checkPromise.then(hasChanged => {
374
380
  projectInfo.hasChanged = hasChanged;
@@ -394,10 +400,30 @@ function publish(commitUrl, updateVersionType) {
394
400
  return workspace;
395
401
  }, monoWorkspace);
396
402
  const updatedVersions = monoWorkspace.updateResult;
397
- commitVersionChanges(updatedVersions, commitUrl);
398
- updateMonoWorkspaceVersion(monoWorkspace, updateVersionType);
399
- pushCommits(commitUrl);
400
- return Promise.resolve(monoWorkspace);
403
+ if (updatedVersions) {
404
+ return commitVersionChanges(updatedVersions, commitUrl)
405
+ .then((result) => {
406
+ if (result.stderr) {
407
+ console.log(result.stderr);
408
+ }
409
+ if (result.stdout) {
410
+ console.log(result.stdout);
411
+ }
412
+ return updateMonoWorkspaceVersion(monoWorkspace, updateVersionType, commitUrl);
413
+ })
414
+ .then((result) => {
415
+ if (result.stderr) {
416
+ console.log(result.stderr);
417
+ }
418
+ if (result.stdout) {
419
+ console.log(result.stdout);
420
+ }
421
+ return Promise.resolve(monoWorkspace);
422
+ });
423
+ } else {
424
+ return Promise.resolve(monoWorkspace);
425
+ }
426
+
401
427
  });
402
428
  });
403
429
  // 5. 编译所有Angular工作区
@@ -405,20 +431,38 @@ function publish(commitUrl, updateVersionType) {
405
431
  const buildPromises = monoWorkspace.workspaces
406
432
  .filter(workspace => workspace.hasChanged)
407
433
  .map((workspace) => buildWorkspace(workspace));
408
- return Promise.all(buildPromises)
409
- .then((results) => {
410
- console.log(results.stdout);
411
- return Promise.resolve(monoWorkspace);
412
- });
434
+ if (buildPromises.length) {
435
+ return Promise.all(buildPromises)
436
+ .then((results) => {
437
+ if (results) {
438
+ results.map((result) => {
439
+ if (result.stderr) {
440
+ console.log(result.stderr);
441
+ }
442
+ if (result.stdout) {
443
+ console.log(result.stdout);
444
+ }
445
+ });
446
+ }
447
+ return Promise.resolve(monoWorkspace);
448
+ });
449
+ } else {
450
+ return Promise.resolve(monoWorkspace);
451
+ }
413
452
  });
414
453
  // 6. 将变更项目的内容发布为npm包,并增加发布Tag标签
415
454
  chain = chain.then(monoWorkspace => {
416
455
  const changedProjects = monoWorkspace.changedProjects;
417
- const publishPromises = changedProjects.map(projectInfo => publishToNpmRepository(projectInfo.project.path));
418
- Promise.all(publishPromises)
419
- .then(() => {
420
- return addTagToMonoWorkspace(monoWorkspace, commitUrl);
421
- });
456
+ if (changedProjects.length) {
457
+ const publishPromises = changedProjects.map(projectInfo => publishToNpmRepository(projectInfo.project.path));
458
+ Promise.all(publishPromises)
459
+ .then(() => {
460
+ return addTagToMonoWorkspace(monoWorkspace, commitUrl);
461
+ });
462
+ } else {
463
+ return Promise.resolve(monoWorkspace);
464
+ }
465
+
422
466
  });
423
467
  }
424
468
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farris/cli",
3
- "version": "1.0.23",
3
+ "version": "1.0.26",
4
4
  "description": "Farris command line interface",
5
5
  "main": "index.js",
6
6
  "scripts": {