-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
executable file
·58 lines (53 loc) · 2.03 KB
/
compile.js
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
#!/usr/bin/env node
const path = require('node:path');
const fs = require('fs');
const { compile } = require('./src/compiler');
const { exec } = require("child_process");
let [_, __, fileName, package] = process.argv;
package = package === 'f'? false : true;
let code = fs.readFileSync(fileName, 'utf8');
let compiledCode = compile(code);
if (package) {
exec('npm i @vercel/ncc -g', (nccErr, nccStdout, nccStderr) => {
if (nccErr)
console.error(nccErr.message);
else if (nccStderr)
console.error(nccStderr);
else {
exec('mkdir -p dist', (dirError, dirStdout, dirStderr) => {
if (dirError || dirStderr)
console.error('Could not create ./dist directory!');
else {
fs.writeFile('dist/index.temp.js', compiledCode, (err) => {
if(err)
console.error(err);
else {
console.log('Intermediate output in: dist/index.temp.js');
exec('ncc build dist/index.temp.js -o dist', (error, stdout, stderr) => {
if (error)
console.error(error.message);
else if (stderr)
console.error(stderr);
else
console.log(stdout);
});
}
});
}
});
}
});
} else {
exec('mkdir -p dist', (dirError, dirStdout, dirStderr) => {
if (dirError || dirStderr)
console.error('Could not create ./dist directory!');
else {
fs.writeFile('dist/index.temp.js', compiledCode, (err) => {
if(err)
console.error(err);
else
console.log('Output in: dist/index.temp.js');
});
}
});
}