@farris/cli 1.0.11 → 1.0.12

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 +28 -3
  2. package/package.json +1 -1
package/ci/cli.js CHANGED
@@ -81,10 +81,10 @@ cli
81
81
  */
82
82
  function getLastCommit() {
83
83
  if (hasTags()) {
84
- log.silly("getLastTagInBranch");
84
+ console.log("getLastTagInBranch");
85
85
  return childProcess.execSync("git", ["describe", "--tags", "--abbrev=0"]);
86
86
  }
87
- log.silly("getFirstCommit");
87
+ console.log("getFirstCommit");
88
88
  return childProcess.execSync("git", ["rev-list", "--max-parents=0", "HEAD"]);
89
89
  }
90
90
 
@@ -208,11 +208,14 @@ function tagMonoWorkspace(monoWorkspace, commitUrl) {
208
208
  const tagMessage = builderVersionChangeMessage('Publish npm packages ', monoWorkspace.updateResult, '.');
209
209
  const date = moment(new Date());
210
210
  const tagVersion = `v${date.format('yyyyMMddhhmmss')}`;
211
+ console.log(`git tag ${tagVersion} -m ${tagMessage}`);
211
212
  childProcess.execSync('git', ['tag', tagVersion, '-m', tagMessage]);
212
213
  // 提交变更集
213
214
  if (commitUrl) {
215
+ console.log(`git push -o ci.skip ${commitUrl}`);
214
216
  return childProcess.exec("git", ["push", '-o', 'ci.skip', commitUrl]);
215
217
  } else {
218
+ console.log(`git push -o ci.skip`);
216
219
  return childProcess.exec('git', ['push', '-o', 'ci.skip']);
217
220
  }
218
221
  }
@@ -229,36 +232,55 @@ function publish(projectPath) {
229
232
  const dest = ngPackageConfig.dest;
230
233
  const packagePath = path.normalize(`${projectPath}/${dest}`);
231
234
  // 调用 npm publish 发布指定路径下的npm包
235
+ console.log(`npm publish ${packagePath}`);
232
236
  return childProcess.exec('npm', ['publish', packagePath])
233
237
  }
234
238
 
239
+ /**
240
+ * 将所有变更发布为新的npm包
241
+ * @param {string} commitUrl commit api 地址
242
+ */
235
243
  function publishAll(commitUrl) {
244
+ // 初始化当前工作目录下的多代码仓库项目
236
245
  const monoRepoProject = new Project(process.cwd());
237
246
  let chain = Promise.resolve();
247
+ // 1. 提取当前多代码仓库中的所有子项目,创建多项目工作区
238
248
  chain = chain.then(() => {
249
+ // 提取所有子项目
239
250
  return monoRepoProject.getPackages()
240
251
  .then(packages => {
252
+ // 创建并返回多项目工作区
241
253
  const monoWorkspace = { packages };
242
254
  return monoWorkspace;
243
255
  })
244
256
  });
257
+ // 2. 读取多项目工作区下的Angular工作区和所有Angular项目
245
258
  chain = chain.then((monoWorkspace) => {
259
+ // 提取所有子仓库项目
246
260
  const packages = monoWorkspace.packages;
261
+ // 初始化Angular工作区集合
247
262
  monoWorkspace.workspaces = [];
263
+ // 初始化Angular工程集合
248
264
  monoWorkspace.projects = [];
265
+ // 遍历所有子仓库
249
266
  packages.forEach(packageJson => {
267
+ // 读取Angular工作区路径
250
268
  const workspacePath = packageJson.location;
269
+ // 读取Angular工作区下的angular.json文件内容
251
270
  const angularJson = readAngularJson(workspacePath)
271
+ // 构造Angular工作区
252
272
  const workspace = readWorkspace(angularJson, packageJson);
273
+ // 记录Angular工作区对象
253
274
  monoWorkspace.workspaces.push(workspace);
275
+ // 遍历Angular工作区下的Angular项目,归集到根工作区中
254
276
  workspace.projects.reduce((monoWorkspace, projectInfo) => {
255
277
  monoWorkspace.projects.push(projectInfo);
256
278
  return monoWorkspace;
257
279
  }, monoWorkspace);
258
- // .forEach((projectInfo) => monoWorkspace.projects.push(projectInfo));
259
280
  });
260
281
  return monoWorkspace;
261
282
  });
283
+ // 3. 检查代码提交记录,获取自上次发布以来所有发生变化的Angular工程
262
284
  chain = chain.then(monoWorkspace => {
263
285
  const projects = monoWorkspace.projects;
264
286
  const checkProjects = projects.map((projectInfo) => {
@@ -275,6 +297,7 @@ function publishAll(commitUrl) {
275
297
  return Promise.resolve(monoWorkspace);
276
298
  });
277
299
  });
300
+ // 4. 更新所有变更项目预发布版本,提交代码仓库,供发布时使用
278
301
  chain = chain.then(monoWorkspace => {
279
302
  const changedProjects = monoWorkspace.changedProjects;
280
303
  const prereleasePromise = changedProjects.map(projectInfo => updateProjectPrereleaseVersion(projectInfo.project.path, monoWorkspace));
@@ -290,6 +313,7 @@ function publishAll(commitUrl) {
290
313
  return Promise.resolve(monoWorkspace);
291
314
  });
292
315
  });
316
+ // 5. 编译所有Angular工作区
293
317
  chain = chain.then(monoWorkspace => {
294
318
  const buildPromises = monoWorkspace.workspaces.map((workspace) => buildWorkspace(workspace));
295
319
  return Promise.all(buildPromises)
@@ -297,6 +321,7 @@ function publishAll(commitUrl) {
297
321
  return Promise.resolve(monoWorkspace);
298
322
  });
299
323
  });
324
+ // 6. 将变更项目的内容发布为npm包,并增加发布Tag标签
300
325
  chain = chain.then(monoWorkspace => {
301
326
  const changedProjects = monoWorkspace.changedProjects;
302
327
  const publishPromises = changedProjects.map(projectInfo => publish(projectInfo.project.path));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farris/cli",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Farris command line interface",
5
5
  "main": "index.js",
6
6
  "scripts": {