/
options.ts
186 lines (162 loc) · 5.42 KB
/
options.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { join } from 'path';
import { getVermoji } from './vermoji';
import { PackageData } from './write-pkg-json';
import { readJSONSync, writeJSONSync } from 'fs-extra';
export function getOptions(rootDir: string, inputOpts: BuildOptions = {}) {
const srcDir = join(rootDir, 'src');
const packageJsonPath = join(rootDir, 'package.json');
const packageLockJsonPath = join(rootDir, 'package-lock.json');
const changelogPath = join(rootDir, 'CHANGELOG.md');
const nodeModulesDir = join(rootDir, 'node_modules');
const typescriptDir = join(nodeModulesDir, 'typescript');
const typescriptLibDir = join(typescriptDir, 'lib');
const buildDir = join(rootDir, 'build');
const scriptsDir = join(rootDir, 'scripts');
const scriptsBundlesDir = join(scriptsDir, 'bundles');
const bundleHelpersDir = join(scriptsBundlesDir, 'helpers');
const opts: BuildOptions = {
ghRepoOrg: 'ionic-team',
ghRepoName: 'stencil',
rootDir,
srcDir,
packageJsonPath,
packageLockJsonPath,
changelogPath,
nodeModulesDir,
typescriptDir,
typescriptLibDir,
buildDir,
scriptsDir,
scriptsBundlesDir,
bundleHelpersDir,
output: {
cliDir: join(rootDir, 'cli'),
compilerDir: join(rootDir, 'compiler'),
devServerDir: join(rootDir, 'dev-server'),
internalDir: join(rootDir, 'internal'),
mockDocDir: join(rootDir, 'mock-doc'),
screenshotDir: join(rootDir, 'screenshot'),
sysDenoDir: join(rootDir, 'sys', 'deno'),
sysNodeDir: join(rootDir, 'sys', 'node'),
testingDir: join(rootDir, 'testing'),
},
packageJson: readJSONSync(packageJsonPath),
version: null,
buildId: null,
isProd: false,
isCI: false,
isPublishRelease: false,
vermoji: null,
tag: 'dev',
};
Object.assign(opts, inputOpts);
if (!opts.buildId) {
opts.buildId = getBuildId();
}
if (!opts.version) {
opts.version = '0.0.0-dev.' + opts.buildId;
}
if (opts.isPublishRelease) {
if (!opts.isProd) {
throw new Error('release must also be a prod build');
}
}
if (!opts.vermoji) {
if (opts.isProd) {
opts.vermoji = getVermoji(opts.changelogPath);
} else {
opts.vermoji = '💎';
}
}
return opts;
}
export function createReplaceData(opts: BuildOptions) {
const CACHE_BUSTER = 6;
const typescriptPkg = require(join(opts.typescriptDir, 'package.json'));
opts.typescriptVersion = typescriptPkg.version;
const transpileId = typescriptPkg.name + typescriptPkg.version + '_' + CACHE_BUSTER;
const terserPkg = require(join(opts.nodeModulesDir, 'terser', 'package.json'));
opts.terserVersion = terserPkg.version;
const minifyJsId = terserPkg.name + terserPkg.version + '_' + CACHE_BUSTER;
const rollupPkg = require(join(opts.nodeModulesDir, 'rollup', 'package.json'));
opts.rollupVersion = rollupPkg.version;
const bundlerId = rollupPkg.name + rollupPkg.version + '_' + CACHE_BUSTER;
const autoprefixerPkg = require(join(opts.nodeModulesDir, 'autoprefixer', 'package.json'));
const postcssPkg = require(join(opts.nodeModulesDir, 'postcss', 'package.json'));
const optimizeCssId = autoprefixerPkg.name + autoprefixerPkg.version + '_' + postcssPkg.name + postcssPkg.version + '_' + CACHE_BUSTER;
const parse5Pkg = require(join(opts.nodeModulesDir, 'parse5', 'package.json'));
opts.parse5Verion = parse5Pkg.version;
const data = readJSONSync(join(opts.srcDir, 'compiler', 'sys', 'dependencies.json'));
data.dependencies[0].version = opts.version;
data.dependencies[1].version = typescriptPkg.version;
data.dependencies[2].version = rollupPkg.version;
data.dependencies[3].version = terserPkg.version;
writeJSONSync(join(opts.rootDir, 'dependencies.json'), data, { spaces: 2 });
return {
'__BUILDID__': opts.buildId,
'__BUILDID:BUNDLER__': bundlerId,
'__BUILDID:MINIFYJS__': minifyJsId,
'__BUILDID:OPTIMIZECSS__': optimizeCssId,
'__BUILDID:TRANSPILE__': transpileId,
'__VERSION:STENCIL__': opts.version,
'__VERSION:ROLLUP__': rollupPkg.version,
'__VERSION:TYPESCRIPT__': typescriptPkg.version,
'__VERSION:TERSER__': terserPkg.version,
'__VERMOJI__': opts.vermoji,
};
}
export interface BuildOptions {
ghRepoOrg?: string;
ghRepoName?: string;
rootDir?: string;
srcDir?: string;
nodeModulesDir?: string;
typescriptDir?: string;
typescriptLibDir?: string;
buildDir?: string;
scriptsDir?: string;
scriptsBundlesDir?: string;
bundleHelpersDir?: string;
output?: {
cliDir: string;
compilerDir: string;
devServerDir: string;
internalDir: string;
mockDocDir: string;
screenshotDir: string;
sysDenoDir: string;
sysNodeDir: string;
testingDir: string;
};
version?: string;
buildId?: string;
isProd?: boolean;
isPublishRelease?: boolean;
isCI?: boolean;
vermoji?: string;
packageJsonPath?: string;
packageLockJsonPath?: string;
packageJson?: PackageData;
changelogPath?: string;
tag?: string;
typescriptVersion?: string;
rollupVersion?: string;
parse5Verion?: string;
terserVersion?: string;
}
export interface CmdLineArgs {
'config-version'?: string;
'config-build-id'?: string;
'config-prod'?: string;
}
function getBuildId() {
const d = new Date();
return [
d.getUTCFullYear() + '',
('0' + (d.getUTCMonth() + 1)).slice(-2),
('0' + d.getUTCDate()).slice(-2),
('0' + d.getUTCHours()).slice(-2),
('0' + d.getUTCMinutes()).slice(-2),
('0' + d.getUTCSeconds()).slice(-2),
].join('');
}