1
0
Fork 0
forked from svrjs/svrjs

style: enforce the new Prettier rules on the build script

This commit is contained in:
Dorian Niemiec 2024-09-20 06:37:14 +02:00
parent f01d5d5b1e
commit 350496f57a

View file

@ -23,10 +23,10 @@ function findAllDependencies(curList) {
__dirname + __dirname +
"/node_modules/" + "/node_modules/" +
dependency.replace(/\/\.\./g, "") + dependency.replace(/\/\.\./g, "") +
"/package.json", "/package.json"
) )
.toString(), .toString()
).dependencies || {}, ).dependencies || {}
); );
let noDupNewDepList = []; let noDupNewDepList = [];
newDeplist.forEach((dep) => { newDeplist.forEach((dep) => {
@ -56,19 +56,19 @@ requiredDependencyList.forEach((dependency) => {
// Create the template functions using EJS // Create the template functions using EJS
const layoutTemplate = ejs.compile( const layoutTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/layout.ejs").toString(), fs.readFileSync(__dirname + "/templates/layout.ejs").toString()
); );
const testsTemplate = ejs.compile( const testsTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/tests.ejs").toString(), fs.readFileSync(__dirname + "/templates/tests.ejs").toString()
); );
const indexTemplate = ejs.compile( const indexTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/index.ejs").toString(), fs.readFileSync(__dirname + "/templates/index.ejs").toString()
); );
const licensesTemplate = ejs.compile( const licensesTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/licenses.ejs").toString(), fs.readFileSync(__dirname + "/templates/licenses.ejs").toString()
); );
const licenseElementTemplate = ejs.compile( const licenseElementTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/licenseElement.ejs").toString(), fs.readFileSync(__dirname + "/templates/licenseElement.ejs").toString()
); );
let licenseElements = ""; let licenseElements = "";
@ -81,9 +81,9 @@ dependencyList.forEach((dependency) => {
__dirname + __dirname +
"/node_modules/" + "/node_modules/" +
dependency.replace(/\/\.\./g, "") + dependency.replace(/\/\.\./g, "") +
"/package.json", "/package.json"
) )
.toString(), .toString()
); );
licenseElements += licenseElementTemplate({ licenseElements += licenseElementTemplate({
moduleName: packageJSON.name, moduleName: packageJSON.name,
@ -91,7 +91,7 @@ dependencyList.forEach((dependency) => {
license: packageJSON.license, license: packageJSON.license,
description: packageJSON.description || "No description", description: packageJSON.description || "No description",
author: packageJSON.author ? packageJSON.author.name : packageJSON.author, author: packageJSON.author ? packageJSON.author.name : packageJSON.author,
required: dependenciesAreRequired[dependency], required: dependenciesAreRequired[dependency]
}); });
}); });
@ -101,16 +101,16 @@ const licensesPage = layoutTemplate({
content: licensesTemplate({ content: licensesTemplate({
name: name, name: name,
version: version, version: version,
licenses: licenseElements, licenses: licenseElements
}), })
}); });
const testsPage = layoutTemplate({ const testsPage = layoutTemplate({
title: name + " " + version + " Tests", title: name + " " + version + " Tests",
content: testsTemplate({ content: testsTemplate({
name: name, name: name,
version: version, version: version
}), })
}); });
const indexPage = layoutTemplate({ const indexPage = layoutTemplate({
@ -119,8 +119,8 @@ const indexPage = layoutTemplate({
name: name, name: name,
version: version, version: version,
documentationURL: documentationURL, documentationURL: documentationURL,
changes: changes, changes: changes
}), })
}); });
// Remove the generated assets directory if exists, and create a new one. // Remove the generated assets directory if exists, and create a new one.
@ -155,7 +155,7 @@ fs.writeFileSync(__dirname + "/generatedAssets/index.html", indexPage);
fs.writeFileSync(__dirname + "/generatedAssets/tests.html", testsPage); fs.writeFileSync(__dirname + "/generatedAssets/tests.html", testsPage);
fs.writeFileSync( fs.writeFileSync(
__dirname + "/generatedAssets/licenses/index.html", __dirname + "/generatedAssets/licenses/index.html",
licensesPage, licensesPage
); );
// Bundle the source and copy the assets using esbuild and esbuild-plugin-copy // Bundle the source and copy the assets using esbuild and esbuild-plugin-copy
@ -171,23 +171,25 @@ esbuild
resolveFrom: __dirname, resolveFrom: __dirname,
assets: { assets: {
from: ["./assets/**/*"], from: ["./assets/**/*"],
to: ["./dist"], to: ["./dist"]
}, },
globbyOptions: { globbyOptions: {
dot: true, dot: true
}, }
}), }),
esbuildCopyPlugin.copy({ esbuildCopyPlugin.copy({
resolveFrom: __dirname, resolveFrom: __dirname,
assets: { assets: {
from: ["./generatedAssets/**/*"], from: ["./generatedAssets/**/*"],
to: ["./dist"], to: ["./dist"]
}, }
}), })
], ]
}) })
.then(() => { .then(() => {
const utilFilesAndDirectories = fs.existsSync(__dirname + "/src/extraScripts") const utilFilesAndDirectories = fs.existsSync(
__dirname + "/src/extraScripts"
)
? fs.readdirSync(__dirname + "/src/extraScripts") ? fs.readdirSync(__dirname + "/src/extraScripts")
: []; : [];
const utilFiles = []; const utilFiles = [];
@ -199,11 +201,13 @@ esbuild
// Transpile utilities using esbuild // Transpile utilities using esbuild
esbuild esbuild
.build({ .build({
entryPoints: utilFiles.map((filename) => "src/extraScripts/" + filename), entryPoints: utilFiles.map(
(filename) => "src/extraScripts/" + filename
),
bundle: true, bundle: true,
outdir: "dist", outdir: "dist",
platform: "node", platform: "node",
target: "es2017", target: "es2017"
}) })
.then(() => { .then(() => {
const archiveName = const archiveName =
@ -212,17 +216,14 @@ esbuild
".zip"; ".zip";
const output = fs.createWriteStream(__dirname + "/out/" + archiveName); const output = fs.createWriteStream(__dirname + "/out/" + archiveName);
const archive = archiver("zip", { const archive = archiver("zip", {
zlib: { level: 9 }, zlib: { level: 9 }
}); });
archive.pipe(output); archive.pipe(output);
// Add everything in the "dist" directory except for "svr.js" and "svr.compressed" // Add everything in the "dist" directory except for "svr.js" and "svr.compressed"
archive.glob("**/*", { archive.glob("**/*", {
cwd: __dirname + "/dist", cwd: __dirname + "/dist",
ignore: [ ignore: ["svr.js", "svr.compressed"],
"svr.js",
"svr.compressed"
],
dot: true dot: true
}); });
@ -231,13 +232,13 @@ esbuild
.createReadStream(__dirname + "/dist/svr.js") .createReadStream(__dirname + "/dist/svr.js")
.pipe( .pipe(
zlib.createGzip({ zlib.createGzip({
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" }
); );
archive.finalize(); archive.finalize();
}) })