-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pack.mjs
71 lines (60 loc) · 1.79 KB
/
pack.mjs
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
#!/usr/bin/env zx
// TODO: enable type checking for this file.
import path from 'node:path';
import { copyFileSync } from 'node:fs';
import * as esbuild from 'esbuild';
import 'zx/globals';
/* eslint-disable no-undef */
if (!process.argv[2]) {
// eslint-disable-next-line no-console
console.error(
'No version is provided, building cli with the existing version.'
);
}
if (process.platform === 'win32') {
usePowerShell();
// for PowerShell compatibility
$.prefix = '$ErrorActionPreference = "Stop";';
$.postfix = '; exit $LastExitCode';
}
// TODO: Enable useSnapshot for a faster startup in the future
let executableName = 'libdragon';
if (process.platform === 'win32') {
executableName = 'libdragon.exe';
} else if (process.platform === 'darwin') {
executableName = 'libdragon-macos';
} else if (process.platform === 'linux') {
executableName = 'libdragon-linux';
}
const executablePath = path.join('build', executableName);
await esbuild.build({
entryPoints: ['index.js'],
bundle: true,
format: 'esm',
platform: 'node',
target: 'node22',
outfile: path.join('build', 'main.js'),
minify: true,
loader: {
'.c': 'text',
'.mk': 'text',
},
define: {
...(process.argv[2] && {
'globalThis.VERSION': JSON.stringify(process.argv[2]),
}),
},
});
await $`node --experimental-sea-config sea-config.json`;
copyFileSync(process.execPath, executablePath);
if (process.platform === 'win32') {
await $`signtool remove /s ${executablePath}`.nothrow();
} else if (process.platform === 'darwin') {
await $`codesign --remove-signature ${executablePath}`.nothrow();
}
await $([
`npx postject ${executablePath} NODE_SEA_BLOB ${path.join(
'build',
'sea-prep.blob'
)} --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --macho-segment-name NODE_SEA`,
]);