@farris/cli 1.0.12 → 1.0.16
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 +16 -52
- 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
|
-
|
84
|
+
log.silly("getLastTagInBranch");
|
85
85
|
return childProcess.execSync("git", ["describe", "--tags", "--abbrev=0"]);
|
86
86
|
}
|
87
|
-
|
87
|
+
log.silly("getFirstCommit");
|
88
88
|
return childProcess.execSync("git", ["rev-list", "--max-parents=0", "HEAD"]);
|
89
89
|
}
|
90
90
|
|
@@ -161,29 +161,16 @@ function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
|
|
161
161
|
return latestMessage = latestMessage + message;
|
162
162
|
}, `${prefix} `)
|
163
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}`;
|
177
164
|
}
|
178
165
|
|
179
166
|
function commitChanges(updatedVersions, commitUrl) {
|
180
|
-
const commitMessage = builderVersionChangeMessage('Update', updatedVersions, '.');
|
167
|
+
const commitMessage = builderVersionChangeMessage('Update', updatedVersions, '. [skip ci]');
|
181
168
|
|
182
169
|
if (commitMessage) {
|
183
170
|
// 向git缓冲区中添加变更
|
184
171
|
childProcess.execSync('git', ['add', '.']);
|
185
172
|
// // 提交变更记录
|
186
|
-
childProcess.execSync('git', ['commit', '-m', `${commitMessage}
|
173
|
+
childProcess.execSync('git', ['commit', '-m', `${commitMessage}`]);
|
187
174
|
|
188
175
|
console.log(commitMessage);
|
189
176
|
|
@@ -191,9 +178,9 @@ function commitChanges(updatedVersions, commitUrl) {
|
|
191
178
|
console.log(`executing git push ${branch}`);
|
192
179
|
// 提交变更集
|
193
180
|
if (commitUrl) {
|
194
|
-
return childProcess.exec("git", ["push",
|
181
|
+
return childProcess.exec("git", ["push", commitUrl]);
|
195
182
|
} else {
|
196
|
-
return childProcess.exec('git', ['push'
|
183
|
+
return childProcess.exec('git', ['push']);
|
197
184
|
}
|
198
185
|
}
|
199
186
|
}
|
@@ -205,18 +192,17 @@ function buildWorkspace(workspace) {
|
|
205
192
|
}
|
206
193
|
|
207
194
|
function tagMonoWorkspace(monoWorkspace, commitUrl) {
|
208
|
-
const tagMessage = builderVersionChangeMessage('Publish npm packages ', monoWorkspace.updateResult, '.');
|
195
|
+
// const tagMessage = builderVersionChangeMessage('Publish npm packages ', monoWorkspace.updateResult, '.');
|
209
196
|
const date = moment(new Date());
|
210
|
-
const tagVersion = `v${date.format('
|
211
|
-
|
212
|
-
childProcess.execSync('git', ['tag', tagVersion, '-m', tagMessage]);
|
197
|
+
const tagVersion = `v${date.format('YYYYMMDDHHmmss')}`;
|
198
|
+
childProcess.execSync('git', ['tag', tagVersion, '-m', 'Publish npm packages. [skip ci]']);
|
213
199
|
// 提交变更集
|
214
200
|
if (commitUrl) {
|
215
|
-
console.log(`git push
|
216
|
-
return childProcess.exec("git", ["push", '
|
201
|
+
console.log(`git push --tags ${commitUrl}`);
|
202
|
+
return childProcess.exec("git", ["push", '--tags', commitUrl]);
|
217
203
|
} else {
|
218
|
-
console.log(`git push
|
219
|
-
return childProcess.exec('git', ['push', '
|
204
|
+
console.log(`git push --tags`);
|
205
|
+
return childProcess.exec('git', ['push', '--tags',]);
|
220
206
|
}
|
221
207
|
}
|
222
208
|
|
@@ -232,55 +218,36 @@ function publish(projectPath) {
|
|
232
218
|
const dest = ngPackageConfig.dest;
|
233
219
|
const packagePath = path.normalize(`${projectPath}/${dest}`);
|
234
220
|
// 调用 npm publish 发布指定路径下的npm包
|
235
|
-
console.log(`npm publish ${packagePath}`);
|
236
221
|
return childProcess.exec('npm', ['publish', packagePath])
|
237
222
|
}
|
238
223
|
|
239
|
-
/**
|
240
|
-
* 将所有变更发布为新的npm包
|
241
|
-
* @param {string} commitUrl commit api 地址
|
242
|
-
*/
|
243
224
|
function publishAll(commitUrl) {
|
244
|
-
// 初始化当前工作目录下的多代码仓库项目
|
245
225
|
const monoRepoProject = new Project(process.cwd());
|
246
226
|
let chain = Promise.resolve();
|
247
|
-
// 1. 提取当前多代码仓库中的所有子项目,创建多项目工作区
|
248
227
|
chain = chain.then(() => {
|
249
|
-
// 提取所有子项目
|
250
228
|
return monoRepoProject.getPackages()
|
251
229
|
.then(packages => {
|
252
|
-
// 创建并返回多项目工作区
|
253
230
|
const monoWorkspace = { packages };
|
254
231
|
return monoWorkspace;
|
255
232
|
})
|
256
233
|
});
|
257
|
-
// 2. 读取多项目工作区下的Angular工作区和所有Angular项目
|
258
234
|
chain = chain.then((monoWorkspace) => {
|
259
|
-
// 提取所有子仓库项目
|
260
235
|
const packages = monoWorkspace.packages;
|
261
|
-
// 初始化Angular工作区集合
|
262
236
|
monoWorkspace.workspaces = [];
|
263
|
-
// 初始化Angular工程集合
|
264
237
|
monoWorkspace.projects = [];
|
265
|
-
// 遍历所有子仓库
|
266
238
|
packages.forEach(packageJson => {
|
267
|
-
// 读取Angular工作区路径
|
268
239
|
const workspacePath = packageJson.location;
|
269
|
-
// 读取Angular工作区下的angular.json文件内容
|
270
240
|
const angularJson = readAngularJson(workspacePath)
|
271
|
-
// 构造Angular工作区
|
272
241
|
const workspace = readWorkspace(angularJson, packageJson);
|
273
|
-
// 记录Angular工作区对象
|
274
242
|
monoWorkspace.workspaces.push(workspace);
|
275
|
-
// 遍历Angular工作区下的Angular项目,归集到根工作区中
|
276
243
|
workspace.projects.reduce((monoWorkspace, projectInfo) => {
|
277
244
|
monoWorkspace.projects.push(projectInfo);
|
278
245
|
return monoWorkspace;
|
279
246
|
}, monoWorkspace);
|
247
|
+
// .forEach((projectInfo) => monoWorkspace.projects.push(projectInfo));
|
280
248
|
});
|
281
249
|
return monoWorkspace;
|
282
250
|
});
|
283
|
-
// 3. 检查代码提交记录,获取自上次发布以来所有发生变化的Angular工程
|
284
251
|
chain = chain.then(monoWorkspace => {
|
285
252
|
const projects = monoWorkspace.projects;
|
286
253
|
const checkProjects = projects.map((projectInfo) => {
|
@@ -292,12 +259,11 @@ function publishAll(commitUrl) {
|
|
292
259
|
return changedPromise;
|
293
260
|
});
|
294
261
|
return Promise.all(checkProjects)
|
295
|
-
.then(
|
296
|
-
monoWorkspace.changedProjects =
|
262
|
+
.then((checkResults) => {
|
263
|
+
monoWorkspace.changedProjects = checkResults.filter((projectInfo) => projectInfo.hasChanged);
|
297
264
|
return Promise.resolve(monoWorkspace);
|
298
265
|
});
|
299
266
|
});
|
300
|
-
// 4. 更新所有变更项目预发布版本,提交代码仓库,供发布时使用
|
301
267
|
chain = chain.then(monoWorkspace => {
|
302
268
|
const changedProjects = monoWorkspace.changedProjects;
|
303
269
|
const prereleasePromise = changedProjects.map(projectInfo => updateProjectPrereleaseVersion(projectInfo.project.path, monoWorkspace));
|
@@ -313,7 +279,6 @@ function publishAll(commitUrl) {
|
|
313
279
|
return Promise.resolve(monoWorkspace);
|
314
280
|
});
|
315
281
|
});
|
316
|
-
// 5. 编译所有Angular工作区
|
317
282
|
chain = chain.then(monoWorkspace => {
|
318
283
|
const buildPromises = monoWorkspace.workspaces.map((workspace) => buildWorkspace(workspace));
|
319
284
|
return Promise.all(buildPromises)
|
@@ -321,7 +286,6 @@ function publishAll(commitUrl) {
|
|
321
286
|
return Promise.resolve(monoWorkspace);
|
322
287
|
});
|
323
288
|
});
|
324
|
-
// 6. 将变更项目的内容发布为npm包,并增加发布Tag标签
|
325
289
|
chain = chain.then(monoWorkspace => {
|
326
290
|
const changedProjects = monoWorkspace.changedProjects;
|
327
291
|
const publishPromises = changedProjects.map(projectInfo => publish(projectInfo.project.path));
|