@farris/cli 1.0.15 → 1.0.18

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 +78 -44
  2. package/package.json +1 -1
package/ci/cli.js CHANGED
@@ -34,14 +34,45 @@ cli
34
34
  (argv) => {
35
35
  const project = argv.project;
36
36
  const url = argv.url;
37
- let chain = Promise.resolve();
38
-
39
- chain = chain.then(() => checkProjectChanges(project));
40
- chain = chain.then((hasChanged) => {
41
- if (hasChanged) {
42
- return updateProjectPrereleaseVersion(project, url)
43
- }
44
- });
37
+ const prereleaseAll = argv.all;
38
+ if (prereleaseAll) {
39
+ return publish(url, 'prerelease');
40
+ } else if (project) {
41
+ let chain = Promise.resolve();
42
+ chain = chain.then(() => checkProjectChanges(project));
43
+ chain = chain.then((hasChanged) => {
44
+ if (hasChanged) {
45
+ return updateProjectVersion(project, 'prerelease')
46
+ }
47
+ });
48
+ }else{
49
+ console.log('You must provide param of either --all or --project.')
50
+ }
51
+ }
52
+ )
53
+ .command(
54
+ 'patch',
55
+ 'Update package patch version when package has changed.',
56
+ (yargs) => {
57
+ return yargs;
58
+ },
59
+ (argv) => {
60
+ const project = argv.project;
61
+ const url = argv.url;
62
+ const patchAll = argv.all;
63
+ if (patchAll) {
64
+ return publish(url, 'patch');
65
+ } else if (project) {
66
+ let chain = Promise.resolve();
67
+ chain = chain.then(() => checkProjectChanges(project));
68
+ chain = chain.then((hasChanged) => {
69
+ if (hasChanged) {
70
+ return updateProjectVersion(project, 'patch')
71
+ }
72
+ });
73
+ }else{
74
+ console.log('You must provide param of either --all or --project.')
75
+ }
45
76
  }
46
77
  )
47
78
  .command(
@@ -81,10 +112,10 @@ cli
81
112
  */
82
113
  function getLastCommit() {
83
114
  if (hasTags()) {
84
- log.silly("getLastTagInBranch");
115
+ console.log("getLastTagInBranch");
85
116
  return childProcess.execSync("git", ["describe", "--tags", "--abbrev=0"]);
86
117
  }
87
- log.silly("getFirstCommit");
118
+ console.log("getFirstCommit");
88
119
  return childProcess.execSync("git", ["rev-list", "--max-parents=0", "HEAD"]);
89
120
  }
90
121
 
@@ -111,6 +142,7 @@ function hasTags() {
111
142
  */
112
143
  function checkProjectChanges(projectPath) {
113
144
  const lastCommit = getLastCommit();
145
+ console.log(`last commit ${lastCommit}`);
114
146
  return childProcess
115
147
  // 使用 git diff 命令查询自上传提交以来,目标工程路径下是否有变更的文件
116
148
  .exec("git", ["diff", "--name-only", lastCommit, projectPath])
@@ -134,10 +166,25 @@ function checkProjectChanges(projectPath) {
134
166
  * @param {string} projectPath 目标工程路径
135
167
  * @returns 更新后的版本
136
168
  */
137
- function updateProjectPrereleaseVersion(projectPath) {
169
+ function updateProjectVersion(projectPath, updateVersionType) {
170
+ let npmCommandArray = [];
171
+ switch (updateVersionType) {
172
+ case 'prerelease':
173
+ npmCommandArray = ['version', 'prerelease', '--preid=beta', '--prefix', projectPath];
174
+ break;
175
+ case 'patch':
176
+ npmCommandArray = ['version', 'patch', '--prefix', projectPath];
177
+ break;
178
+ case 'minor':
179
+ npmCommandArray = ['version', 'minor', '--prefix', projectPath];
180
+ break;
181
+ case 'major':
182
+ npmCommandArray = ['version', 'major', '--prefix', projectPath];
183
+ break;
184
+ }
138
185
  return childProcess
139
186
  // 使用 npm version prerelease 更新指定工程的预发布版本
140
- .exec('npm', ['version', 'prerelease', '--preid=beta', '--prefix', projectPath])
187
+ .exec('npm', npmCommandArray)
141
188
  .then((returnValue) => {
142
189
  // 读取目标工程的package.json文件
143
190
  const packageJsonFilePath = `${projectPath}/package.json`;
@@ -161,23 +208,10 @@ function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
161
208
  return latestMessage = latestMessage + message;
162
209
  }, `${prefix} `)
163
210
  return `${versionMessage} ${suffix}`;
164
- // const versionMessage = updatedVersions.reduce((latestMessage, updateVersion, index, originalArray) => {
165
- // if (Object.keys(updateVersion).length) {
166
- // const packageName = Object.keys(updateVersion)[0];
167
- // const version = updateVersion[packageName];
168
- // let message = `${packageName} to ${version}`;
169
- // if (index <= originalArray.length - 2) {
170
- // message = message + ', ';
171
- // }
172
- // latestMessage = latestMessage + message;
173
- // }
174
- // return latestMessage;
175
- // }, `${prefix} `);
176
- // return `${versionMessage} ${suffix}`;
177
211
  }
178
212
 
179
213
  function commitChanges(updatedVersions, commitUrl) {
180
- const commitMessage = builderVersionChangeMessage('Update', updatedVersions, '.');
214
+ const commitMessage = builderVersionChangeMessage('Update', updatedVersions, '. [skip ci]');
181
215
 
182
216
  if (commitMessage) {
183
217
  // 向git缓冲区中添加变更
@@ -191,9 +225,9 @@ function commitChanges(updatedVersions, commitUrl) {
191
225
  console.log(`executing git push ${branch}`);
192
226
  // 提交变更集
193
227
  if (commitUrl) {
194
- return childProcess.exec("git", ["push", '-o', 'ci.skip', commitUrl]);
228
+ return childProcess.exec("git", ["push", commitUrl]);
195
229
  } else {
196
- return childProcess.exec('git', ['push', '-o', 'ci.skip']);
230
+ return childProcess.exec('git', ['push']);
197
231
  }
198
232
  }
199
233
  }
@@ -208,14 +242,14 @@ function tagMonoWorkspace(monoWorkspace, commitUrl) {
208
242
  // const tagMessage = builderVersionChangeMessage('Publish npm packages ', monoWorkspace.updateResult, '.');
209
243
  const date = moment(new Date());
210
244
  const tagVersion = `v${date.format('YYYYMMDDHHmmss')}`;
211
- childProcess.execSync('git', ['tag', tagVersion, '-m', 'Publish npm packages']);
245
+ childProcess.execSync('git', ['tag', tagVersion, '-m', 'Publish npm packages. [skip ci]']);
212
246
  // 提交变更集
213
247
  if (commitUrl) {
214
- console.log(`git push --tags -o ci.skip ${commitUrl}`);
215
- return childProcess.exec("git", ["push", '--tags', '-o', 'ci.skip', commitUrl]);
248
+ console.log(`git push --tags ${commitUrl}`);
249
+ return childProcess.exec("git", ["push", '--tags', commitUrl]);
216
250
  } else {
217
- console.log(`git push --tags -o ci.skip`);
218
- return childProcess.exec('git', ['push', '--tags', '-o', 'ci.skip']);
251
+ console.log(`git push --tags`);
252
+ return childProcess.exec('git', ['push', '--tags',]);
219
253
  }
220
254
  }
221
255
 
@@ -224,17 +258,17 @@ function tagMonoWorkspace(monoWorkspace, commitUrl) {
224
258
  * @param {string} projectPath 目标工程路径
225
259
  * @returns 发布结果
226
260
  */
227
- function publish(projectPath) {
228
- // 读取目标工程的package.json文件
229
- const ngPackageJsonFilePath = `${projectPath}/ng-package.json`;
230
- const ngPackageConfig = JSON.parse(fs.readFileSync(ngPackageJsonFilePath, 'utf-8'));
231
- const dest = ngPackageConfig.dest;
232
- const packagePath = path.normalize(`${projectPath}/${dest}`);
233
- // 调用 npm publish 发布指定路径下的npm包
234
- return childProcess.exec('npm', ['publish', packagePath])
235
- }
261
+ // function publish(projectPath) {
262
+ // // 读取目标工程的package.json文件
263
+ // const ngPackageJsonFilePath = `${projectPath}/ng-package.json`;
264
+ // const ngPackageConfig = JSON.parse(fs.readFileSync(ngPackageJsonFilePath, 'utf-8'));
265
+ // const dest = ngPackageConfig.dest;
266
+ // const packagePath = path.normalize(`${projectPath}/${dest}`);
267
+ // // 调用 npm publish 发布指定路径下的npm包
268
+ // return childProcess.exec('npm', ['publish', packagePath])
269
+ // }
236
270
 
237
- function publishAll(commitUrl) {
271
+ function publish(commitUrl, updateVersionType) {
238
272
  const monoRepoProject = new Project(process.cwd());
239
273
  let chain = Promise.resolve();
240
274
  chain = chain.then(() => {
@@ -279,7 +313,7 @@ function publishAll(commitUrl) {
279
313
  });
280
314
  chain = chain.then(monoWorkspace => {
281
315
  const changedProjects = monoWorkspace.changedProjects;
282
- const prereleasePromise = changedProjects.map(projectInfo => updateProjectPrereleaseVersion(projectInfo.project.path, monoWorkspace));
316
+ const prereleasePromise = changedProjects.map(projectInfo => updateProjectVersion(projectInfo.project.path, updateVersionType));
283
317
  return Promise.all(prereleasePromise)
284
318
  .then((results) => {
285
319
  results.reduce((workspace, updateResult) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farris/cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.18",
4
4
  "description": "Farris command line interface",
5
5
  "main": "index.js",
6
6
  "scripts": {