Making build script into a module, so that it can be used in a specialised server build which also builds the thread scripts as required for worker-farm.
This commit is contained in:
parent
91c1aaffa7
commit
4f7e56fed9
|
@ -10,7 +10,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"prebuild": "rimraf dist/",
|
||||
"build": "../../scripts/build.js",
|
||||
"build": "./scripts/build.js",
|
||||
"tsbuild": "tsc -p tsconfig.build.json && mv dist/src/* dist/ && rimraf dist/src/",
|
||||
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
|
||||
"debug": "yarn build && node --expose-gc --inspect=9222 dist/index.js",
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/node
|
||||
const { join } = require("path")
|
||||
const fs = require("fs")
|
||||
const coreBuild = require("../../../scripts/build")
|
||||
|
||||
const dir = join(__dirname, "..")
|
||||
const entryPath = join(dir, "src")
|
||||
const outfilePath = join(dir, "dist")
|
||||
|
||||
const ignoredFiles = ["definitions", "index", "utils"]
|
||||
const threadNames = fs
|
||||
.readdirSync(join(dir, "src", "threads"))
|
||||
.filter(path => !ignoredFiles.find(file => path.includes(file)))
|
||||
.map(path => path.replace(".ts", ""))
|
||||
const files = [
|
||||
{
|
||||
entry: join(entryPath, "index.ts"),
|
||||
out: join(outfilePath, "index.js"),
|
||||
},
|
||||
]
|
||||
for (let name of threadNames) {
|
||||
files.push({
|
||||
entry: join(entryPath, "threads", `${name}.ts`),
|
||||
out: join(outfilePath, `${name}.js`),
|
||||
})
|
||||
}
|
||||
|
||||
for (let file of files) {
|
||||
coreBuild(file.entry, file.out)
|
||||
}
|
|
@ -5,6 +5,7 @@ import authorized from "../../middleware/authorized"
|
|||
import { permissions } from "@budibase/backend-core"
|
||||
import env from "../../environment"
|
||||
import { paramResource } from "../../middleware/resourceId"
|
||||
import { devClientLibPath } from "../../utilities/fileSystem"
|
||||
const { BUILDER, PermissionType, PermissionLevel } = permissions
|
||||
|
||||
const router: Router = new Router()
|
||||
|
@ -17,7 +18,8 @@ router.param("file", async (file: any, ctx: any, next: any) => {
|
|||
}
|
||||
// test serves from require
|
||||
if (env.isTest()) {
|
||||
ctx.devPath = require.resolve("@budibase/client").split(ctx.file)[0]
|
||||
const path = devClientLibPath()
|
||||
ctx.devPath = path.split(ctx.file)[0]
|
||||
} else if (env.isDev()) {
|
||||
// Serving the client library from your local dir in dev
|
||||
ctx.devPath = budibaseTempDir()
|
||||
|
|
|
@ -6,6 +6,10 @@ import { resolve } from "../centralPath"
|
|||
import env from "../../environment"
|
||||
import { TOP_LEVEL_PATH } from "./filesystem"
|
||||
|
||||
export function devClientLibPath() {
|
||||
return require.resolve("@budibase/client")
|
||||
}
|
||||
|
||||
/**
|
||||
* Client library paths in the object store:
|
||||
* Previously, the entire client library package was downloaded from NPM
|
||||
|
@ -89,9 +93,10 @@ export async function updateClientLibrary(appId: string) {
|
|||
let manifest, client
|
||||
|
||||
if (env.isDev()) {
|
||||
const path = devClientLibPath()
|
||||
// Load the symlinked version in dev which is always the newest
|
||||
manifest = require.resolve("@budibase/client/manifest.json")
|
||||
client = require.resolve("@budibase/client")
|
||||
manifest = join(path, "manifest.json")
|
||||
client = path
|
||||
} else {
|
||||
// Load the bundled version in prod
|
||||
manifest = resolve(TOP_LEVEL_PATH, "client", "manifest.json")
|
||||
|
|
|
@ -4,53 +4,59 @@ const start = Date.now()
|
|||
|
||||
const glob = require("glob")
|
||||
const fs = require("fs")
|
||||
var path = require("path")
|
||||
const path = require("path")
|
||||
|
||||
const { build } = require("esbuild")
|
||||
const sveltePlugin = require("esbuild-svelte")
|
||||
|
||||
const { default: NodeResolve } = require("@esbuild-plugins/node-resolve")
|
||||
|
||||
const entry = process.argv[2] || "./src/index.ts"
|
||||
const outfile = `dist/${entry.split("/").pop().replace(".ts", ".js")}`
|
||||
console.log(`Building from ${entry} to ${outfile}`)
|
||||
|
||||
const sharedConfig = {
|
||||
entryPoints: [entry],
|
||||
bundle: true,
|
||||
minify: true,
|
||||
tsconfig: `tsconfig.build.json`,
|
||||
plugins: [
|
||||
sveltePlugin(),
|
||||
NodeResolve({
|
||||
extensions: [".ts", ".js"],
|
||||
onResolved: resolved => {
|
||||
if (resolved.includes("node_modules")) {
|
||||
return {
|
||||
external: true,
|
||||
function runBuild(entry, outfile) {
|
||||
const sharedConfig = {
|
||||
entryPoints: [entry],
|
||||
bundle: true,
|
||||
minify: true,
|
||||
tsconfig: `tsconfig.build.json`,
|
||||
plugins: [
|
||||
sveltePlugin(),
|
||||
NodeResolve({
|
||||
extensions: [".ts", ".js"],
|
||||
onResolved: resolved => {
|
||||
if (resolved.includes("node_modules")) {
|
||||
return {
|
||||
external: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
return resolved
|
||||
},
|
||||
}),
|
||||
],
|
||||
target: "node14",
|
||||
preserveSymlinks: true,
|
||||
return resolved
|
||||
},
|
||||
}),
|
||||
],
|
||||
target: "node14",
|
||||
preserveSymlinks: true,
|
||||
}
|
||||
|
||||
build({
|
||||
...sharedConfig,
|
||||
platform: "node",
|
||||
outfile,
|
||||
}).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`
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
build({
|
||||
...sharedConfig,
|
||||
platform: "node",
|
||||
outfile,
|
||||
}).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`
|
||||
)
|
||||
})
|
||||
})
|
||||
if (require.main === module) {
|
||||
const entry = process.argv[2] || "./src/index.ts"
|
||||
const outfile = `dist/${entry.split("/").pop().replace(".ts", ".js")}`
|
||||
runBuild(entry, outfile)
|
||||
} else {
|
||||
module.exports = runBuild
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue