2023-04-24 19:24:09 +02:00
|
|
|
#!/usr/bin/node
|
|
|
|
|
2023-03-02 16:34:52 +01:00
|
|
|
const start = Date.now()
|
|
|
|
|
2023-03-02 17:03:56 +01:00
|
|
|
const glob = require("glob")
|
|
|
|
const fs = require("fs")
|
2023-04-27 20:00:01 +02:00
|
|
|
const path = require("path")
|
2023-03-02 17:03:56 +01:00
|
|
|
|
2023-03-02 16:34:52 +01:00
|
|
|
const { build } = require("esbuild")
|
|
|
|
|
|
|
|
const { default: NodeResolve } = require("@esbuild-plugins/node-resolve")
|
|
|
|
|
2023-05-03 13:38:23 +02:00
|
|
|
var argv = require("minimist")(process.argv.slice(2))
|
|
|
|
|
2023-04-27 20:00:01 +02:00
|
|
|
function runBuild(entry, outfile) {
|
2023-05-03 13:38:23 +02:00
|
|
|
const isDev = process.env.NODE_ENV !== "production"
|
2023-05-03 15:04:54 +02:00
|
|
|
const tsconfig = argv["p"] || `tsconfig.build.json`
|
|
|
|
|
2023-04-27 20:00:01 +02:00
|
|
|
const sharedConfig = {
|
|
|
|
entryPoints: [entry],
|
|
|
|
bundle: true,
|
2023-05-03 13:38:23 +02:00
|
|
|
minify: !isDev,
|
2023-05-03 18:15:57 +02:00
|
|
|
sourcemap: isDev,
|
2023-05-03 15:04:54 +02:00
|
|
|
tsconfig,
|
2023-04-27 20:00:01 +02:00
|
|
|
plugins: [
|
|
|
|
NodeResolve({
|
|
|
|
extensions: [".ts", ".js"],
|
|
|
|
onResolved: resolved => {
|
|
|
|
if (resolved.includes("node_modules")) {
|
|
|
|
return {
|
|
|
|
external: true,
|
|
|
|
}
|
2023-03-02 16:34:52 +01:00
|
|
|
}
|
2023-04-27 20:00:01 +02:00
|
|
|
return resolved
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
target: "node14",
|
|
|
|
preserveSymlinks: true,
|
2023-05-03 18:15:57 +02:00
|
|
|
loader: {
|
|
|
|
".svelte": "copy",
|
|
|
|
},
|
2023-04-27 20:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
build({
|
|
|
|
...sharedConfig,
|
|
|
|
platform: "node",
|
2023-05-03 15:04:54 +02:00
|
|
|
outfile,
|
2023-04-27 20:00:01 +02:00
|
|
|
}).then(() => {
|
|
|
|
glob(`${process.cwd()}/src/**/*.hbs`, {}, (err, files) => {
|
|
|
|
for (const file of files) {
|
|
|
|
fs.copyFileSync(file, `${process.cwd()}/dist/${path.basename(file)}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
"\x1b[32m%s\x1b[0m",
|
|
|
|
`Build successfully in ${(Date.now() - start) / 1000} seconds`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2023-03-02 16:34:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-27 20:00:01 +02:00
|
|
|
if (require.main === module) {
|
2023-05-03 13:38:23 +02:00
|
|
|
const entry = argv["e"] || "./src/index.ts"
|
2023-05-03 16:45:29 +02:00
|
|
|
const outfile = `dist/${entry.split("/").pop().replace(".ts", ".js")}`
|
|
|
|
runBuild(entry, outfile)
|
2023-04-27 20:00:01 +02:00
|
|
|
} else {
|
|
|
|
module.exports = runBuild
|
|
|
|
}
|