import * as child_process from "child_process" ; import * as fse from "fs-extra" ; import * as path from "path" ; function main ( ) { let lernaOutput ; try { lernaOutput = JSON . parse ( child_process . execSync ( "npx lerna list --all --json" ) . toString ( ) ) ; if ( ! Array . isArray ( lernaOutput ) ) { throw new Error ( "failed to get package information" ) ; } } catch ( e ) { console . error ( e . toString ( ) ) ; process . exit ( - 1 ) ; } const analysesDestPath = path . join ( process . cwd ( ) , "artifacts/bundleAnalysis" ) ; lernaOutput . forEach ( ( pkg ) => { if ( pkg . location === undefined ) { console . error ( "missing location in lerna package entry" ) ; process . exit ( - 1 ) ; } const packageAnalysisPath = path . join ( pkg . location , "bundleAnalysis" ) ; if ( fse . existsSync ( packageAnalysisPath ) ) { try { console . log ( `found bundleAnalysis for ${ pkg . name }` ) ; fse . copySync ( packageAnalysisPath , path . join ( analysesDestPath , pkg . name ) , { recursive : true } ) ; } catch ( e ) { console . error ( e . toString ( ) ) ; process . exit ( - 1 ) ; } } } ) ; } main ( ) ;