-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathbuildExe.js
More file actions
56 lines (48 loc) · 1.87 KB
/
Copy pathbuildExe.js
File metadata and controls
56 lines (48 loc) · 1.87 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
const rcedit = require('rcedit');
const glob = require('glob');
const path = require('path');
const pjson = require('../package.json');
const fs = require('fs');
// the process.env definition is placed here because the code breaks when it is
// placed after requiring pkg and pkg-fetch
process.env.PKG_CACHE_PATH = path.resolve('.\\.pkg-cache');
const pkg = require('pkg');
const pkgFetch = require('pkg-fetch');
build();
async function build() {
const pkgTarget = 'node22-win-x64';
const cacheExe = await downloadCache(pkgTarget);
await rcedit(cacheExe, {
"version-string": {
"CompanyName": "Microsoft",
"ProductName": "Azurite",
"FileDescription": "Azurite",
"ProductVersion": pjson.version,
"OriginalFilename": "",
"InternalName": "node",
"LegalCopyright": "© 2021 Microsoft. All rights reserved."
},
// file-version is kept as the node version used by the .exe for debugging purposes
"icon": path.resolve('.\\icon.ico')
});
// rename the cache file to skip hash check by pkg-fetch since hash check reverts our change of properties
const newName = cacheExe.replace("fetched", "built");
function asyncRename(oldName, changedName) {
return new Promise(resolve => {
fs.rename(oldName, changedName, response => resolve(response));
});
}
await asyncRename(cacheExe, newName);
const outputExe = path.resolve('.\\release\\azurite.exe');
await pkg.exec([path.resolve('.'), ...['--target', pkgTarget], ...['--output', outputExe], ...['-C', 'Brotli']]);
}
async function downloadCache(pkgTarget) {
const [nodeRange, platform, arch] = pkgTarget.split('-');
await pkgFetch.need({ nodeRange, platform, arch });
const cacheExe = glob.sync(process.env.PKG_CACHE_PATH + "\\**\\fetched*");
if (cacheExe.length < 1) {
console.log('Error downloading PKG cache');
process.exit(1);
}
return cacheExe[0];
}