-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathbuild.js
More file actions
664 lines (534 loc) · 22.9 KB
/
build.js
File metadata and controls
664 lines (534 loc) · 22.9 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
/*!
wow.export (https://github.com/Kruithne/wow.export)
Authors: Kruithne <kruithne@gmail.com>
License: MIT
*/
import fs from 'node:fs/promises';
import AdmZip from 'adm-zip';
import zlib from 'node:zlib';
import path from 'node:path';
import util from 'node:util';
import rcedit from 'rcedit';
import crypto from 'node:crypto';
import { log, log_color } from './build/log.js';
const argv = process.argv.splice(2);
const CONFIG_FILE = './build.json';
const MANIFEST_FILE = './package.json';
const log_colour_array = (arr, color = 'cyan') => arr.map(e => log_color(color, e.name || e)).join(', ');
function format_bytes(bytes) {
if (bytes === 0)
return '0b';
const units = ['b', 'kb', 'mb', 'gb'];
const i = Math.floor(Math.log(bytes) / Math.log(1024));
// no more than gb
const unit_index = Math.min(i, 3);
// format with at most 2 decimal places and remove trailing zeros
return (bytes / Math.pow(1024, unit_index)).toFixed(2)
.replace(/\.0+$|(\.\d*[1-9])0+$/, '$1') + units[unit_index];
}
/**
* Returns an array of all files recursively collected from a directory.
* @param {string} dir Directory to recursively search.
* @param {array} out Array to be populated with results (automatically created).
*/
const collectFiles = async (dir, out = []) => {
const entries = await fs.opendir(dir);
for await (const entry of entries) {
const entryPath = path.join(dir, entry.name);
if (entry.isDirectory())
await collectFiles(entryPath, out);
else
out.push(entryPath);
}
return out;
};
/**
* Apply placeholder replacements to a string value.
* e.g: {{year}} -> placeholders.year
* @param {string} value
* @param {object} placeholders
* @returns {string}
*/
const applyPlaceholders = (value, placeholders) => {
if (typeof value === 'string') {
return value.replace(/\{\{(\w+)\}\}/g, (match, placeholder) => {
return placeholders[placeholder] ?? match;
});
}
return value;
};
// Create a promisified version of zlib.deflate.
const deflateBuffer = util.promisify(zlib.deflate);
(async () => {
const config = await Bun.file(CONFIG_FILE).json();
const outDir = path.resolve(config.outputDirectory);
const cacheDir = path.resolve(config.cacheDirectory);
// Create base directories we use during the build.
await fs.mkdir(outDir, { recursive: true });
await fs.mkdir(cacheDir, { recursive: true });
// Index builds from the build config.
const builds = new Map();
for (const build of config.builds)
builds.set(build.name, build);
// Check all provided CLI parameters for valid build names.
const targetBuilds = [];
if (argv.includes('*')) {
// If * is present as a parameter, include all builds.
targetBuilds.push(...builds.values());
} else {
for (const arg of argv) {
const build = builds.get(arg.toLowerCase());
if (build !== undefined)
targetBuilds.push(build);
}
}
// User has not selected any valid builds; display available and exit.
if (targetBuilds.length === 0) {
log.warn('You have not selected any builds.');
log.info('Available builds: %s', log_colour_array(config.builds));
return;
}
const allBuildsStart = Date.now();
log.info('Selected builds: %s', log_colour_array(targetBuilds));
let last_addon_arch = null;
for (const build of targetBuilds) {
const buildGUID = Bun.randomUUIDv7();
log.info('Starting build *%s* [guid *%s*]...', build.name, buildGUID);
const buildStart = Date.now();
const buildDir = path.join(outDir, build.name);
// build native addons for the target architecture (skip if already built for this arch)
const target_arch = build.arch ?? process.arch;
if (config.nativeAddonScript && last_addon_arch !== target_arch) {
const addonScriptPath = path.resolve(config.nativeAddonScript);
log.info('Building native addons for *%s* (*%s*)...', target_arch, addonScriptPath);
const addonStart = Date.now();
const addon_result = Bun.spawnSync({
cmd: ['bun', addonScriptPath, `--arch=${target_arch}`],
stdio: ['inherit', 'inherit', 'inherit']
});
if (addon_result.exitCode !== 0)
throw new Error('Native addon build failed');
last_addon_arch = target_arch;
const addonElapsed = (Date.now() - addonStart) / 1000;
log.success('Native addons built for *%s* in *%ds*', target_arch, addonElapsed);
}
// Wipe the build directory and then re-create it.
await fs.rm(buildDir, { recursive: true, force: true });
await fs.mkdir(buildDir, { recursive: true });
const bundleArchive = util.format(build.bundle, config.webkitVersion);
const bundlePath = path.join(cacheDir, bundleArchive);
// Check if we already have a copy of this bundle in our cache directory.
// If not, download it from the remote server and store it for re-use.
await fs.access(bundlePath).catch(async () => {
const bundleURL = util.format(config.webkitURL, config.webkitVersion, bundleArchive);
log.info('Downloading *%s*...', bundleURL);
const startTime = Date.now();
const response = await fetch(bundleURL);
if (!response.ok)
throw new Error('Download failed: ' + response.statusText);
const data = await response.arrayBuffer();
await Bun.write(bundlePath, data);
const elapsed = (Date.now() - startTime) / 1000;
const bundleStats = await fs.stat(bundlePath);
log.success('Download complete! *%s* in *%ds* (*%s/s*)', format_bytes(bundleStats.size), elapsed, format_bytes(bundleStats.size / elapsed));
});
// This function allows us to filter out files from the framework
// bundle that we don't want included in our final output.
const extractFilter = (entry) => {
// Whitelist takes priority over blacklist.
for (const check of build.filter.whitelist) {
if (entry.match(check))
return true;
}
for (const check of build.filter.blacklist) {
if (entry.match(check))
return false;
}
// Default to inclusion.
return true;
};
const extractStart = Date.now();
let extractCount = 0;
let filterCount = 0;
log.info('Extracting files from *%s*...', bundleArchive);
const bundleType = build.bundleType.toUpperCase();
if (bundleType === 'ZIP') { // 0x04034b50
const zip = new AdmZip(bundlePath);
const zipEntries = zip.getEntries();
const bundleName = path.basename(bundleArchive, '.zip');
for (const entry of zipEntries) {
const entryName = entry.entryName;
if (extractFilter(entryName)) {
const entryPath = entryName.substring(bundleName.length);
const entryDir = path.join(buildDir, path.dirname(entryPath));
await fs.mkdir(entryDir, { recursive: true });
zip.extractEntryTo(entry, entryDir, false, true, true);
extractCount++;
} else {
filterCount++;
}
}
} else if (bundleType === 'GZ') { // 0x8B1F
const list_result = Bun.spawnSync({ cmd: ['tar', '-tf', bundlePath] });
if (list_result.exitCode !== 0)
throw new Error(`Failed to list archive contents: ${list_result.stderr?.toString() || 'Unknown error'}`);
const all_files = list_result.stdout?.toString().split('\n').filter(line => line.trim() && !line.endsWith('/')) || [];
const files_to_extract = [];
for (const file of all_files) {
if (extractFilter(file)) {
const stripped_path = file.split('/').slice(1).join('/');
if (stripped_path) {
files_to_extract.push(file);
extractCount++;
}
} else {
filterCount++;
}
}
if (files_to_extract.length > 0) {
const extract_args = [
'-xf', bundlePath,
'-C', buildDir,
'--strip-components=1',
...files_to_extract
];
const extract_res = Bun.spawnSync({ cmd: ['tar', ...extract_args] });
if (extract_res.exitCode !== 0)
throw new Error(`Extraction failed: ${extract_res.stderr?.toString() || 'Unknown error'}`);
}
} else {
// Developer didn't config a build properly.
throw new Error('Unexpected bundle type: ' + bundleType);
}
const extractElapsed = (Date.now() - extractStart) / 1000;
log.success('Extracted *%d* files (*%d* filtered) in *%ds*', extractCount, filterCount, extractElapsed);
log.info('Remapping files and merging additional sources...');
const mappings = [];
// File remappings: Source -and- target are relative to build directory.
const remaps = Object.entries(build.remap || {});
if (remaps.length > 0) {
for (const [origName, target] of remaps)
mappings.push({ source: path.join(buildDir, origName), target });
}
// Additional source merges: Source is relative to cwd, target relative to build directory.
const include = Object.entries(build.include || {});
if (include.length > 0) {
for (const [source, target] of include) {
// Check if source ends with /* for recursive directory copy
if (source.endsWith('/*')) {
const sourceDir = path.resolve(source.slice(0, -2));
const targetBase = target.endsWith('/*') ? target.slice(0, -2) : target;
mappings.push({ source: sourceDir, target: targetBase, clone: true, recursive: true });
} else {
mappings.push({ source: path.resolve(source), target, clone: true });
}
}
}
for (const map of mappings) {
if (map.recursive) {
// Recursively copy directory contents
const targetPath = path.join(buildDir, map.target);
log.info('*%s/* -> *%s/* (recursive)', map.source, targetPath);
await fs.mkdir(targetPath, { recursive: true });
const files = await collectFiles(map.source);
for (const file of files) {
const relativePath = path.relative(map.source, file);
const destPath = path.join(targetPath, relativePath);
await fs.mkdir(path.dirname(destPath), { recursive: true });
await fs.copyFile(file, destPath);
}
} else {
const targetPath = path.join(buildDir, map.target);
log.info('*%s* -> *%s*', map.source, targetPath);
// In the event that we specify a deeper path that does not
// exist, make sure we create missing directories first.
await fs.mkdir(path.dirname(targetPath), { recursive: true });
const func = map.clone ? fs.copyFile : fs.rename;
await func(map.source, targetPath);
}
}
// macOS app bundle rebranding: rename binaries, update Info.plist files
if (build.macos) {
const macos_app_name = build.macos.appName;
const macos_bundle_id = build.macos.bundleIdentifier;
const appDir = path.join(buildDir, macos_app_name + '.app');
log.info('Rebranding macOS app bundle (*%s*)...', macos_app_name);
const rebrand_plist = async (plist_path) => {
let content = await fs.readFile(plist_path, 'utf8');
for (const key of ['CFBundleDisplayName', 'CFBundleExecutable', 'CFBundleName']) {
const regex = new RegExp(`(<key>${key}</key>\\s*<string>)nwjs([^<]*</string>)`);
content = content.replace(regex, `$1${macos_app_name}$2`);
}
content = content.replace(/io\.nwjs\.nwjs/g, macos_bundle_id);
await fs.writeFile(plist_path, content, 'utf8');
};
// rename main binary
await fs.rename(
path.join(appDir, 'Contents', 'MacOS', 'nwjs'),
path.join(appDir, 'Contents', 'MacOS', macos_app_name)
);
// update main Info.plist
await rebrand_plist(path.join(appDir, 'Contents', 'Info.plist'));
log.success('Rebranded main app bundle');
// update localized strings
try {
const strings_path = path.join(appDir, 'Contents', 'Resources', 'en.lproj', 'InfoPlist.strings');
let strings = await fs.readFile(strings_path, 'utf8');
strings = strings.replace(/nwjs/g, macos_app_name);
await fs.writeFile(strings_path, strings, 'utf8');
log.success('Updated InfoPlist.strings');
} catch {
// localization file may not exist in all nwjs versions
}
// find framework version directory for helper/framework plist updates
const versions_dir = path.join(appDir, 'Contents', 'Frameworks', 'nwjs Framework.framework', 'Versions');
const versions = await fs.readdir(versions_dir);
const version_name = versions.find(v => v !== 'Current');
if (version_name) {
const version_dir = path.join(versions_dir, version_name);
// update framework Info.plist
try {
await rebrand_plist(path.join(version_dir, 'Resources', 'Info.plist'));
log.success('Updated framework Info.plist');
} catch {
// framework plist may not exist
}
// rename and rebrand helper apps
const helpers_dir = path.join(version_dir, 'Helpers');
const helper_suffixes = ['', ' (GPU)', ' (Renderer)', ' (Plugin)', ' (Alerts)'];
for (const suffix of helper_suffixes) {
const old_name = 'nwjs Helper' + suffix;
const new_name = macos_app_name + ' Helper' + suffix;
const old_app_path = path.join(helpers_dir, old_name + '.app');
try {
await fs.access(old_app_path);
} catch {
continue;
}
await rebrand_plist(path.join(old_app_path, 'Contents', 'Info.plist'));
await fs.rename(
path.join(old_app_path, 'Contents', 'MacOS', old_name),
path.join(old_app_path, 'Contents', 'MacOS', new_name)
);
await fs.rename(old_app_path, path.join(helpers_dir, new_name + '.app'));
log.success('Rebranded helper: *%s*', new_name);
}
}
}
// Clone or link sources (depending on build-specific flag).
const sourceType = build.sourceMethod.toUpperCase();
const sourceDirectory = path.resolve(config.sourceDirectory);
const sourceTarget = path.resolve(path.join(buildDir, build.sourceTarget));
const isBundle = sourceType === 'BUNDLE';
if (sourceType === 'LINK') {
// Create a symlink for the source directory.
await fs.symlink(sourceDirectory, sourceTarget, 'junction');
log.success('Created source link *%s* <-> *%s*', sourceTarget, sourceDirectory);
} else if (isBundle) {
// Bundle everything together, packaged for production release.
const bundleConfig = build.bundleConfig;
const jsEntry = path.join(sourceDirectory, bundleConfig.jsEntry);
log.info('Bundling sources (entry: *%s*)...', jsEntry);
// Make sure the source directory exists.
await fs.mkdir(sourceTarget, { recursive: true });
const out_build = await Bun.build({
entrypoints: [jsEntry],
outdir: sourceTarget,
target: 'node',
format: 'cjs',
define: {
'process.env.BUILD_RELEASE': '"true"'
}
});
for (const output of out_build.outputs)
log.success('Created bundle *%s*', output.hash);
}
if (sourceType === 'CLONE' || isBundle) {
const filterExt = isBundle ? build.bundleConfig.filterExt || [] : [];
// Clone all of the sources files to the build output.
log.info('Cloning sources *%s* -> *%s*...', sourceDirectory, sourceTarget);
const cloneStart = Date.now();
await fs.mkdir(sourceTarget, { recursive: true });
const files = await collectFiles(sourceDirectory);
for (const file of files) {
if (isBundle && filterExt.some(e => file.endsWith(e)))
continue;
const targetPath = path.join(sourceTarget, path.relative(sourceDirectory, file));
await fs.mkdir(path.dirname(targetPath), { recursive: true });
await fs.copyFile(file, targetPath);
}
const cloneElapsed = (Date.now() - cloneStart) / 1000;
log.success('Cloned *%d* source files in *%ds*', files.length, cloneElapsed);
}
// Grab the contents of the project manifest file.
const meta = JSON.parse(await fs.readFile(MANIFEST_FILE));
// Set resource strings for the Windows binary.
if (build.rcedit) {
const rcConfig = Object.assign({
'file-version': meta.version,
'product-version': meta.version
}, build.rcedit);
const placeholders = { year: new Date().getFullYear() };
if (rcConfig['version-string']) {
for (const [key, value] of Object.entries(rcConfig['version-string']))
rcConfig['version-string'][key] = applyPlaceholders(value, placeholders);
}
log.info('Writing resource strings on binary...');
await rcedit(path.join(buildDir, rcConfig.binary), rcConfig);
}
// Compile updater application.
if (build.updater) {
const updaterStart = Date.now();
const updaterOutput = path.join(buildDir, build.updater.out);
log.info('Compiling updater application (*%s*)...', build.updater.target);
const bunArgs = [
'build',
config.updaterScript,
'--compile',
'--target=' + build.updater.target,
'--outfile',
updaterOutput
];
if (build.updater.metadata) {
const metadata = build.updater.metadata;
const placeholders = { year: new Date().getFullYear() };
if (build.updater.target.includes('windows')) {
if (metadata.title)
bunArgs.push('--windows-title=' + applyPlaceholders(metadata.title, placeholders));
if (metadata.publisher)
bunArgs.push('--windows-publisher=' + applyPlaceholders(metadata.publisher, placeholders));
if (metadata.description)
bunArgs.push('--windows-description=' + applyPlaceholders(metadata.description, placeholders));
if (metadata.copyright)
bunArgs.push('--windows-copyright=' + applyPlaceholders(metadata.copyright, placeholders));
if (metadata.icon)
bunArgs.push('--windows-icon=' + path.resolve(metadata.icon));
bunArgs.push('--windows-version=' + meta.version);
}
log.info('Applied updater metadata: *%s*', metadata.title || 'unknown');
}
const result = Bun.spawnSync({ cmd: ['bun', ...bunArgs], stdio: ['inherit', 'inherit', 'inherit'] });
if (result.exitCode !== 0)
throw new Error(`Bun build failed with code ${result.exitCode}`);
const updaterElapsed = (Date.now() - updaterStart) / 1000;
log.success('Updater application compiled in *%ds* -> *%s*', updaterElapsed, updaterOutput);
// ad-hoc codesign bun-compiled binaries for macOS
if (build.updater.target.includes('darwin') && process.platform === 'darwin') {
log.info('Ad-hoc codesigning updater binary...');
const sign_result = Bun.spawnSync({ cmd: ['codesign', '--force', '-s', '-', updaterOutput], stdio: ['inherit', 'inherit', 'inherit'] });
if (sign_result.exitCode !== 0)
throw new Error('Codesigning updater binary failed');
log.success('Updater binary codesigned');
}
}
// Compile installer application (output to separate directory for publish).
if (build.installer) {
const installerStart = Date.now();
const installerDir = path.join(outDir, build.name + '-installer');
await fs.mkdir(installerDir, { recursive: true });
const installerOutput = path.join(installerDir, build.installer.out);
log.info('Compiling installer application (*%s*)...', build.installer.target);
const bunArgs = [
'build',
config.installerScript,
'--compile',
'--target=' + build.installer.target,
'--outfile',
installerOutput
];
if (build.installer.metadata) {
const metadata = build.installer.metadata;
const placeholders = { year: new Date().getFullYear() };
if (build.installer.target.includes('windows')) {
if (metadata.title)
bunArgs.push('--windows-title=' + applyPlaceholders(metadata.title, placeholders));
if (metadata.publisher)
bunArgs.push('--windows-publisher=' + applyPlaceholders(metadata.publisher, placeholders));
if (metadata.description)
bunArgs.push('--windows-description=' + applyPlaceholders(metadata.description, placeholders));
if (metadata.copyright)
bunArgs.push('--windows-copyright=' + applyPlaceholders(metadata.copyright, placeholders));
if (metadata.icon)
bunArgs.push('--windows-icon=' + path.resolve(metadata.icon));
bunArgs.push('--windows-version=' + meta.version);
}
log.info('Applied installer metadata: *%s*', metadata.title || 'unknown');
}
const result = Bun.spawnSync({ cmd: ['bun', ...bunArgs], stdio: ['inherit', 'inherit', 'inherit'] });
if (result.exitCode !== 0)
throw new Error(`Bun installer build failed with code ${result.exitCode}`);
const installerElapsed = (Date.now() - installerStart) / 1000;
log.success('Installer application compiled in *%ds* -> *%s*', installerElapsed, installerOutput);
// ad-hoc codesign bun-compiled binaries for macOS
if (build.installer.target.includes('darwin') && process.platform === 'darwin') {
log.info('Ad-hoc codesigning installer binary...');
const sign_result = Bun.spawnSync({ cmd: ['codesign', '--force', '-s', '-', installerOutput], stdio: ['inherit', 'inherit', 'inherit'] });
if (sign_result.exitCode !== 0)
throw new Error('Codesigning installer binary failed');
log.success('Installer binary codesigned');
}
}
// Build a manifest (package.json) file for the build.
const manifest = {};
// Apply manifest properties inherited from this scripts manifest.
for (const inherit of config.manifestInherit || [])
manifest[inherit] = meta[inherit];
// Apply manifest properties defined in the config.
Object.assign(manifest, config.manifest);
// Apply build specific meta data to the manifest.
Object.assign(manifest, { flavour: build.name, guid: buildGUID });
const manifestPath = path.resolve(path.join(buildDir, build.manifestTarget));
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t'));
log.success('Manifest file written to *%s*', manifestPath);
// ad-hoc codesign macOS app bundle after all modifications are finalized
if (build.macos && process.platform === 'darwin') {
const app_path = path.join(buildDir, build.macos.appName + '.app');
log.info('Ad-hoc codesigning app bundle (*%s*)...', app_path);
const sign_result = Bun.spawnSync({ cmd: ['codesign', '--force', '--deep', '-s', '-', app_path], stdio: ['inherit', 'inherit', 'inherit'] });
if (sign_result.exitCode !== 0)
throw new Error('Codesigning app bundle failed');
log.success('App bundle codesigned');
}
// Create update bundle and manifest.
if (build.updateBundle) {
log.info('Building update package...');
const contents = {};
const bundleOut = path.join(buildDir, build.updateBundle.bundle);
const files = await collectFiles(buildDir);
let entryCount = 0;
let totalSize = 0;
let compSize = 0;
for (const file of files) {
const relative = path.relative(buildDir, file).replace(/\\/g, '/');
const permissions = (await fs.stat(file)).mode & 0o7777;
const data = await fs.readFile(file);
const hash = crypto.createHash('sha256');
hash.update(data);
const comp = await deflateBuffer(data);
await fs.writeFile(bundleOut, comp, { flag: 'a' });
contents[relative] = {
hash: hash.digest('hex'),
permissions: permissions,
size: data.byteLength,
compSize: comp.byteLength,
ofs: compSize
};
totalSize += data.byteLength;
compSize += comp.byteLength;
entryCount++;
}
const manifestData = { contents, guid: buildGUID }
const manifestOut = path.join(buildDir, build.updateBundle.manifest);
await fs.writeFile(manifestOut, JSON.stringify(manifestData, null, '\t'), 'utf8');
log.info('Update package built (*%s* (*%s* deflated) in *%d* files)', format_bytes(totalSize), format_bytes(compSize), entryCount);
}
const buildElapsed = (Date.now() - buildStart) / 1000;
log.success('Build *%s* completed in *%ds*', build.name, buildElapsed);
}
const allBuildsElapsed = (Date.now() - allBuildsStart) / 1000;
log.success('*%d* builds completed in *%ds*!', targetBuilds.length, allBuildsElapsed);
})().catch(e => {
log.error('An unexpected error has halted the build:');
log.error(e);
process.exit(1);
});