1
0
Fork 0
forked from svrjs/svrjs

Make the build script transpile the utilities

This commit is contained in:
Dorian Niemiec 2024-08-26 08:24:29 +02:00
parent 2a9b47a318
commit c4c207cd98
2 changed files with 27 additions and 19 deletions

2
NOTES
View file

@ -1,2 +0,0 @@
In the src folder, you can use any version - it will be transpiled to ES2017 by esbuild.
But in the utils folder, you have to use at most ES2017, because it is not transpiled.

View file

@ -124,19 +124,12 @@ fs.writeFileSync(__dirname + "/generatedAssets/licenses/index.html", licensesPag
// Bundle the source and copy the assets using esbuild and esbuild-plugin-copy
esbuild.build({
entryPoints: ["src/index.js"], // Your entry file
entryPoints: ["src/index.js"],
bundle: true,
outfile: "dist/svr.js", // Output file
outfile: "dist/svr.js",
platform: "node",
target: "es2017",
plugins: [
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
from: ["./utils/**/*"],
to: ["./dist"],
}
}),
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
@ -156,14 +149,31 @@ esbuild.build({
})
],
}).then(() => {
const archiveName = "svr.js." + version.toLowerCase().replace(/[^0-9a-z]+/g,".") + ".zip";
const output = fs.createWriteStream(__dirname + "/out/" + archiveName);
const archive = archiver("zip", {
zlib: { level: 9 } // Sets the compression level.
});
archive.pipe(output);
archive.directory("dist/", false);
archive.finalize();
const utilFilesAndDirectories = fs.existsSync(__dirname + "/utils") ? fs.readdirSync(__dirname + "/utils") : [];
const utilFiles = [];
utilFilesAndDirectories.forEach((entry) => {
if (fs.statSync(__dirname + "/utils/" + entry).isFile()) utilFiles.push(entry);
})
// Transpile utilities using esbuild
esbuild.build({
entryPoints: [utilFiles.map((filename) => "utils/" + filename)],
bundle: false,
outdir: "dist",
platform: "node",
target: "es2017",
}).then(() => {
const archiveName = "svr.js." + version.toLowerCase().replace(/[^0-9a-z]+/g,".") + ".zip";
const output = fs.createWriteStream(__dirname + "/out/" + archiveName);
const archive = archiver("zip", {
zlib: { level: 9 } // Sets the compression level.
});
archive.pipe(output);
archive.directory("dist/", false);
archive.finalize();
}).catch((err) => {
throw err;
})
}).catch((err) => {
throw err;
});