2020-02-22 23:24:19 +01:00
|
|
|
const { readdir, stat, copyFile, ensureDir } = require("fs-extra")
|
2020-02-03 10:24:25 +01:00
|
|
|
const { constants } = require("fs")
|
|
|
|
const { join, basename } = require("path")
|
|
|
|
const serverConfig = require("../../server/config")()
|
2019-09-29 07:40:06 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const packagesFolder = ".."
|
2019-09-29 07:40:06 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const jsFile = dir => join(dir, "index.js")
|
|
|
|
const jsMapFile = dir => join(dir, "index.js.map")
|
|
|
|
const sourceJs = jsFile("dist")
|
|
|
|
const sourceJsMap = jsMapFile("dist")
|
|
|
|
const componentsFile = "components.json"
|
2019-10-07 07:03:41 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const appPackages = join(
|
|
|
|
packagesFolder,
|
|
|
|
"server",
|
2020-04-29 21:29:42 +02:00
|
|
|
resolve(homedir(), ".budibase")
|
2020-02-03 10:24:25 +01:00
|
|
|
)
|
2019-09-29 07:40:06 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const publicMain = appName =>
|
|
|
|
join(
|
|
|
|
appPackages,
|
|
|
|
appName,
|
|
|
|
"public",
|
|
|
|
"main",
|
|
|
|
"lib",
|
|
|
|
"node_modules",
|
|
|
|
"@budibase",
|
|
|
|
"standard-components"
|
|
|
|
)
|
|
|
|
const publicUnauth = appName =>
|
|
|
|
join(
|
|
|
|
appPackages,
|
|
|
|
appName,
|
|
|
|
"public",
|
|
|
|
"unauthenticated",
|
|
|
|
"lib",
|
|
|
|
"node_modules",
|
|
|
|
"@budibase",
|
|
|
|
"standard-components"
|
|
|
|
)
|
|
|
|
const nodeModulesDist = appName =>
|
|
|
|
join(
|
|
|
|
appPackages,
|
|
|
|
appName,
|
|
|
|
"node_modules",
|
|
|
|
"@budibase",
|
|
|
|
"standard-components",
|
|
|
|
"dist"
|
|
|
|
)
|
2020-02-18 16:41:44 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const nodeModules = appName =>
|
|
|
|
join(appPackages, appName, "node_modules", "@budibase", "standard-components")
|
2019-10-07 07:03:41 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
;(async () => {
|
|
|
|
const apps = await readdir(appPackages)
|
2019-09-29 07:40:06 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const copySource = file => async toDir => {
|
2020-02-22 23:24:19 +01:00
|
|
|
await ensureDir(toDir)
|
2020-02-03 10:24:25 +01:00
|
|
|
const dest = join(toDir, basename(file))
|
|
|
|
try {
|
|
|
|
await copyFile(file, dest, constants.COPYFILE_FICLONE)
|
|
|
|
console.log(`COPIED ${file} to ${dest}`)
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`COPY FAILED ${file} to ${dest}: ${e}`)
|
2019-09-29 07:40:06 +02:00
|
|
|
}
|
2020-02-03 10:24:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const copySourceJs = copySource(sourceJs)
|
|
|
|
const copySourceJsMap = copySource(sourceJsMap)
|
|
|
|
const copyComponentsJson = copySource(componentsFile)
|
|
|
|
|
|
|
|
for (let app of apps) {
|
|
|
|
if (app === ".data") continue
|
|
|
|
if (!(await stat(join(appPackages, app))).isDirectory()) continue
|
|
|
|
|
|
|
|
await copySourceJs(nodeModulesDist(app))
|
|
|
|
await copySourceJsMap(nodeModulesDist(app))
|
|
|
|
|
|
|
|
await copyComponentsJson(nodeModules(app))
|
|
|
|
|
|
|
|
await copySourceJs(join(publicMain(app), "dist"))
|
|
|
|
await copySourceJsMap(join(publicMain(app), "dist"))
|
2019-09-29 07:40:06 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
await copySourceJs(join(publicUnauth(app), "dist"))
|
|
|
|
await copySourceJsMap(join(publicUnauth(app), "dist"))
|
|
|
|
}
|
|
|
|
})()
|