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": {
|
"scripts": {
|
||||||
"prebuild": "rimraf dist/",
|
"prebuild": "rimraf dist/",
|
||||||
"build": "../../scripts/build.js",
|
"build": "./scripts/build.js",
|
||||||
"tsbuild": "tsc -p tsconfig.build.json && mv dist/src/* dist/ && rimraf dist/src/",
|
"tsbuild": "tsc -p tsconfig.build.json && mv dist/src/* dist/ && rimraf dist/src/",
|
||||||
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
|
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
|
||||||
"debug": "yarn build && node --expose-gc --inspect=9222 dist/index.js",
|
"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 { permissions } from "@budibase/backend-core"
|
||||||
import env from "../../environment"
|
import env from "../../environment"
|
||||||
import { paramResource } from "../../middleware/resourceId"
|
import { paramResource } from "../../middleware/resourceId"
|
||||||
|
import { devClientLibPath } from "../../utilities/fileSystem"
|
||||||
const { BUILDER, PermissionType, PermissionLevel } = permissions
|
const { BUILDER, PermissionType, PermissionLevel } = permissions
|
||||||
|
|
||||||
const router: Router = new Router()
|
const router: Router = new Router()
|
||||||
|
@ -17,7 +18,8 @@ router.param("file", async (file: any, ctx: any, next: any) => {
|
||||||
}
|
}
|
||||||
// test serves from require
|
// test serves from require
|
||||||
if (env.isTest()) {
|
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()) {
|
} else if (env.isDev()) {
|
||||||
// Serving the client library from your local dir in dev
|
// Serving the client library from your local dir in dev
|
||||||
ctx.devPath = budibaseTempDir()
|
ctx.devPath = budibaseTempDir()
|
||||||
|
|
|
@ -6,6 +6,10 @@ import { resolve } from "../centralPath"
|
||||||
import env from "../../environment"
|
import env from "../../environment"
|
||||||
import { TOP_LEVEL_PATH } from "./filesystem"
|
import { TOP_LEVEL_PATH } from "./filesystem"
|
||||||
|
|
||||||
|
export function devClientLibPath() {
|
||||||
|
return require.resolve("@budibase/client")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client library paths in the object store:
|
* Client library paths in the object store:
|
||||||
* Previously, the entire client library package was downloaded from NPM
|
* Previously, the entire client library package was downloaded from NPM
|
||||||
|
@ -89,9 +93,10 @@ export async function updateClientLibrary(appId: string) {
|
||||||
let manifest, client
|
let manifest, client
|
||||||
|
|
||||||
if (env.isDev()) {
|
if (env.isDev()) {
|
||||||
|
const path = devClientLibPath()
|
||||||
// Load the symlinked version in dev which is always the newest
|
// Load the symlinked version in dev which is always the newest
|
||||||
manifest = require.resolve("@budibase/client/manifest.json")
|
manifest = join(path, "manifest.json")
|
||||||
client = require.resolve("@budibase/client")
|
client = path
|
||||||
} else {
|
} else {
|
||||||
// Load the bundled version in prod
|
// Load the bundled version in prod
|
||||||
manifest = resolve(TOP_LEVEL_PATH, "client", "manifest.json")
|
manifest = resolve(TOP_LEVEL_PATH, "client", "manifest.json")
|
||||||
|
|
|
@ -4,53 +4,59 @@ const start = Date.now()
|
||||||
|
|
||||||
const glob = require("glob")
|
const glob = require("glob")
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
var path = require("path")
|
const path = require("path")
|
||||||
|
|
||||||
const { build } = require("esbuild")
|
const { build } = require("esbuild")
|
||||||
const sveltePlugin = require("esbuild-svelte")
|
const sveltePlugin = require("esbuild-svelte")
|
||||||
|
|
||||||
const { default: NodeResolve } = require("@esbuild-plugins/node-resolve")
|
const { default: NodeResolve } = require("@esbuild-plugins/node-resolve")
|
||||||
|
|
||||||
const entry = process.argv[2] || "./src/index.ts"
|
function runBuild(entry, outfile) {
|
||||||
const outfile = `dist/${entry.split("/").pop().replace(".ts", ".js")}`
|
const sharedConfig = {
|
||||||
console.log(`Building from ${entry} to ${outfile}`)
|
entryPoints: [entry],
|
||||||
|
bundle: true,
|
||||||
const sharedConfig = {
|
minify: true,
|
||||||
entryPoints: [entry],
|
tsconfig: `tsconfig.build.json`,
|
||||||
bundle: true,
|
plugins: [
|
||||||
minify: true,
|
sveltePlugin(),
|
||||||
tsconfig: `tsconfig.build.json`,
|
NodeResolve({
|
||||||
plugins: [
|
extensions: [".ts", ".js"],
|
||||||
sveltePlugin(),
|
onResolved: resolved => {
|
||||||
NodeResolve({
|
if (resolved.includes("node_modules")) {
|
||||||
extensions: [".ts", ".js"],
|
return {
|
||||||
onResolved: resolved => {
|
external: true,
|
||||||
if (resolved.includes("node_modules")) {
|
}
|
||||||
return {
|
|
||||||
external: true,
|
|
||||||
}
|
}
|
||||||
}
|
return resolved
|
||||||
return resolved
|
},
|
||||||
},
|
}),
|
||||||
}),
|
],
|
||||||
],
|
target: "node14",
|
||||||
target: "node14",
|
preserveSymlinks: true,
|
||||||
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({
|
if (require.main === module) {
|
||||||
...sharedConfig,
|
const entry = process.argv[2] || "./src/index.ts"
|
||||||
platform: "node",
|
const outfile = `dist/${entry.split("/").pop().replace(".ts", ".js")}`
|
||||||
outfile,
|
runBuild(entry, outfile)
|
||||||
}).then(() => {
|
} else {
|
||||||
glob(`${process.cwd()}/src/**/*.hbs`, {}, (err, files) => {
|
module.exports = runBuild
|
||||||
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`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
Loading…
Reference in New Issue