@farris/cli 1.0.17 → 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.
- package/ci/cli.js +67 -21
- 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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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(
|
@@ -135,10 +166,25 @@ function checkProjectChanges(projectPath) {
|
|
135
166
|
* @param {string} projectPath 目标工程路径
|
136
167
|
* @returns 更新后的版本
|
137
168
|
*/
|
138
|
-
function
|
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
|
+
}
|
139
185
|
return childProcess
|
140
186
|
// 使用 npm version prerelease 更新指定工程的预发布版本
|
141
|
-
.exec('npm',
|
187
|
+
.exec('npm', npmCommandArray)
|
142
188
|
.then((returnValue) => {
|
143
189
|
// 读取目标工程的package.json文件
|
144
190
|
const packageJsonFilePath = `${projectPath}/package.json`;
|
@@ -212,17 +258,17 @@ function tagMonoWorkspace(monoWorkspace, commitUrl) {
|
|
212
258
|
* @param {string} projectPath 目标工程路径
|
213
259
|
* @returns 发布结果
|
214
260
|
*/
|
215
|
-
function publish(projectPath) {
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
}
|
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
|
+
// }
|
224
270
|
|
225
|
-
function
|
271
|
+
function publish(commitUrl, updateVersionType) {
|
226
272
|
const monoRepoProject = new Project(process.cwd());
|
227
273
|
let chain = Promise.resolve();
|
228
274
|
chain = chain.then(() => {
|
@@ -267,7 +313,7 @@ function publishAll(commitUrl) {
|
|
267
313
|
});
|
268
314
|
chain = chain.then(monoWorkspace => {
|
269
315
|
const changedProjects = monoWorkspace.changedProjects;
|
270
|
-
const prereleasePromise = changedProjects.map(projectInfo =>
|
316
|
+
const prereleasePromise = changedProjects.map(projectInfo => updateProjectVersion(projectInfo.project.path, updateVersionType));
|
271
317
|
return Promise.all(prereleasePromise)
|
272
318
|
.then((results) => {
|
273
319
|
results.reduce((workspace, updateResult) => {
|