-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (48 loc) · 2.12 KB
/
index.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
#!/usr/bin/env node
const pkg = require('@yao-pkg/pkg');
const tar = require('tar');
const fastGlob = require('fast-glob');
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const argv = process.argv.slice(2);
const projectCwd = path.resolve(process.cwd(), argv[0]);
console.log("[*] Generating files...");
fs.mkdirSync(path.join(projectCwd, '.nodage'), { recursive: true });
fs.copyFileSync(__dirname + '/node-20', path.join(projectCwd, '.nodage/node.exe'));
console.log("[*] Compressing project files...");
console.log(path.join(__dirname, 'boilerplate/app.tgz'))
const files = [
...fastGlob.sync('**/*', { cwd: path.resolve(process.cwd(), argv[0]), dot: true })
];
// TODO: __dirname + ... must be replaced with path.join
tar.create({
gzip: true,
file: path.join(__dirname, 'boilerplate/app.tgz'),
cwd: projectCwd
}, files)
.then(_ => {
console.log("[$] Project files compressed");
const hash = crypto.createHash('sha256');
const rs = fs.createReadStream(__dirname + '/boilerplate/app.tgz');
console.log("[*] Calculating project SHA256 hash...")
rs.on('data', (data) => { hash.update(data); });
rs.on('end', async () => {
console.log("[*] Writing hash to file...")
fs.writeFileSync(__dirname + '/boilerplate/app.tgz.sha256', hash.digest('hex'));
console.log("[$] Hash written to file");
console.log("[*] Packaging project files...");
await pkg.exec([
__dirname + '/boilerplate/index.js',
'--targets', 'node20-windows-x64',
'--config', __dirname + '/boilerplate/package.json',
'--output', path.resolve(argv[1])
]);
console.log("[$] Project files packaged to", path.resolve(argv[1]));
console.log("[*] Cleaning up...")
fs.unlinkSync(__dirname + '/boilerplate/app.tgz');
fs.unlinkSync(__dirname + '/boilerplate/app.tgz.sha256');
fs.rmSync(path.join(projectCwd, '.nodage'), { recursive: true, force: true });
console.log("[$] Cleaned up");
});
}).catch(err => console.log(err));