From a3dfecc2bb28619fa30418a9084cc76935da83b9 Mon Sep 17 00:00:00 2001 From: Benjamin <166110368+BenjaminPabst@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:41:30 +0100 Subject: [PATCH] feat: implemented build-copy command (#617) * feat: implemented build-copy command --- .gitignore | 2 ++ copy-build.js | 27 +++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 copy-build.js diff --git a/.gitignore b/.gitignore index 42e7f14bc..86ad33313 100644 --- a/.gitignore +++ b/.gitignore @@ -140,3 +140,5 @@ dist libs/angular-accelerator/tmp/ libs/portal-integration-angular/tmp/ + +.copy-build-to \ No newline at end of file diff --git a/copy-build.js b/copy-build.js new file mode 100644 index 000000000..4aee1c920 --- /dev/null +++ b/copy-build.js @@ -0,0 +1,27 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +// Define the path to the .copy-build-to file +const copyBuildToFile = path.join(__dirname, '.copy-build-to'); + +// Check if the .copy-build-to file exists +if (!fs.existsSync(copyBuildToFile)) { + // Create the .copy-build-to file with instructions + fs.writeFileSync(copyBuildToFile, 'Enter the paths where you want to copy the compiled output, each on a new line.\nExample:\n/path/to/destination1/node_modules/@onecx\n/path/to/destination2/node_modules/@onecx\n'); + console.log('.copy-build-to file created. Please add the paths where you want to copy the compiled output, each on a new line.'); + process.exit(0); +} + +// Read the paths from the .copy-build-to file +const paths = fs.readFileSync(copyBuildToFile, 'utf-8').split('\n').filter(Boolean); + +// Define the source directory +const sourceDir = path.join(__dirname, 'dist'); + +// Copy the compiled output to each path +paths.forEach(destination => { + const destDir = path.resolve(destination); + execSync(`cp -r ${sourceDir}/libs/* ${destDir}`, { stdio: 'inherit' }); + console.log(`Copied compiled output to ${destDir}`); +}); \ No newline at end of file diff --git a/package.json b/package.json index 76c831ac9..1319d4e0b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "sass": "npx sass libs/portal-integration-angular/assets/styles.scss libs/portal-integration-angular/assets/output.css", "postinstall": "mkdir -p .nx", - "build": "nx run-many -t build" + "build": "nx run-many -t build", + "build-copy": "npm run build && node copy-build.js" }, "private": true, "dependencies": {