#!/usr/bin/env node // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // This is done in a node script for 2 reasons // 1. Potability: I will need to run this in windows // 2. Errors. If the main command fails, the script needs to clean up // but and exit with this error. // this _can_ be done from bash or shell, // but now the portability problems loom large. const { spawn, execSync } = require('child_process') const pipeStdIo = { stdio: [process.stdin, process.stdout, process.stderr] } // Always clear storage so the latest versions are published // I am not worried about _what_ version number is published // Only that it is the latest code execSync('rm -rf verdaccio/storage/@aws-crypto') // Start verdaccio in the background const verdaccio = spawn('npx', ['verdaccio', '-c', 'verdaccio/config.yaml'], pipeStdIo) .on('error', e => { throw e }) .on('close', (code, signal) => { console.log(`verdaccio process closed with code ${code} or signal ${signal}`); }) .on('exit', (code, signal) => { console.log(`verdaccio process exited with code ${code} or signal ${signal}`); }) // Publish all changed packages the local verdaccio server. // Anything that has not been changed will match what is in npm const args = [ 'lerna', 'publish', 'prepatch', '--registry', 'http://localhost:4873/', '--yes', '--no-changelog', '--no-git-tag-version', '--no-push', '--no-git-reset', '--preid', 'ci', '--no-verify-access', '--force-publish', '--loglevel', 'warn', '--no-progress' ] timeout = 60000 * 2 console.log(`Starting lerna publish with timeout of ${timeout}`); spawn('npx', args, { stdio: [process.stdin, process.stdout, process.stderr], timeout: timeout }).on('close', (code, signal) => { console.log(`lerna terminated due to receipt of signal ${signal} or code ${code}`); // The above command will make some modifications, // Roll them back // Ideally, we would find a way to not have to do this execSync('git checkout -- modules/**/package.json') execSync('git checkout -- lerna.json') execSync('git restore package-lock.json') // Kill the background verdaccio server verdaccioKilledStatus = verdaccio.kill() console.log(`killing Verdaccio returned ${verdaccioKilledStatus}`); // If this command had an error, // we need to forward this. // Otherwise the entire CI build may think that things succeeded. if (code !== 0) throw Error(`Exit code: ${code}`) process.exit() })