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 svrjsInfo = JSON.parse(fs.readFileSync(__dirname + "/svrjs.json"));
|
||||
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 coreVersion = svrjsCoreInfo.version;
|
||||
const corePackageJSON = svrjsCoreInfo.packageJSON;
|
||||
|
@ -23,10 +25,12 @@ if (!fs.existsSync(__dirname + "/dist/temp"))
|
|||
fs.mkdirSync(__dirname + "/dist/temp");
|
||||
|
||||
// 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
|
||||
if (!isDev && !fs.existsSync(__dirname + "/core")) fs.mkdirSync(__dirname + "/core");
|
||||
if (!isDev && !fs.existsSync(__dirname + "/core"))
|
||||
fs.mkdirSync(__dirname + "/core");
|
||||
|
||||
function generateAssets() {
|
||||
// Variables from "svrjs.json" file
|
||||
|
@ -178,7 +182,8 @@ if (!isDev) {
|
|||
__dirname + "/package.json",
|
||||
__dirname + "/svrjs.json"
|
||||
]);
|
||||
watcher.on("change", () => {
|
||||
watcher
|
||||
.on("change", () => {
|
||||
try {
|
||||
generateAssets();
|
||||
} catch (err) {
|
||||
|
@ -186,7 +191,8 @@ if (!isDev) {
|
|||
console.error("Stack:");
|
||||
console.error(err.stack);
|
||||
}
|
||||
}).on("ready", () => {
|
||||
})
|
||||
.on("ready", () => {
|
||||
try {
|
||||
generateAssets();
|
||||
} catch (err) {
|
||||
|
@ -250,20 +256,30 @@ if (!isDev) {
|
|||
target: "es2017"
|
||||
})
|
||||
.then(() => {
|
||||
const dependencies = JSON.parse(fs.readFileSync(__dirname + "/package.json")).dependencies || {};
|
||||
const coreDependencyNames = Object.keys(dependencies).filter((dependency) => externalPackages.indexOf(dependency) != -1);
|
||||
const dependencies =
|
||||
JSON.parse(fs.readFileSync(__dirname + "/package.json"))
|
||||
.dependencies || {};
|
||||
const coreDependencyNames = Object.keys(dependencies).filter(
|
||||
(dependency) => externalPackages.indexOf(dependency) != -1
|
||||
);
|
||||
const packageJSON = Object.assign({}, corePackageJSON);
|
||||
|
||||
// Add package.json properties
|
||||
packageJSON.version = coreVersion;
|
||||
packageJSON.main = "./svr.core.js";
|
||||
packageJSON.dependencies = coreDependencyNames.reduce((previousDependencies, dependency) => {
|
||||
packageJSON.dependencies = coreDependencyNames.reduce(
|
||||
(previousDependencies, dependency) => {
|
||||
previousDependencies[dependency] = dependencies[dependency];
|
||||
return previousDependencies;
|
||||
}, {});
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
// 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
|
||||
esbuild
|
||||
|
@ -315,7 +331,9 @@ if (!isDev) {
|
|||
level: 9
|
||||
})
|
||||
);
|
||||
archive.append(compressedSVRJSFileStream, { name: "svr.compressed" });
|
||||
archive.append(compressedSVRJSFileStream, {
|
||||
name: "svr.compressed"
|
||||
});
|
||||
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.");',
|
||||
{ name: "svr.js" }
|
||||
|
|
Reference in a new issue