-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate-version.ts
More file actions
97 lines (89 loc) · 3.05 KB
/
generate-version.ts
File metadata and controls
97 lines (89 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { execSync, ExecSyncOptions } from "child_process";
import * as rimraf from "rimraf";
const runCommands = true;
const projectName = "the-project";
const applicationName = "the-application";
const libraryName = "the-library";
const version = process.argv[2];
const majorVersion = version.split(".")[0];
const minorVersion = version.split(".")[1];
const flags = new Set(process.argv.slice(3));
const branch = version + Array.from(flags).sort().join("");
// args available in `new`, `generate application`, and `generate library`. (Note that in the docs you have to check both "generate" and "application"/"library".)
const commonArgs = `${flags.has("-karma") ? "--test-runner=karma" : ""} --skip-install --interactive=false`;
const commonAppArgs = `${commonArgs} ${flags.has("-route") ? "--routing=true" : ""} --zoneless=${!flags.has("-zone")} --style=scss`;
run(`git checkout -b ${branch}`, {});
rimraf.sync(projectName);
runAndCommit(`npm install --save-dev @angular/cli@${version}`, {});
runAndCommit(
`npx ng new ${projectName} --create-application=${!flags.has(
"-noApp"
)} ${commonAppArgs}`,
{}
);
if (flags.has("-eslint")) {
runAndCommit(
`npx ng add angular-eslint --interactive=false --skip-confirmation=true`
);
runAndCommit(
`npx ng config "schematics.angular-eslint:application.setParserOptionsProject" true`
);
runAndCommit(
`npx ng config "schematics.angular-eslint:library.setParserOptionsProject" true`
);
}
if (flags.has("-subApp")) {
runAndCommit(
`npx ng generate application ${applicationName} ${commonAppArgs}`
);
}
if (flags.has("-lib")) {
runAndCommit(
`npx ng generate library ${libraryName} ${commonArgs}`
);
}
if (flags.has("-mat")) {
runAndCommit(
`npx ng add @angular/material@${majorVersion}.${minorVersion} ${flags.has("-noApp") ? `--project=${applicationName}` : ""} --theme=custom --interactive=false --skip-confirmation=true`
);
}
if (flags.has("-pwa")) {
runAndCommit(
"npx ng add @angular/pwa --interactive=false --skip-confirmation=true"
);
}
if (flags.has("-worker")) {
runAndCommit(`npx ng generate web-worker app`);
}
if (flags.has("-fire")) {
// steps from https://firebase.google.com/docs/hosting/quickstart
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
console.error(
"Firebase hosting must be added manually. Run this, and commit:"
);
console.log("cd the-project");
console.log("firebase init hosting");
console.log("git add .");
console.log("cd ..");
console.log(`git commit -m "firebase init hosting"`);
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
} else {
rimraf.sync(`${projectName}/node_modules`);
}
function runAndCommit(
command: string,
options: ExecSyncOptions = { cwd: projectName }
) {
run(command, options);
if (runCommands) {
execSync("git add .");
execSync(`git commit -m "${command}"`);
}
}
function run(command: string, options: ExecSyncOptions = { cwd: projectName }) {
console.log("\n--------------------------------------------");
console.log(command);
if (runCommands) {
execSync(command, options);
}
}