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 // Bundle the source and copy the assets using esbuild and esbuild-plugin-copy
esbuild.build({ esbuild.build({
entryPoints: ["src/index.js"], // Your entry file entryPoints: ["src/index.js"],
bundle: true, bundle: true,
outfile: "dist/svr.js", // Output file outfile: "dist/svr.js",
platform: "node", platform: "node",
target: "es2017", target: "es2017",
plugins: [ plugins: [
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
from: ["./utils/**/*"],
to: ["./dist"],
}
}),
esbuildCopyPlugin.copy({ esbuildCopyPlugin.copy({
resolveFrom: __dirname, resolveFrom: __dirname,
assets: { assets: {
@ -156,6 +149,20 @@ esbuild.build({
}) })
], ],
}).then(() => { }).then(() => {
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 archiveName = "svr.js." + version.toLowerCase().replace(/[^0-9a-z]+/g,".") + ".zip";
const output = fs.createWriteStream(__dirname + "/out/" + archiveName); const output = fs.createWriteStream(__dirname + "/out/" + archiveName);
const archive = archiver("zip", { const archive = archiver("zip", {
@ -164,6 +171,9 @@ esbuild.build({
archive.pipe(output); archive.pipe(output);
archive.directory("dist/", false); archive.directory("dist/", false);
archive.finalize(); archive.finalize();
}).catch((err) => {
throw err;
})
}).catch((err) => { }).catch((err) => {
throw err; throw err;
}); });