forked from svrjs/svrjs
style: format esbuild configuration (the build script)
This commit is contained in:
parent
d34d4bcc2d
commit
c9bbd0e202
1 changed files with 101 additions and 83 deletions
|
@ -7,7 +7,9 @@ const archiver = require("archiver");
|
||||||
const chokidar = require("chokidar");
|
const chokidar = require("chokidar");
|
||||||
const svrjsInfo = JSON.parse(fs.readFileSync(__dirname + "/svrjs.json"));
|
const svrjsInfo = JSON.parse(fs.readFileSync(__dirname + "/svrjs.json"));
|
||||||
const { version } = svrjsInfo;
|
const { version } = svrjsInfo;
|
||||||
const svrjsCoreInfo = JSON.parse(fs.readFileSync(__dirname + "/svrjs.core.json"));
|
const svrjsCoreInfo = JSON.parse(
|
||||||
|
fs.readFileSync(__dirname + "/svrjs.core.json")
|
||||||
|
);
|
||||||
const { externalPackages } = svrjsCoreInfo;
|
const { externalPackages } = svrjsCoreInfo;
|
||||||
const coreVersion = svrjsCoreInfo.version;
|
const coreVersion = svrjsCoreInfo.version;
|
||||||
const corePackageJSON = svrjsCoreInfo.packageJSON;
|
const corePackageJSON = svrjsCoreInfo.packageJSON;
|
||||||
|
@ -23,10 +25,12 @@ if (!fs.existsSync(__dirname + "/dist/temp"))
|
||||||
fs.mkdirSync(__dirname + "/dist/temp");
|
fs.mkdirSync(__dirname + "/dist/temp");
|
||||||
|
|
||||||
// Create the out directory if it doesn't exist and if not building for development
|
// Create the out directory if it doesn't exist and if not building for development
|
||||||
if (!isDev && !fs.existsSync(__dirname + "/out")) fs.mkdirSync(__dirname + "/out");
|
if (!isDev && !fs.existsSync(__dirname + "/out"))
|
||||||
|
fs.mkdirSync(__dirname + "/out");
|
||||||
|
|
||||||
// Create the core directory if it doesn't exist and if not building for development
|
// Create the core directory if it doesn't exist and if not building for development
|
||||||
if (!isDev && !fs.existsSync(__dirname + "/core")) fs.mkdirSync(__dirname + "/core");
|
if (!isDev && !fs.existsSync(__dirname + "/core"))
|
||||||
|
fs.mkdirSync(__dirname + "/core");
|
||||||
|
|
||||||
function generateAssets() {
|
function generateAssets() {
|
||||||
// Variables from "svrjs.json" file
|
// Variables from "svrjs.json" file
|
||||||
|
@ -178,7 +182,8 @@ if (!isDev) {
|
||||||
__dirname + "/package.json",
|
__dirname + "/package.json",
|
||||||
__dirname + "/svrjs.json"
|
__dirname + "/svrjs.json"
|
||||||
]);
|
]);
|
||||||
watcher.on("change", () => {
|
watcher
|
||||||
|
.on("change", () => {
|
||||||
try {
|
try {
|
||||||
generateAssets();
|
generateAssets();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -186,7 +191,8 @@ if (!isDev) {
|
||||||
console.error("Stack:");
|
console.error("Stack:");
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
}
|
}
|
||||||
}).on("ready", () => {
|
})
|
||||||
|
.on("ready", () => {
|
||||||
try {
|
try {
|
||||||
generateAssets();
|
generateAssets();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -250,20 +256,30 @@ if (!isDev) {
|
||||||
target: "es2017"
|
target: "es2017"
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const dependencies = JSON.parse(fs.readFileSync(__dirname + "/package.json")).dependencies || {};
|
const dependencies =
|
||||||
const coreDependencyNames = Object.keys(dependencies).filter((dependency) => externalPackages.indexOf(dependency) != -1);
|
JSON.parse(fs.readFileSync(__dirname + "/package.json"))
|
||||||
|
.dependencies || {};
|
||||||
|
const coreDependencyNames = Object.keys(dependencies).filter(
|
||||||
|
(dependency) => externalPackages.indexOf(dependency) != -1
|
||||||
|
);
|
||||||
const packageJSON = Object.assign({}, corePackageJSON);
|
const packageJSON = Object.assign({}, corePackageJSON);
|
||||||
|
|
||||||
// Add package.json properties
|
// Add package.json properties
|
||||||
packageJSON.version = coreVersion;
|
packageJSON.version = coreVersion;
|
||||||
packageJSON.main = "./svr.core.js";
|
packageJSON.main = "./svr.core.js";
|
||||||
packageJSON.dependencies = coreDependencyNames.reduce((previousDependencies, dependency) => {
|
packageJSON.dependencies = coreDependencyNames.reduce(
|
||||||
|
(previousDependencies, dependency) => {
|
||||||
previousDependencies[dependency] = dependencies[dependency];
|
previousDependencies[dependency] = dependencies[dependency];
|
||||||
return previousDependencies;
|
return previousDependencies;
|
||||||
}, {});
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
// Write package.json
|
// Write package.json
|
||||||
fs.writeFileSync(__dirname + "/core/package.json", JSON.stringify(packageJSON, null, 2));
|
fs.writeFileSync(
|
||||||
|
__dirname + "/core/package.json",
|
||||||
|
JSON.stringify(packageJSON, null, 2)
|
||||||
|
);
|
||||||
|
|
||||||
// Build SVR.JS Core
|
// Build SVR.JS Core
|
||||||
esbuild
|
esbuild
|
||||||
|
@ -315,7 +331,9 @@ if (!isDev) {
|
||||||
level: 9
|
level: 9
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
archive.append(compressedSVRJSFileStream, { name: "svr.compressed" });
|
archive.append(compressedSVRJSFileStream, {
|
||||||
|
name: "svr.compressed"
|
||||||
|
});
|
||||||
archive.append(
|
archive.append(
|
||||||
'const zlib = require("zlib");\nconst fs = require("fs");\nconsole.log("Deleting SVR.JS stub...");\nfs.unlinkSync("svr.js");\nconsole.log("Decompressing SVR.JS...");\nconst script = zlib.gunzipSync(fs.readFileSync("svr.compressed"));\nfs.unlinkSync("svr.compressed");\nfs.writeFileSync("svr.js",script);\nconsole.log("Restart SVR.JS to get server interface.");',
|
'const zlib = require("zlib");\nconst fs = require("fs");\nconsole.log("Deleting SVR.JS stub...");\nfs.unlinkSync("svr.js");\nconsole.log("Decompressing SVR.JS...");\nconst script = zlib.gunzipSync(fs.readFileSync("svr.compressed"));\nfs.unlinkSync("svr.compressed");\nfs.writeFileSync("svr.js",script);\nconsole.log("Restart SVR.JS to get server interface.");',
|
||||||
{ name: "svr.js" }
|
{ name: "svr.js" }
|
||||||
|
|
Reference in a new issue