@farris/cli 1.0.10 → 1.0.13
Sign up to get free protection for your applications and to get access to all the features.
- package/ci/cli.js +38 -24
- package/package.json +1 -1
package/ci/cli.js
CHANGED
@@ -134,8 +134,7 @@ function checkProjectChanges(projectPath) {
|
|
134
134
|
* @param {string} projectPath 目标工程路径
|
135
135
|
* @returns 更新后的版本
|
136
136
|
*/
|
137
|
-
function updateProjectPrereleaseVersion(projectPath
|
138
|
-
monoWorkspace.updateResult = monoWorkspace.updateResult || {};
|
137
|
+
function updateProjectPrereleaseVersion(projectPath) {
|
139
138
|
return childProcess
|
140
139
|
// 使用 npm version prerelease 更新指定工程的预发布版本
|
141
140
|
.exec('npm', ['version', 'prerelease', '--preid=beta', '--prefix', projectPath])
|
@@ -146,25 +145,35 @@ function updateProjectPrereleaseVersion(projectPath, monoWorkspace) {
|
|
146
145
|
// 提取更新后的版本
|
147
146
|
const updatedVersion = returnValue.stdout;
|
148
147
|
console.log(`update ${packageConfig.name} prerelease version to ${updatedVersion}`);
|
149
|
-
|
150
|
-
|
148
|
+
const updateResult = {};
|
149
|
+
updateResult[packageConfig.name] = updatedVersion;
|
150
|
+
return updateResult;
|
151
151
|
})
|
152
152
|
}
|
153
153
|
|
154
154
|
function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
|
155
|
-
const versionMessage = updatedVersions.reduce((latestMessage,
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
if (index <= originalArray.length - 2) {
|
161
|
-
message = message + ', ';
|
162
|
-
}
|
163
|
-
latestMessage = latestMessage + message;
|
155
|
+
const versionMessage = Object.keys(updatedVersions).reduce((latestMessage, packageName, index, originalArray) => {
|
156
|
+
const version = updatedVersions[packageName];
|
157
|
+
let message = `${packageName} to ${version}`;
|
158
|
+
if (index <= originalArray.length - 2) {
|
159
|
+
message = message + ', ';
|
164
160
|
}
|
165
|
-
return latestMessage;
|
166
|
-
}, `${prefix} `)
|
167
|
-
return `${versionMessage} ${suffix}
|
161
|
+
return latestMessage = latestMessage + message;
|
162
|
+
}, `${prefix} `)
|
163
|
+
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}`;
|
168
177
|
}
|
169
178
|
|
170
179
|
function commitChanges(updatedVersions, commitUrl) {
|
@@ -190,21 +199,21 @@ function commitChanges(updatedVersions, commitUrl) {
|
|
190
199
|
}
|
191
200
|
|
192
201
|
function buildWorkspace(workspace) {
|
202
|
+
console.log(`executing lerna run build --scope=${workspace.packageName}`)
|
193
203
|
return childProcess.exec('lerna', ['run', 'build', `--scope=${workspace.packageName}`]);
|
194
204
|
// lerna run build --scope=@farris/ide-framework
|
195
205
|
}
|
196
206
|
|
197
207
|
function tagMonoWorkspace(monoWorkspace, commitUrl) {
|
198
|
-
const tagMessage = builderVersionChangeMessage('Publish npm packages ', monoWorkspace.updateResult, '.');
|
199
|
-
/*from www.w3cschool.cn*/
|
208
|
+
// const tagMessage = builderVersionChangeMessage('Publish npm packages ', monoWorkspace.updateResult, '.');
|
200
209
|
const date = moment(new Date());
|
201
|
-
const tagVersion = `v${date.format('
|
202
|
-
childProcess.execSync('git', ['tag', tagVersion, '-m',
|
210
|
+
const tagVersion = `v${date.format('YYYMMDDHHmmss')}`;
|
211
|
+
childProcess.execSync('git', ['tag', tagVersion, '-m', "publish npm package"]);
|
203
212
|
// 提交变更集
|
204
213
|
if (commitUrl) {
|
205
|
-
return childProcess.exec("git", ["push", '-o', 'ci.skip', commitUrl]);
|
214
|
+
return childProcess.exec("git", ["push", '--tags', '-o', 'ci.skip', commitUrl]);
|
206
215
|
} else {
|
207
|
-
return childProcess.exec('git', ['push', '-o', 'ci.skip']);
|
216
|
+
return childProcess.exec('git', ['push', '--tags', '-o', 'ci.skip']);
|
208
217
|
}
|
209
218
|
}
|
210
219
|
|
@@ -270,7 +279,12 @@ function publishAll(commitUrl) {
|
|
270
279
|
const changedProjects = monoWorkspace.changedProjects;
|
271
280
|
const prereleasePromise = changedProjects.map(projectInfo => updateProjectPrereleaseVersion(projectInfo.project.path, monoWorkspace));
|
272
281
|
return Promise.all(prereleasePromise)
|
273
|
-
.then((
|
282
|
+
.then((results) => {
|
283
|
+
results.reduce((workspace, updateResult) => {
|
284
|
+
workspace.updateResult = workspace.updateResult || {};
|
285
|
+
Object.assign(workspace.updateResult, updateResult);
|
286
|
+
return workspace;
|
287
|
+
}, monoWorkspace);
|
274
288
|
const updatedVersions = monoWorkspace.updateResult;
|
275
289
|
commitChanges(updatedVersions, commitUrl);
|
276
290
|
return Promise.resolve(monoWorkspace);
|
@@ -279,7 +293,7 @@ function publishAll(commitUrl) {
|
|
279
293
|
chain = chain.then(monoWorkspace => {
|
280
294
|
const buildPromises = monoWorkspace.workspaces.map((workspace) => buildWorkspace(workspace));
|
281
295
|
return Promise.all(buildPromises)
|
282
|
-
.then(() => {
|
296
|
+
.then((results) => {
|
283
297
|
return Promise.resolve(monoWorkspace);
|
284
298
|
});
|
285
299
|
});
|