|
| 1 | +const { spawnSync } = require('child_process'); |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +const version = process.argv[2] || 'latest'; |
| 6 | + |
| 7 | +const tmpDir = path.join(__dirname, '..', 'tmp'); |
| 8 | +fs.mkdirSync(tmpDir, { recursive: true }); |
| 9 | +process.chdir(tmpDir); |
| 10 | + |
| 11 | +// Delete the previous workspace |
| 12 | +if (fs.existsSync('nx-workspace')) { |
| 13 | + fs.rmSync('nx-workspace', { recursive: true, force: true }); |
| 14 | +} |
| 15 | + |
| 16 | +console.log('Creating Nx Workspace with version:', version); |
| 17 | +executeCommand(`npx --yes create-nx-workspace@${version} --version`); |
| 18 | +console.log('☝️'); |
| 19 | + |
| 20 | +console.log('----- Create Nx Workspace -----'); |
| 21 | +executeCommand( |
| 22 | + `npx create-nx-workspace@${version} --name nx-workspace --preset npm ${ |
| 23 | + version === '16.10.0' ? '--nxCloud=false' : '--nxCloud=skip' |
| 24 | + }` |
| 25 | +); |
| 26 | +process.chdir('nx-workspace'); |
| 27 | + |
| 28 | +fs.writeFileSync('.env', `NX_WORKSPACE_ROOT_PATH=${process.cwd()}`); |
| 29 | + |
| 30 | +console.log('----- Generate lib -----'); |
| 31 | +executeCommand(`npm add -D @nx/node@${version}`); |
| 32 | +executeCommand('npx nx generate @nx/node:init'); |
| 33 | +executeCommand( |
| 34 | + 'npx nx generate @nx/node:library nx-lib --publishable --importPath nx-lib' |
| 35 | +); |
| 36 | + |
| 37 | +console.log('----- Link ngx-deploy-npm -----'); |
| 38 | +executeCommand('npx --yes yalc add ngx-deploy-npm'); |
| 39 | + |
| 40 | +console.log('----- Add ngx-deploy-npm to the workspace -----'); |
| 41 | +executeCommand( |
| 42 | + 'npx nx generate ngx-deploy-npm:install --project nx-lib --distFolderPath dist/nx-lib' |
| 43 | +); |
| 44 | + |
| 45 | +console.log('----- Test the build -----'); |
| 46 | +executeCommand('npx nx deploy nx-lib --dry-run'); |
| 47 | + |
| 48 | +function executeCommand(command) { |
| 49 | + if (process.env.CI !== 'true') { |
| 50 | + console.log(`\x1b[32mExecuting command:\x1b[0m '${command}'`); |
| 51 | + } |
| 52 | + const commandArr = command.split(' '); |
| 53 | + |
| 54 | + spawnSync( |
| 55 | + commandArr[0], |
| 56 | + commandArr |
| 57 | + .slice(1) |
| 58 | + .map(arg => arg.split(' ')) |
| 59 | + .flat(), |
| 60 | + { |
| 61 | + stdio: 'inherit', |
| 62 | + }, |
| 63 | + { |
| 64 | + stdio: 'inherit', |
| 65 | + } |
| 66 | + ); |
| 67 | +} |
0 commit comments