|
| 1 | +const { execSync } = require('child_process'); |
| 2 | +const path = require('path'); |
| 3 | +const fs = require('fs'); |
| 4 | +const readline = require('readline'); |
| 5 | + |
| 6 | +try { |
| 7 | + const angularSdkPath = process.cwd(); |
| 8 | + console.log(`angular-sdk path: ${angularSdkPath}`); |
| 9 | + |
| 10 | + // Create readline interface to ask for angular-sdk-components path |
| 11 | + const rl = readline.createInterface({ |
| 12 | + input: process.stdin, |
| 13 | + output: process.stdout |
| 14 | + }); |
| 15 | + |
| 16 | + rl.question('Please enter the absolute path of angular-sdk-components project: ', componentsProjectPathInput => { |
| 17 | + rl.close(); |
| 18 | + const componentsProjectPath = path.resolve(componentsProjectPathInput); |
| 19 | + const distDir = path.join(componentsProjectPath, 'dist', 'angular-sdk-components'); |
| 20 | + |
| 21 | + // Delete existing dist folder before build |
| 22 | + if (fs.existsSync(distDir)) { |
| 23 | + console.log(`---- Removing existing dist folder: ${distDir} ----`); |
| 24 | + fs.rmSync(distDir, { recursive: true, force: true }); |
| 25 | + } |
| 26 | + |
| 27 | + console.log(`---- Building angular-sdk-components at: ${componentsProjectPath} ----`); |
| 28 | + execSync(`cd ${componentsProjectPath} && ng build angular-sdk-components`, { stdio: 'inherit' }); |
| 29 | + |
| 30 | + console.log(`---- Packing npm package in: ${distDir} ----`); |
| 31 | + execSync(`cd ${distDir} && npm pack`, { stdio: 'inherit' }); |
| 32 | + |
| 33 | + // Find the generated .tgz file |
| 34 | + const tgzFile = fs.readdirSync(distDir).find(file => file.endsWith('.tgz')); |
| 35 | + if (!tgzFile) { |
| 36 | + throw new Error('No .tgz file found in dist folder!'); |
| 37 | + } |
| 38 | + |
| 39 | + const tgzPath = path.join(distDir, tgzFile); |
| 40 | + const targetPath = path.join(angularSdkPath, tgzFile); |
| 41 | + |
| 42 | + // Delete old .tgz file if exists in angular-sdk folder |
| 43 | + const existingTgz = fs.readdirSync(angularSdkPath).find(file => file.endsWith('.tgz')); |
| 44 | + if (existingTgz) { |
| 45 | + console.log(`---- Removing old package: ${existingTgz} ----`); |
| 46 | + fs.unlinkSync(path.join(angularSdkPath, existingTgz)); |
| 47 | + } |
| 48 | + |
| 49 | + console.log(`---- Copying ${tgzFile} to angular-sdk folder: ${angularSdkPath} ----`); |
| 50 | + fs.copyFileSync(tgzPath, targetPath); |
| 51 | + |
| 52 | + console.log('---- Installing package in angular-sdk ----'); |
| 53 | + execSync(`cd ${angularSdkPath} && npm install ./${tgzFile}`, { stdio: 'inherit' }); |
| 54 | + console.log("Done!!! 'angular-sdk' now uses local build of angular-sdk-components."); |
| 55 | + }); |
| 56 | +} catch (error) { |
| 57 | + console.error('Error:', error.message); |
| 58 | + process.exit(1); |
| 59 | +} |
0 commit comments