2023-04-25 05:24:09 +12:00
|
|
|
#!/usr/bin/node
|
|
|
|
|
2023-03-03 04:34:52 +13:00
|
|
|
const start = Date.now()
|
|
|
|
|
2023-03-03 05:03:56 +13:00
|
|
|
const glob = require("glob")
|
|
|
|
const fs = require("fs")
|
2023-04-28 06:00:01 +12:00
|
|
|
const path = require("path")
|
2023-03-03 05:03:56 +13:00
|
|
|
|
2023-03-03 04:34:52 +13:00
|
|
|
const { build } = require("esbuild")
|
|
|
|
|
2023-05-25 21:49:38 +12:00
|
|
|
const {
|
|
|
|
default: TsconfigPathsPlugin,
|
|
|
|
} = require("@esbuild-plugins/tsconfig-paths")
|
2023-06-17 01:26:34 +12:00
|
|
|
const { nodeExternalsPlugin } = require("esbuild-node-externals")
|
2023-03-03 04:34:52 +13:00
|
|
|
|
2023-12-05 23:02:44 +13:00
|
|
|
var { argv } = require("yargs")
|
2023-05-03 23:38:23 +12:00
|
|
|
|
2023-10-03 20:49:58 +13:00
|
|
|
function runBuild(entry, outfile) {
|
2023-05-03 23:38:23 +12:00
|
|
|
const isDev = process.env.NODE_ENV !== "production"
|
2023-05-04 01:04:54 +12:00
|
|
|
const tsconfig = argv["p"] || `tsconfig.build.json`
|
2023-07-26 21:32:03 +12:00
|
|
|
const tsconfigPathPluginContent = JSON.parse(
|
|
|
|
fs.readFileSync(tsconfig, "utf-8")
|
|
|
|
)
|
|
|
|
|
2023-08-10 20:48:18 +12:00
|
|
|
if (
|
2023-11-01 02:49:40 +13:00
|
|
|
!fs.existsSync(path.join(__dirname, "../packages/pro/src")) &&
|
2023-08-10 20:48:18 +12:00
|
|
|
tsconfigPathPluginContent.compilerOptions?.paths
|
|
|
|
) {
|
2023-07-26 22:01:05 +12:00
|
|
|
// If we don't have pro, we cannot bundle backend-core.
|
|
|
|
// Otherwise, the main context will not be shared between libraries
|
2023-08-15 04:44:24 +12:00
|
|
|
delete tsconfigPathPluginContent?.compilerOptions?.paths?.[
|
2023-07-26 21:32:03 +12:00
|
|
|
"@budibase/backend-core"
|
|
|
|
]
|
2023-08-15 04:44:24 +12:00
|
|
|
delete tsconfigPathPluginContent?.compilerOptions?.paths?.[
|
2023-07-26 21:32:03 +12:00
|
|
|
"@budibase/backend-core/*"
|
|
|
|
]
|
|
|
|
}
|
2023-05-04 01:04:54 +12:00
|
|
|
|
2023-04-28 06:00:01 +12:00
|
|
|
const sharedConfig = {
|
|
|
|
entryPoints: [entry],
|
2023-10-03 20:49:58 +13:00
|
|
|
bundle: true,
|
2023-05-03 23:38:23 +12:00
|
|
|
minify: !isDev,
|
2023-05-04 04:15:57 +12:00
|
|
|
sourcemap: isDev,
|
2023-05-04 01:04:54 +12:00
|
|
|
tsconfig,
|
2023-07-26 21:32:03 +12:00
|
|
|
plugins: [
|
|
|
|
TsconfigPathsPlugin({ tsconfig: tsconfigPathPluginContent }),
|
|
|
|
nodeExternalsPlugin(),
|
|
|
|
],
|
2023-04-28 06:00:01 +12:00
|
|
|
preserveSymlinks: true,
|
2023-05-04 04:15:57 +12:00
|
|
|
loader: {
|
|
|
|
".svelte": "copy",
|
2024-02-06 22:18:58 +13:00
|
|
|
".ivm.bundle.js": "text",
|
2023-05-04 04:15:57 +12:00
|
|
|
},
|
2023-10-03 20:49:58 +13:00
|
|
|
metafile: true,
|
2023-11-01 03:21:40 +13:00
|
|
|
external: [
|
|
|
|
"deasync",
|
|
|
|
"mock-aws-s3",
|
|
|
|
"nock",
|
|
|
|
"bull",
|
|
|
|
"pouchdb",
|
|
|
|
"bcrypt",
|
|
|
|
"bcryptjs",
|
2023-12-19 06:41:15 +13:00
|
|
|
"graphql/*",
|
2024-02-06 22:18:58 +13:00
|
|
|
"bson",
|
2023-11-01 03:21:40 +13:00
|
|
|
],
|
2024-02-14 05:43:42 +13:00
|
|
|
define: {
|
|
|
|
"process.env.BUNDLED": '"true"',
|
|
|
|
},
|
2023-04-28 06:00:01 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
build({
|
|
|
|
...sharedConfig,
|
|
|
|
platform: "node",
|
2023-05-04 01:04:54 +12:00
|
|
|
outfile,
|
2023-06-17 01:16:32 +12:00
|
|
|
}).then(result => {
|
2023-04-28 06:00:01 +12:00
|
|
|
glob(`${process.cwd()}/src/**/*.hbs`, {}, (err, files) => {
|
|
|
|
for (const file of files) {
|
|
|
|
fs.copyFileSync(file, `${process.cwd()}/dist/${path.basename(file)}`)
|
|
|
|
}
|
|
|
|
|
2023-10-03 20:49:58 +13:00
|
|
|
console.log(
|
|
|
|
"\x1b[32m%s\x1b[0m",
|
|
|
|
`Build successfully in ${(Date.now() - start) / 1000} seconds`
|
|
|
|
)
|
2023-04-28 06:00:01 +12:00
|
|
|
})
|
2023-06-17 01:16:32 +12:00
|
|
|
|
2023-10-03 20:49:58 +13:00
|
|
|
fs.writeFileSync(
|
|
|
|
`dist/${path.basename(outfile)}.meta.json`,
|
|
|
|
JSON.stringify(result.metafile)
|
|
|
|
)
|
2023-04-28 06:00:01 +12:00
|
|
|
})
|
2023-03-03 04:34:52 +13:00
|
|
|
}
|
|
|
|
|
2023-04-28 06:00:01 +12:00
|
|
|
if (require.main === module) {
|
2023-05-03 23:38:23 +12:00
|
|
|
const entry = argv["e"] || "./src/index.ts"
|
2023-05-04 02:45:29 +12:00
|
|
|
const outfile = `dist/${entry.split("/").pop().replace(".ts", ".js")}`
|
|
|
|
runBuild(entry, outfile)
|
2023-04-28 06:00:01 +12:00
|
|
|
} else {
|
|
|
|
module.exports = runBuild
|
|
|
|
}
|