2019-01-16 01:36:09 +07:00
|
|
|
const fs = require("fs");
|
2019-02-06 00:15:20 +07:00
|
|
|
const fse = require("fs-extra");
|
2019-01-16 01:36:09 +07:00
|
|
|
const os = require("os");
|
|
|
|
const path = require("path");
|
|
|
|
const nexe = require("nexe");
|
2019-02-06 00:15:20 +07:00
|
|
|
const zlib = require("zlib");
|
2019-01-16 01:36:09 +07:00
|
|
|
|
|
|
|
const nexeRoot = path.join(os.homedir(), ".nexe");
|
|
|
|
if (!fs.existsSync(nexeRoot)) {
|
|
|
|
throw new Error("run nexe manually on a binary to initialize it");
|
|
|
|
}
|
|
|
|
const listed = fs.readdirSync(nexeRoot);
|
|
|
|
listed.forEach((list) => {
|
|
|
|
if (list.startsWith("linux")) {
|
|
|
|
const stat = fs.statSync(path.join(nexeRoot, list));
|
|
|
|
if (stat.isFile()) {
|
|
|
|
if (stat.size > 20000000) {
|
|
|
|
throw new Error("must use upx to shrink node binary in ~/.nexe/" + list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-06 00:15:20 +07:00
|
|
|
const tmpDir = path.join(__dirname, "../build");
|
|
|
|
if (fs.existsSync(tmpDir)) {
|
|
|
|
console.log("Removing old build dir...");
|
|
|
|
fse.removeSync(tmpDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Copying build files...");
|
|
|
|
fse.copySync(path.join(__dirname, "../resources"), tmpDir, {
|
|
|
|
recursive: true,
|
|
|
|
});
|
|
|
|
const modDir = path.join(tmpDir, "modules");
|
|
|
|
fs.mkdirSync(modDir);
|
|
|
|
fse.copySync(path.join(__dirname, "../../protocol/node_modules/node-pty/build/Release/pty.node"), path.join(modDir, "pty.node"));
|
|
|
|
|
|
|
|
const zipper = (p) => {
|
|
|
|
const stat = fs.statSync(p);
|
|
|
|
if (!stat.isDirectory()) {
|
|
|
|
fs.writeFileSync(p + ".gz", zlib.gzipSync(fs.readFileSync(p)));
|
|
|
|
fse.removeSync(p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const files = fs.readdirSync(p);
|
|
|
|
files.forEach((f) => zipper(path.join(p, f)));
|
|
|
|
};
|
|
|
|
|
|
|
|
zipper(path.join(tmpDir, "web"));
|
|
|
|
zipper(path.join(tmpDir, "bootstrap-fork.js"));
|
|
|
|
|
2019-01-16 01:36:09 +07:00
|
|
|
nexe.compile({
|
|
|
|
debugBundle: true,
|
|
|
|
input: path.join(__dirname, "../out/cli.js"),
|
|
|
|
output: 'cli',
|
2019-02-06 00:15:20 +07:00
|
|
|
targets: ["linux"],
|
2019-01-16 01:36:09 +07:00
|
|
|
native: {
|
2019-02-06 00:15:20 +07:00
|
|
|
spdlog: {
|
2019-01-19 04:46:40 +07:00
|
|
|
additionalFiles: [
|
2019-02-06 00:15:20 +07:00
|
|
|
'spdlog.node'
|
2019-01-19 04:46:40 +07:00
|
|
|
],
|
|
|
|
},
|
2019-01-16 01:36:09 +07:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* To include native extensions, do NOT install node_modules for each one. They
|
|
|
|
* are not required as each extension is built using webpack.
|
|
|
|
*/
|
2019-01-19 04:46:40 +07:00
|
|
|
resources: [
|
|
|
|
path.join(__dirname, "../package.json"),
|
2019-02-06 00:15:20 +07:00
|
|
|
path.join(__dirname, "../build/**/*"),
|
2019-01-19 04:46:40 +07:00
|
|
|
],
|
2019-01-16 01:36:09 +07:00
|
|
|
});
|