diff --git a/package.json b/package.json index 43bec5d5..fdc4f0de 100755 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "dev:chat_server": "cd packages/chat_server && yarn dev", "dev:marketplace_server": "cd packages/marketplace_server && yarn dev", "dev:server": "cd packages/server && yarn dev", - "dev:client": "cd packages/app && yarn dev" + "dev:client": "cd packages/app && yarn dev", + "post:deploy": "node ./scripts/post-deploy.js" }, "workspaces": [ "packages/**" diff --git a/scripts/post-deploy.js b/scripts/post-deploy.js new file mode 100644 index 00000000..046c268d --- /dev/null +++ b/scripts/post-deploy.js @@ -0,0 +1,45 @@ +const path = require("path") +const fs = require("fs") +const child_process = require("child_process") + +const sharedRootPath = path.resolve(process.cwd(), "shared") + +const rootPath = process.cwd() +const packagesPath = path.resolve(rootPath, "packages") + +const getPackages = require("./utils/getPackages") + +async function main() { + const packages = await getPackages({ + ignore: ["shared", "app", "wrapper"] + }) + + for await (const packageName of packages) { + const packagePath = path.resolve(packagesPath, packageName) + + // copy shared + const sharedPath = path.resolve(packagePath, "src", "_shared") + + if (fs.existsSync(sharedPath)) { + // remove old shared folder + fs.rmdirSync(sharedPath, { recursive: true }) + } + + // copy entire shared folder + // shared/* => /_shared/* + fs.mkdirSync(sharedPath, { recursive: true }) + + await child_process.execSync(`cp -r ${sharedRootPath}/* ${sharedPath} && echo Shared lib copied`, { + cwd: packagePath, + stdio: "inherit" + }) + + // run yarn build + await child_process.execSync("yarn build", { + cwd: packagePath, + stdio: "inherit" + }) + } +} + +main().catch(console.error) \ No newline at end of file