-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
executable file
·103 lines (88 loc) · 1.91 KB
/
build.js
File metadata and controls
executable file
·103 lines (88 loc) · 1.91 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
#!/usr/bin/env node
"use strict";
(async () => {
const {
execSync,
} = await import('child_process');
const {
readFile,
unlink,
writeFile,
} = await import('fs/promises');
const GCC_COMMAND = './node_modules/.bin/google-closure-compiler --';
const {version} = require('./package.json', 'utf8');
try {
if (
!execSync(GCC_COMMAND + 'version')
.toString()
.includes('Version: v202')
) {
console.error('newer google closure compiler required!');
throw null;
}
}
catch (e) {
console.error('maybe run: npm install google-closure-compiler');
process.exit(1);
}
console.log(`build ${version}...`);
let code = (await readFile('rtjscomp.js', 'utf8'))
.replace(
"require('./package.json').version",
JSON.stringify(version)
)
.replace(
'await import(',
'await import_hiddenfromgcc('
)
.replaceAll(
'parseInt(',
'parseInt_hiddenfromgcc('
);
let name_count = 0;
for (const name of 'dependencies_paths file_function handler_stop path_split promise_deps_resolve promise_deps promise_stopped_resolve promise_stopped watcher'.split(' ')) {
code = code.replaceAll(
name,
'x' + (name_count++).toString(36)
);
}
await writeFile(
'/tmp/rtjscomp.js',
code,
'utf8'
);
execSync(
GCC_COMMAND +
[
'compilation_level SIMPLE',
'externs externs.js',
'js /tmp/rtjscomp.js',
'js_output_file /tmp/rtjscomp.min.js',
'language_out ECMASCRIPT_2017',
'module_resolution NODE',
'rewrite_polyfills false',
'use_types_for_optimization',
'warning_level VERBOSE',
'jscomp_off undefinedVars',
'jscomp_off missingProperties',
]
.join(' --')
);
await writeFile(
'rtjscomp.js',
'#!/usr/bin/env node\n"use strict";' +
(await readFile('/tmp/rtjscomp.min.js', 'ascii'))
.replace(
'await import_hiddenfromgcc(',
'await import('
)
.replaceAll(
'parseInt_hiddenfromgcc(',
'parseInt('
),
'ascii'
);
await unlink('/tmp/rtjscomp.js');
await unlink('/tmp/rtjscomp.min.js');
console.log('done.');
})();