From 4cd2de5df3629c19dd10bc61e8281d6b9a3816e8 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Thu, 12 Sep 2019 15:04:07 +0100 Subject: [PATCH] publish:dev script to help client development --- packages/client/.vscode/launch.json | 14 ++++++++ packages/client/package.json | 4 ++- packages/client/scripts/publishDev.js | 49 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 packages/client/.vscode/launch.json create mode 100644 packages/client/scripts/publishDev.js diff --git a/packages/client/.vscode/launch.json b/packages/client/.vscode/launch.json new file mode 100644 index 0000000000..ef01de280f --- /dev/null +++ b/packages/client/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Publish Dev", + "program": "${workspaceFolder}/scripts/publishDev.js" + } + ] +} \ No newline at end of file diff --git a/packages/client/package.json b/packages/client/package.json index 3d53933f11..f3afea48f4 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -6,7 +6,8 @@ "module": "dist/budibase-client.js", "scripts": { "build": "rollup -c", - "test": "jest" + "test": "jest", + "publish:dev": "yarn build && node ./scripts/publishDev.js" }, "jest": { "globals": { @@ -46,6 +47,7 @@ "@babel/preset-env": "^7.5.5", "@babel/runtime": "^7.5.5", "babel-jest": "^24.8.0", + "fs-extra": "^8.1.0", "jest": "^24.8.0", "rollup": "^1.12.0", "rollup-plugin-commonjs": "^10.0.0", diff --git a/packages/client/scripts/publishDev.js b/packages/client/scripts/publishDev.js new file mode 100644 index 0000000000..6d58a29f29 --- /dev/null +++ b/packages/client/scripts/publishDev.js @@ -0,0 +1,49 @@ +const { readdir, stat, copyFile } = require("fs-extra"); +const { constants } = require("fs"); +const { join } = require("path"); + +const packagesFolder = ".."; + +const jsFile = dir => join(dir, "budibase-client.js"); +const jsMapFile = dir => join(dir, "budibase-client.js.map"); +const sourceJs = jsFile("dist"); +const sourceJsMap = jsMapFile("dist"); + +const appPackages = join(packagesFolder, "server", "appPackages"); + +const publicMain = appName => join(appPackages, appName, "public", "main"); +const publicUnauth = appName => join(appPackages, appName, "public", "unauthenticated"); +const nodeModules = appName => join(appPackages, appName, "node_modules", "@budibase", "client", "dist"); + +(async () => { + + const apps = await readdir(appPackages); + + const copySource = file => async toDir => { + const dest = jsFile(toDir); + try { + await copyFile(file, dest, constants.COPYFILE_FICLONE); + console.log(`COPIED ${file} to ${dest}`); + } catch(e) { + console.log(`COPY FAILED ${file} to ${dest}: ${e}`); + } + } + + const copySourceJs = copySource(sourceJs); + const copySourceJsMap = copySource(sourceJsMap); + + + for(let app of apps) { + if(!(await stat(join(appPackages, app))).isDirectory()) continue; + + await copySourceJs(nodeModules(app)); + await copySourceJsMap(nodeModules(app)); + + await copySourceJs(publicMain(app)); + await copySourceJsMap(publicMain(app)); + + await copySourceJs(publicUnauth(app)); + await copySourceJsMap(publicUnauth(app)); + } + +})(); \ No newline at end of file