-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathbuild.ts
102 lines (86 loc) · 3.12 KB
/
build.ts
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
98
99
100
101
102
import * as path from 'path';
import { bold, cyan, dim, green, red } from 'colorette';
import { Command, CommandLineInputs, CommandLineOptions, CommandMetadata } from '@ionic/cli-framework';
import { remove } from '@ionic/utils-fs';
import { getCommandHeader, runcmd } from '../utils';
import {
BUILD_DIRECTORY,
REPO_DIRECTORY,
buildStarter,
buildStarters,
gatherChangedBaseFiles,
getStarterInfoFromPath,
} from '../lib/build';
export class BuildCommand extends Command {
async getMetadata(): Promise<CommandMetadata> {
return {
name: 'build',
summary: 'Builds all the starters',
inputs: [
{
name: 'starter',
summary: 'Path to single starter to build',
},
],
options: [
{
name: 'current',
summary: 'Use base files as-is, do not checkout base files using baseref',
type: Boolean,
},
{
name: 'wipe',
summary: 'Do not wipe build directory',
type: Boolean,
default: true,
},
],
};
}
async run(inputs: CommandLineInputs, options: CommandLineOptions) {
const [starter] = inputs;
const current = options['current'] ? true : false;
const wipe = options['wipe'] ? true : false;
const gitVersion = (await runcmd('git', ['--version'])).trim();
console.log(getCommandHeader('BUILD'));
console.log(`\n${gitVersion}\n`);
if (wipe) {
console.log(`Wiping ${bold(`${BUILD_DIRECTORY}/*`)}`);
await remove(`${BUILD_DIRECTORY}/*`);
}
const changedBaseFiles = await gatherChangedBaseFiles();
if (!current && changedBaseFiles.length > 0) {
console.error(
red(
`Changes detected in ${changedBaseFiles.map((p) => bold(p)).join(', ')}.\n` +
`You must either commit/reset these changes OR explicitly use the ${green(
'--current'
)} flag, which ignores starter baserefs.`
)
);
process.exit(1);
}
if (starter) {
const starterDir = path.resolve(starter);
if (!starterDir.startsWith(REPO_DIRECTORY)) {
throw new Error(red('Starter not in this repo.'));
}
const [ionicType, starterType] = getStarterInfoFromPath(starterDir);
await buildStarter(ionicType, starterType, starterDir);
} else {
const currentSha1 = (await runcmd('git', ['rev-parse', 'HEAD'])).trim();
const starterList = await buildStarters({ current, sha1: currentSha1 });
const mismatchedStarters = starterList.starters.filter((s) => s.sha1 !== currentSha1);
if (mismatchedStarters.length > 0) {
const currentRef = (await runcmd('git', ['log', '-1', '--format="%D"', currentSha1])).trim();
console.log(
`The following starters were built from a ref other than ${bold(currentRef ? currentRef : currentSha1)}:\n` +
` - ${mismatchedStarters.map((s) => `${cyan(s.id)} ${dim(`(${s.ref})`)}`).join('\n - ')}\n` +
`If this isn't what you want, consider running with the ${green(
'--current'
)} flag, which ignores starter baserefs.`
);
}
}
}
}