@farris/cli 1.0.27 → 2.0.0-beta.7
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/index.js +2 -0
- package/lib/commands/build-components.js +36 -0
- package/lib/commands/build-css.js +11 -0
- package/lib/commands/build-lib.js +16 -0
- package/lib/commands/build.js +10 -0
- package/lib/commands/create-app.js +54 -0
- package/lib/commands/dev-serve.js +23 -0
- package/lib/commands/preview-serve.js +16 -0
- package/lib/common/constant.js +18 -0
- package/lib/common/generate-app.js +44 -0
- package/lib/common/get-dependencies.js +9 -0
- package/lib/common/get-farris-config.js +11 -0
- package/lib/common/get-version.js +6 -0
- package/lib/common/get-vite-config.js +38 -0
- package/lib/config/vite-app.js +14 -0
- package/lib/config/vite-lib.js +35 -0
- package/lib/index.js +54 -0
- package/lib/plugins/dts.js +8 -0
- package/lib/plugins/gen-component-style.js +43 -0
- package/lib/plugins/html-system.js +11 -0
- package/lib/plugins/replace.js +13 -0
- package/package.json +30 -18
- package/templates/lib/.eslintrc.cjs +15 -0
- package/templates/lib/.prettierrc.json +8 -0
- package/templates/lib/farris.config.mjs +35 -0
- package/templates/lib/index.html +12 -0
- package/templates/lib/package.json +29 -0
- package/templates/lib/packages/button/src/index.vue +4 -0
- package/templates/lib/packages/index.ts +7 -0
- package/templates/lib/src/App.vue +5 -0
- package/templates/lib/src/main.ts +9 -0
- package/templates/lib/tsconfig.json +18 -0
- package/templates/mobile/.eslintrc.cjs +15 -0
- package/templates/mobile/.prettierrc.json +8 -0
- package/templates/mobile/farris.config.mjs +24 -0
- package/templates/mobile/index.html +12 -0
- package/templates/mobile/package.json +29 -0
- package/templates/mobile/src/App.vue +80 -0
- package/templates/mobile/src/components/TheButton.vue +3 -0
- package/templates/mobile/src/main.ts +12 -0
- package/templates/mobile/src/router/index.ts +23 -0
- package/templates/mobile/src/views/AboutView.vue +15 -0
- package/templates/mobile/src/views/HomeView.vue +9 -0
- package/templates/mobile/tsconfig.json +18 -0
- package/README.md +0 -2
- package/ci/cli.js +0 -542
package/ci/cli.js
DELETED
@@ -1,542 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
'use strict';
|
4
|
-
|
5
|
-
const fs = require('fs');
|
6
|
-
const path = require('path');
|
7
|
-
const log = require("npmlog");
|
8
|
-
const moment = require("moment");
|
9
|
-
const childProcess = require("@lerna/child-process");
|
10
|
-
const { Project } = require("@lerna/project");
|
11
|
-
|
12
|
-
|
13
|
-
const yargs = require('yargs/yargs');
|
14
|
-
const cli = yargs(process.argv.slice(2), process.cwd())
|
15
|
-
|
16
|
-
cli
|
17
|
-
.command(
|
18
|
-
'check',
|
19
|
-
'check file changes from last commit.',
|
20
|
-
(yargs) => {
|
21
|
-
return yargs;
|
22
|
-
},
|
23
|
-
(argv) => {
|
24
|
-
const projectPath = argv.project;
|
25
|
-
const lastCommit = getLastCommit();
|
26
|
-
console.log(`last commit ${lastCommit}`);
|
27
|
-
checkProjectChanges(projectPath, latestMessage);
|
28
|
-
}
|
29
|
-
)
|
30
|
-
.command(
|
31
|
-
'prerelease',
|
32
|
-
'Update package prerelease version when package has changed.',
|
33
|
-
(yargs) => {
|
34
|
-
return yargs;
|
35
|
-
},
|
36
|
-
(argv) => {
|
37
|
-
// 读取预发布工程路径
|
38
|
-
const project = argv.project;
|
39
|
-
// 读取commit url地址
|
40
|
-
const url = argv.url;
|
41
|
-
// 读取是否预发布全部工程
|
42
|
-
const prereleaseAll = argv.all;
|
43
|
-
if (prereleaseAll) {
|
44
|
-
console.log('Prerelease all.');
|
45
|
-
// 发布所有变更的项目
|
46
|
-
return publish(url, 'prerelease');
|
47
|
-
} else if (project) {
|
48
|
-
let chain = Promise.resolve();
|
49
|
-
const lastCommit = getLastCommit();
|
50
|
-
console.log(`last commit ${lastCommit}`);
|
51
|
-
chain = chain.then(() => checkProjectChanges(project, lastCommit));
|
52
|
-
chain = chain.then((hasChanged) => {
|
53
|
-
const projectInfo = { 'project': { 'path': project } };
|
54
|
-
if (hasChanged) {
|
55
|
-
return updateProjectVersion(projectInfo, 'prerelease')
|
56
|
-
}
|
57
|
-
});
|
58
|
-
} else {
|
59
|
-
console.log('You must provide param of either --all or --project.')
|
60
|
-
}
|
61
|
-
}
|
62
|
-
)
|
63
|
-
.command(
|
64
|
-
'patch',
|
65
|
-
'Update package patch version when package has changed.',
|
66
|
-
(yargs) => {
|
67
|
-
return yargs;
|
68
|
-
},
|
69
|
-
(argv) => {
|
70
|
-
const project = argv.project;
|
71
|
-
const url = argv.url;
|
72
|
-
const patchAll = argv.all;
|
73
|
-
if (patchAll) {
|
74
|
-
return publish(url, 'patch');
|
75
|
-
} else if (project) {
|
76
|
-
let chain = Promise.resolve();
|
77
|
-
const lastCommit = getLastCommit();
|
78
|
-
console.log(`last commit ${lastCommit}`);
|
79
|
-
chain = chain.then(() => checkProjectChanges(project, lastCommit));
|
80
|
-
chain = chain.then((hasChanged) => {
|
81
|
-
if (hasChanged) {
|
82
|
-
const projectInfo = { 'project': { 'path': project } };
|
83
|
-
return updateProjectVersion(projectInfo, 'patch')
|
84
|
-
}
|
85
|
-
});
|
86
|
-
} else {
|
87
|
-
console.log('You must provide param of either --all or --project.')
|
88
|
-
}
|
89
|
-
}
|
90
|
-
)
|
91
|
-
.command(
|
92
|
-
'publish',
|
93
|
-
'Publish package which has changed sence last commit.',
|
94
|
-
(yargs) => {
|
95
|
-
return yargs;
|
96
|
-
},
|
97
|
-
(argv) => {
|
98
|
-
const project = argv.project;
|
99
|
-
let chain = Promise.resolve();
|
100
|
-
const lastCommit = getLastCommit();
|
101
|
-
console.log(`last commit ${lastCommit}`);
|
102
|
-
chain = chain.then(() => checkProjectChanges(project, lastCommit));
|
103
|
-
chain = chain.then((hasChanged) => {
|
104
|
-
if (hasChanged) {
|
105
|
-
return publish(project)
|
106
|
-
}
|
107
|
-
});
|
108
|
-
}
|
109
|
-
)
|
110
|
-
.command(
|
111
|
-
'publishAll',
|
112
|
-
'Publish all packages that have changed sence latst publish.',
|
113
|
-
(yargs) => {
|
114
|
-
return yargs;
|
115
|
-
},
|
116
|
-
(argv) => {
|
117
|
-
const projectPath = argv.project;
|
118
|
-
const url = argv.url;
|
119
|
-
publishAll(url);
|
120
|
-
}
|
121
|
-
)
|
122
|
-
.argv;
|
123
|
-
|
124
|
-
/**
|
125
|
-
* @param {import("@lerna/child-process").ExecOpts} execOpts
|
126
|
-
*/
|
127
|
-
function getLastCommit() {
|
128
|
-
if (hasTags()) {
|
129
|
-
console.log("getLastTagInBranch");
|
130
|
-
return childProcess.execSync("git", ["describe", "--tags", "--abbrev=0"]);
|
131
|
-
}
|
132
|
-
console.log("getFirstCommit");
|
133
|
-
return childProcess.execSync("git", ["rev-list", "--max-parents=0", "HEAD"]);
|
134
|
-
}
|
135
|
-
|
136
|
-
/**
|
137
|
-
* @param {import("@lerna/child-process").ExecOpts} opts
|
138
|
-
*/
|
139
|
-
function hasTags() {
|
140
|
-
let result = false;
|
141
|
-
try {
|
142
|
-
result = !!childProcess.execSync("git", ["tag"]);
|
143
|
-
} catch (err) {
|
144
|
-
log.warn("ENOTAGS", "No git tags were reachable from this branch!");
|
145
|
-
log.verbose("hasTags error", err);
|
146
|
-
}
|
147
|
-
log.verbose("hasTags", result);
|
148
|
-
return result;
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
|
-
/**
|
153
|
-
* 检查指定工程目录下是否存在变更文件
|
154
|
-
* @param {string} projectInfo 目标工程信息
|
155
|
-
* @param {string} lastCommit 最后提交标识
|
156
|
-
* @returns 检查结果
|
157
|
-
*/
|
158
|
-
function checkProjectChanges(projectInfo, lastCommit) {
|
159
|
-
const projectPath = projectInfo.project.path;
|
160
|
-
const packageName = projectInfo.package.name || projectPath;
|
161
|
-
return childProcess
|
162
|
-
// 使用 git diff 命令查询自上传提交以来,目标工程路径下是否有变更的文件
|
163
|
-
.exec("git", ["diff", "--name-only", lastCommit, projectPath])
|
164
|
-
.then((returnValue) => {
|
165
|
-
// 提取命令输出结果中的文件集合ß
|
166
|
-
const changedFiles = returnValue.stdout.split("\n").filter(Boolean);
|
167
|
-
// 根据文件个数确定是否存在变更
|
168
|
-
const hasChanges = changedFiles.length > 0;
|
169
|
-
if (hasChanges) {
|
170
|
-
projectInfo.workspace.hasChanged = hasChanges;
|
171
|
-
console.log(`${packageName} has changed since latest tag ${lastCommit}.`)
|
172
|
-
} else {
|
173
|
-
console.log(`${packageName} has not changed.`)
|
174
|
-
}
|
175
|
-
// 返回检测结果
|
176
|
-
return hasChanges;
|
177
|
-
});
|
178
|
-
}
|
179
|
-
|
180
|
-
/**
|
181
|
-
* 更新指定工程的预发布版本
|
182
|
-
* @param {string} projectInfo 目标工程信息
|
183
|
-
* @returns 更新后的版本
|
184
|
-
*/
|
185
|
-
function updateProjectVersion(projectInfo, updateVersionType) {
|
186
|
-
let npmCommandArray = [];
|
187
|
-
const projectPath = projectInfo.project.path;
|
188
|
-
if (!projectPath) {
|
189
|
-
throw new Error(`update project version error: you must provide project path by project info object.`)
|
190
|
-
}
|
191
|
-
switch (updateVersionType) {
|
192
|
-
case 'prerelease':
|
193
|
-
npmCommandArray = ['version', 'prerelease', '--preid=beta', '--prefix', projectPath];
|
194
|
-
break;
|
195
|
-
case 'patch':
|
196
|
-
npmCommandArray = ['version', 'patch', '--prefix', projectPath];
|
197
|
-
break;
|
198
|
-
case 'minor':
|
199
|
-
npmCommandArray = ['version', 'minor', '--prefix', projectPath];
|
200
|
-
break;
|
201
|
-
case 'major':
|
202
|
-
npmCommandArray = ['version', 'major', '--prefix', projectPath];
|
203
|
-
break;
|
204
|
-
}
|
205
|
-
return childProcess
|
206
|
-
// 使用 npm version prerelease 更新指定工程的预发布版本
|
207
|
-
.exec('npm', npmCommandArray)
|
208
|
-
.then((returnValue) => {
|
209
|
-
// 读取目标工程的package.json文件
|
210
|
-
const packageJsonFilePath = `${projectPath}/package.json`;
|
211
|
-
const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
|
212
|
-
// 提取更新后的版本
|
213
|
-
const updatedVersion = returnValue.stdout;
|
214
|
-
console.log(`update ${packageConfig.name} prerelease version to ${updatedVersion}`);
|
215
|
-
const updateResult = {};
|
216
|
-
updateResult[packageConfig.name] = updatedVersion;
|
217
|
-
return updateResult;
|
218
|
-
})
|
219
|
-
}
|
220
|
-
|
221
|
-
function updateMonoWorkspaceVersion(monoWorkspace, updateVersionType, commitUrl) {
|
222
|
-
let npmCommandArray = [];
|
223
|
-
switch (updateVersionType) {
|
224
|
-
case 'prerelease':
|
225
|
-
npmCommandArray = ['version', 'prerelease', '--preid=beta'];
|
226
|
-
break;
|
227
|
-
case 'patch':
|
228
|
-
npmCommandArray = ['version', 'patch'];
|
229
|
-
break;
|
230
|
-
case 'minor':
|
231
|
-
npmCommandArray = ['version', 'minor'];
|
232
|
-
break;
|
233
|
-
case 'major':
|
234
|
-
npmCommandArray = ['version', 'major'];
|
235
|
-
break;
|
236
|
-
}
|
237
|
-
console.log(`executing npm version --${updateVersionType} in root directory.`)
|
238
|
-
childProcess.execSync('npm', npmCommandArray);
|
239
|
-
const packageJsonFilePath = `./package.json`;
|
240
|
-
const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
|
241
|
-
monoWorkspace.version = packageConfig.version;
|
242
|
-
// 向git缓冲区中添加变更
|
243
|
-
childProcess.execSync('git', ['add', '.']);
|
244
|
-
// 提交变更记录
|
245
|
-
childProcess.execSync('git', ['commit', '-m', `Update MonoWorkspace version to v${packageConfig.version}. [skip ci]`]);
|
246
|
-
console.log(`Update MonoWorkspace version to v${packageConfig.version}`);
|
247
|
-
const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
|
248
|
-
// 提交变更集
|
249
|
-
if (commitUrl) {
|
250
|
-
console.log(`executing git push ${branch} to ${commitUrl}`);
|
251
|
-
return childProcess.exec("git", ["push", commitUrl]);
|
252
|
-
} else {
|
253
|
-
console.log(`executing git push ${branch}`);
|
254
|
-
return childProcess.exec('git', ['push']);
|
255
|
-
}
|
256
|
-
}
|
257
|
-
|
258
|
-
function builderVersionChangeMessage(prefix, updatedVersions, suffix = '') {
|
259
|
-
const versionMessage = Object.keys(updatedVersions).reduce((latestMessage, packageName, index, originalArray) => {
|
260
|
-
const version = updatedVersions[packageName];
|
261
|
-
let message = `${packageName} to ${version}`;
|
262
|
-
if (index <= originalArray.length - 2) {
|
263
|
-
message = message + ', ';
|
264
|
-
}
|
265
|
-
return latestMessage = latestMessage + message;
|
266
|
-
}, `${prefix} `)
|
267
|
-
return `${versionMessage} ${suffix}`;
|
268
|
-
}
|
269
|
-
|
270
|
-
function commitVersionChanges(updatedVersions, commitUrl, monoWorkspace, updateVersionType) {
|
271
|
-
const commitMessage = builderVersionChangeMessage('update', updatedVersions, '');
|
272
|
-
if (commitMessage) {
|
273
|
-
const updateWorkspaceVersion = ['version', '--force', '--no-git-tag-version', updateVersionType];
|
274
|
-
if (updateVersionType === 'prerelease') {
|
275
|
-
updateWorkspaceVersion.push('--preid=beta');
|
276
|
-
}
|
277
|
-
// switch (updateVersionType) {
|
278
|
-
// case 'prerelease':
|
279
|
-
// updateWorkspaceVersion = ['version', 'prerelease', '--preid=beta', '--force', '--no-git-tag-version'];
|
280
|
-
// break;
|
281
|
-
// case 'patch':
|
282
|
-
// updateWorkspaceVersion = ['version', 'patch', '--force', '--no-git-tag-version'];
|
283
|
-
// break;
|
284
|
-
// case 'minor':
|
285
|
-
// updateWorkspaceVersion = ['version', 'minor', '--force', '--no-git-tag-version'];
|
286
|
-
// break;
|
287
|
-
// case 'major':
|
288
|
-
// updateWorkspaceVersion = ['version', 'major', '--force', '--no-git-tag-version'];
|
289
|
-
// break;
|
290
|
-
// }
|
291
|
-
console.log(`executing npm ${updateWorkspaceVersion.join(' ')} in root directory.`)
|
292
|
-
childProcess.execSync('npm', updateWorkspaceVersion);
|
293
|
-
|
294
|
-
const packageJsonFilePath = `./package.json`;
|
295
|
-
const packageConfig = JSON.parse(fs.readFileSync(packageJsonFilePath, 'utf-8'));
|
296
|
-
monoWorkspace.version = packageConfig.version;
|
297
|
-
|
298
|
-
// 向git缓冲区中添加变更
|
299
|
-
childProcess.execSync('git', ['add', '.']);
|
300
|
-
// 提交变更记录
|
301
|
-
childProcess.execSync('git', ['commit', '-m', `Update workspace version to v${packageConfig.version} for ${commitMessage}. [skip ci]`]);
|
302
|
-
|
303
|
-
// // 向git缓冲区中添加变更
|
304
|
-
// childProcess.execSync('git', ['add', '.']);
|
305
|
-
// // // 提交变更记录
|
306
|
-
// childProcess.execSync('git', ['commit', '-m', `${commitMessage}`]);
|
307
|
-
const branch = childProcess.execSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
|
308
|
-
// 提交变更集
|
309
|
-
if (commitUrl) {
|
310
|
-
console.log(`executing git push ${branch} to ${commitUrl}`);
|
311
|
-
return childProcess.exec("git", ["push", commitUrl]);
|
312
|
-
} else {
|
313
|
-
console.log(`executing git push ${branch}`);
|
314
|
-
return childProcess.exec('git', ['push']);
|
315
|
-
}
|
316
|
-
}
|
317
|
-
}
|
318
|
-
|
319
|
-
function buildWorkspace(workspace) {
|
320
|
-
console.log(`executing lerna run build --scope=${workspace.packageName}`)
|
321
|
-
return childProcess.exec('lerna', ['run', 'build', `--scope=${workspace.packageName}`]);
|
322
|
-
}
|
323
|
-
|
324
|
-
function addTagToMonoWorkspace(monoWorkspace, commitUrl) {
|
325
|
-
const monoWorkspaceVersion = monoWorkspace.version;
|
326
|
-
childProcess.execSync('git', ['tag', monoWorkspaceVersion, '-m', 'Publish npm packages. [skip ci]']);
|
327
|
-
// 提交变更集
|
328
|
-
if (commitUrl) {
|
329
|
-
console.log(`git push --tags ${commitUrl}`);
|
330
|
-
return childProcess.exec("git", ["push", '--tags', commitUrl]);
|
331
|
-
} else {
|
332
|
-
console.log(`git push --tags`);
|
333
|
-
return childProcess.exec('git', ['push', '--tags',]);
|
334
|
-
}
|
335
|
-
}
|
336
|
-
|
337
|
-
/**
|
338
|
-
* 发布指定路径下的npm包
|
339
|
-
* @param {string} projectPath 目标工程路径
|
340
|
-
* @returns 发布结果
|
341
|
-
*/
|
342
|
-
function publishToNpmRepository(projectPath) {
|
343
|
-
// 读取目标工程的package.json文件
|
344
|
-
const ngPackageJsonFilePath = `${projectPath}/ng-package.json`;
|
345
|
-
const ngPackageConfig = JSON.parse(fs.readFileSync(ngPackageJsonFilePath, 'utf-8'));
|
346
|
-
const dest = ngPackageConfig.dest;
|
347
|
-
const packagePath = path.normalize(`${projectPath}/${dest}`);
|
348
|
-
// 调用 npm publish 发布指定路径下的npm包
|
349
|
-
return childProcess.exec('npm', ['publish', packagePath])
|
350
|
-
}
|
351
|
-
|
352
|
-
/**
|
353
|
-
* 将所有变更发布为新的npm包
|
354
|
-
* @param {string} commitUrl commit api 地址
|
355
|
-
*/
|
356
|
-
function publish(commitUrl, updateVersionType) {
|
357
|
-
// 初始化当前工作目录下的多代码仓库项目
|
358
|
-
const monoRepoProject = new Project(process.cwd());
|
359
|
-
let chain = Promise.resolve();
|
360
|
-
// 1. 提取当前多代码仓库中的所有子项目,创建多项目工作区
|
361
|
-
chain = chain.then(() => {
|
362
|
-
// 提取所有子项目
|
363
|
-
return monoRepoProject.getPackages()
|
364
|
-
.then(packages => {
|
365
|
-
// 创建并返回多项目工作区
|
366
|
-
const monoWorkspace = { packages };
|
367
|
-
return monoWorkspace;
|
368
|
-
})
|
369
|
-
});
|
370
|
-
// 2. 读取多项目工作区下的Angular工作区和所有Angular项目
|
371
|
-
chain = chain.then((monoWorkspace) => {
|
372
|
-
// 提取所有子仓库项目
|
373
|
-
const packages = monoWorkspace.packages;
|
374
|
-
// 初始化Angular工作区集合
|
375
|
-
monoWorkspace.workspaces = [];
|
376
|
-
// 初始化Angular工程集合
|
377
|
-
monoWorkspace.projects = [];
|
378
|
-
// 遍历所有子仓库
|
379
|
-
packages.forEach(packageJson => {
|
380
|
-
// 读取Angular工作区路径
|
381
|
-
const workspacePath = packageJson.location;
|
382
|
-
// 读取Angular工作区下的angular.json文件内容
|
383
|
-
const angularJson = readAngularJson(workspacePath)
|
384
|
-
// 构造Angular工作区
|
385
|
-
const workspace = readWorkspace(angularJson, packageJson);
|
386
|
-
// 记录Angular工作区对象
|
387
|
-
monoWorkspace.workspaces.push(workspace);
|
388
|
-
// 遍历Angular工作区下的Angular项目,归集到根工作区中
|
389
|
-
workspace.projects.reduce((monoWorkspace, projectInfo) => {
|
390
|
-
monoWorkspace.projects.push(projectInfo);
|
391
|
-
return monoWorkspace;
|
392
|
-
}, monoWorkspace);
|
393
|
-
});
|
394
|
-
return monoWorkspace;
|
395
|
-
});
|
396
|
-
// 3. 检查代码提交记录,获取自上次发布以来所有发生变化的Angular工程
|
397
|
-
chain = chain.then(monoWorkspace => {
|
398
|
-
const projects = monoWorkspace.projects;
|
399
|
-
const lastCommit = getLastCommit();
|
400
|
-
console.log(`last commit ${lastCommit}`);
|
401
|
-
const checkProjects = projects.map((projectInfo) => {
|
402
|
-
let checkPromise = checkProjectChanges(projectInfo, lastCommit);
|
403
|
-
let changedPromise = checkPromise.then(hasChanged => {
|
404
|
-
projectInfo.hasChanged = hasChanged;
|
405
|
-
return Promise.resolve(projectInfo);
|
406
|
-
});
|
407
|
-
return changedPromise;
|
408
|
-
});
|
409
|
-
return Promise.all(checkProjects)
|
410
|
-
.then((checkResults) => {
|
411
|
-
monoWorkspace.changedProjects = checkResults.filter((projectInfo) => projectInfo.hasChanged);
|
412
|
-
return Promise.resolve(monoWorkspace);
|
413
|
-
});
|
414
|
-
});
|
415
|
-
// 4. 更新所有变更项目预发布版本,提交代码仓库,供发布时使用
|
416
|
-
chain = chain.then(monoWorkspace => {
|
417
|
-
const changedProjects = monoWorkspace.changedProjects;
|
418
|
-
const prereleasePromise = changedProjects.map(projectInfo => updateProjectVersion(projectInfo, updateVersionType));
|
419
|
-
return Promise.all(prereleasePromise)
|
420
|
-
.then((results) => {
|
421
|
-
results.reduce((workspace, updateResult) => {
|
422
|
-
workspace.updateResult = workspace.updateResult || {};
|
423
|
-
Object.assign(workspace.updateResult, updateResult);
|
424
|
-
return workspace;
|
425
|
-
}, monoWorkspace);
|
426
|
-
const updatedVersions = monoWorkspace.updateResult;
|
427
|
-
if (updatedVersions) {
|
428
|
-
return commitVersionChanges(updatedVersions, commitUrl, monoWorkspace, updateVersionType)
|
429
|
-
// .then((result) => {
|
430
|
-
// if (result.stderr) {
|
431
|
-
// console.log(result.stderr);
|
432
|
-
// }
|
433
|
-
// if (result.stdout) {
|
434
|
-
// console.log(result.stdout);
|
435
|
-
// }
|
436
|
-
// return updateMonoWorkspaceVersion(monoWorkspace, updateVersionType, commitUrl);
|
437
|
-
// })
|
438
|
-
.then((result) => {
|
439
|
-
if (result.stderr) {
|
440
|
-
console.log(result.stderr);
|
441
|
-
}
|
442
|
-
if (result.stdout) {
|
443
|
-
console.log(result.stdout);
|
444
|
-
}
|
445
|
-
return Promise.resolve(monoWorkspace);
|
446
|
-
});
|
447
|
-
} else {
|
448
|
-
return Promise.resolve(monoWorkspace);
|
449
|
-
}
|
450
|
-
|
451
|
-
});
|
452
|
-
});
|
453
|
-
// 5. 编译所有Angular工作区
|
454
|
-
chain = chain.then(monoWorkspace => {
|
455
|
-
const buildPromises = monoWorkspace.workspaces
|
456
|
-
.filter(workspace => workspace.hasChanged)
|
457
|
-
.map((workspace) => buildWorkspace(workspace));
|
458
|
-
if (buildPromises.length) {
|
459
|
-
return Promise.all(buildPromises)
|
460
|
-
.then((results) => {
|
461
|
-
if (results) {
|
462
|
-
results.map((result) => {
|
463
|
-
if (result.stderr) {
|
464
|
-
console.log(result.stderr);
|
465
|
-
}
|
466
|
-
if (result.stdout) {
|
467
|
-
console.log(result.stdout);
|
468
|
-
}
|
469
|
-
});
|
470
|
-
}
|
471
|
-
return Promise.resolve(monoWorkspace);
|
472
|
-
});
|
473
|
-
} else {
|
474
|
-
return Promise.resolve(monoWorkspace);
|
475
|
-
}
|
476
|
-
});
|
477
|
-
// 6. 将变更项目的内容发布为npm包,并增加发布Tag标签
|
478
|
-
chain = chain.then(monoWorkspace => {
|
479
|
-
const changedProjects = monoWorkspace.changedProjects;
|
480
|
-
if (changedProjects.length) {
|
481
|
-
const publishPromises = changedProjects.map(projectInfo => publishToNpmRepository(projectInfo.project.path));
|
482
|
-
Promise.all(publishPromises)
|
483
|
-
.then(() => {
|
484
|
-
return addTagToMonoWorkspace(monoWorkspace, commitUrl);
|
485
|
-
});
|
486
|
-
} else {
|
487
|
-
return Promise.resolve(monoWorkspace);
|
488
|
-
}
|
489
|
-
|
490
|
-
});
|
491
|
-
}
|
492
|
-
|
493
|
-
function readAngularJson(workspacePath) {
|
494
|
-
const angularJsonPath = path.normalize(`${workspacePath}/angular.json`);
|
495
|
-
return JSON.parse(fs.readFileSync(angularJsonPath, 'utf-8'));
|
496
|
-
}
|
497
|
-
|
498
|
-
function readWorkspace(angularJson, packageJson) {
|
499
|
-
const projects = angularJson.projects;
|
500
|
-
const workspacePath = packageJson.location;
|
501
|
-
const packageName = packageJson.name;
|
502
|
-
const workspace = {
|
503
|
-
packageName,
|
504
|
-
path: workspacePath,
|
505
|
-
projects: [],
|
506
|
-
hasChanged: false
|
507
|
-
};
|
508
|
-
Object.keys(projects)
|
509
|
-
.reduce((workspace, projectName) => {
|
510
|
-
const projectInfo = readProjectInfo(projectName, projects[projectName], workspace);
|
511
|
-
if (projectInfo) {
|
512
|
-
workspace.projects.push(projectInfo);
|
513
|
-
}
|
514
|
-
return workspace;
|
515
|
-
}, workspace);
|
516
|
-
return workspace;
|
517
|
-
}
|
518
|
-
|
519
|
-
function readProjectInfo(projectName, project, workspace) {
|
520
|
-
const projectPath = path.normalize(`${workspace.path}/${project.root}`);
|
521
|
-
const projectType = project.projectType;
|
522
|
-
if (projectType === 'library') {
|
523
|
-
const packageJsonPath = path.normalize(`${projectPath}/package.json`);
|
524
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
525
|
-
const packageName = packageJson.name;
|
526
|
-
const ngPackagePath = path.normalize(`${projectPath}/ng-package.json`);
|
527
|
-
const ngPackage = JSON.parse(fs.readFileSync(ngPackagePath, 'utf-8'));
|
528
|
-
const packagePath = path.normalize(`${projectPath}/${ngPackage.dest}`);
|
529
|
-
return {
|
530
|
-
workspace,
|
531
|
-
project: {
|
532
|
-
name: projectName,
|
533
|
-
path: projectPath,
|
534
|
-
type: projectType
|
535
|
-
},
|
536
|
-
package: {
|
537
|
-
name: packageName,
|
538
|
-
path: packagePath
|
539
|
-
}
|
540
|
-
}
|
541
|
-
}
|
542
|
-
}
|