@farris/cli 1.0.20 → 1.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/ci/cli.js +23 -18
  2. package/package.json +1 -1
package/ci/cli.js CHANGED
@@ -156,8 +156,8 @@ function hasTags() {
156
156
  * @returns 检查结果
157
157
  */
158
158
  function checkProjectChanges(projectInfo, lastCommit) {
159
- const projectPath = projectInfo?.project?.path;
160
- const packageName = projectInfo?.package?.name || projectPath;
159
+ const projectPath = projectInfo.project.path;
160
+ const packageName = projectInfo.package.name || projectPath;
161
161
  return childProcess
162
162
  // 使用 git diff 命令查询自上传提交以来,目标工程路径下是否有变更的文件
163
163
  .exec("git", ["diff", "--name-only", lastCommit, projectPath])
@@ -234,10 +234,15 @@ function updateMonoWorkspaceVersion(monoWorkspace, updateVersionType) {
234
234
  npmCommandArray = ['version', 'major'];
235
235
  break;
236
236
  }
237
+ console.log(`executing npm version --${updateVersionType} in root directory.`)
237
238
  childProcess.execSync('npm', npmCommandArray);
238
239
  const packageJsonFilePath = `./package.json`;
239
240
  const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
240
- console.log(`update MonoWorkspace version to v${packageConfig.version}`);
241
+ // 向git缓冲区中添加变更
242
+ childProcess.execSync('git', ['add', '.']);
243
+ // // 提交变更记录
244
+ childProcess.execSync('git', ['commit', '-m', `Update MonoWorkspace version to v${packageConfig.version}`]);
245
+ console.log(`Update MonoWorkspace version to v${packageConfig.version}`);
241
246
  monoWorkspace.version = packageConfig.version;
242
247
  }
243
248
 
@@ -253,7 +258,7 @@ function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
253
258
  return `${versionMessage} ${suffix}`;
254
259
  }
255
260
 
256
- function commitChanges(updatedVersions, commitUrl) {
261
+ function commitVersionChanges(updatedVersions) {
257
262
  const commitMessage = builderVersionChangeMessage('Update', updatedVersions, '. [skip ci]');
258
263
 
259
264
  if (commitMessage) {
@@ -263,15 +268,17 @@ function commitChanges(updatedVersions, commitUrl) {
263
268
  childProcess.execSync('git', ['commit', '-m', `${commitMessage}`]);
264
269
 
265
270
  console.log(commitMessage);
271
+ }
272
+ }
266
273
 
267
- const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
268
- console.log(`executing git push ${branch}`);
269
- // 提交变更集
270
- if (commitUrl) {
271
- return childProcess.exec("git", ["push", commitUrl]);
272
- } else {
273
- return childProcess.exec('git', ['push']);
274
- }
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']);
275
282
  }
276
283
  }
277
284
 
@@ -361,7 +368,7 @@ function publish(commitUrl, updateVersionType) {
361
368
  const projects = monoWorkspace.projects;
362
369
  const checkProjects = projects.map((projectInfo) => {
363
370
  const lastCommit = getLastCommit();
364
- console.log(`last commit ${lastCommit}`); Í
371
+ console.log(`last commit ${lastCommit}`);
365
372
  let checkPromise = checkProjectChanges(projectInfo, lastCommit);
366
373
  let changedPromise = checkPromise.then(hasChanged => {
367
374
  projectInfo.hasChanged = hasChanged;
@@ -379,9 +386,6 @@ function publish(commitUrl, updateVersionType) {
379
386
  chain = chain.then(monoWorkspace => {
380
387
  const changedProjects = monoWorkspace.changedProjects;
381
388
  const prereleasePromise = changedProjects.map(projectInfo => updateProjectVersion(projectInfo, updateVersionType));
382
- if (changedProjects) {
383
-
384
- }
385
389
  return Promise.all(prereleasePromise)
386
390
  .then((results) => {
387
391
  results.reduce((workspace, updateResult) => {
@@ -389,9 +393,10 @@ function publish(commitUrl, updateVersionType) {
389
393
  Object.assign(workspace.updateResult, updateResult);
390
394
  return workspace;
391
395
  }, monoWorkspace);
392
- updateMonoWorkspaceVersion(monoWorkspace, updateVersionType);
393
396
  const updatedVersions = monoWorkspace.updateResult;
394
- commitChanges(updatedVersions, commitUrl);
397
+ commitVersionChanges(updatedVersions, commitUrl);
398
+ updateMonoWorkspaceVersion(monoWorkspace, updateVersionType);
399
+ pushCommits(commitUrl);
395
400
  return Promise.resolve(monoWorkspace);
396
401
  });
397
402
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farris/cli",
3
- "version": "1.0.20",
3
+ "version": "1.0.23",
4
4
  "description": "Farris command line interface",
5
5
  "main": "index.js",
6
6
  "scripts": {