import concurrently from "concurrently" ; import { join } from "path" ; import { rm , mkdir } from "shelljs" ; const repoRoot = join ( __dirname , "../../../../" ) ; main ( ) . catch ( e => { console . error ( e ) ; process . exit ( 1 ) ; } ) ; async function main ( ) { let mode = "build" ; if ( process . argv . includes ( "start" ) ) { mode = "start" ; } else if ( process . argv . includes ( "release" ) ) { mode = "release" ; } let outputDir ; if ( mode === "build" || mode === "start" ) { const MX_PROJECT_PATH = process . env . MX_PROJECT_PATH ; outputDir = MX_PROJECT_PATH ? MX_PROJECT_PATH : join ( __dirname , "../tests/testProject" ) ; const toRemoveDirs = [ join ( outputDir , "themesource/atlas_core" ) ] ; rm ( "-rf" , toRemoveDirs ) ; console . info ( `Ensured the directories ${ toRemoveDirs . join ( ", " ) } are removed from your Mendix project` ) ; } else if ( mode === "release" ) { outputDir = join ( __dirname , "../dist" ) ; rm ( "-rf" , outputDir ) ; console . info ( `Ensured the directory ${ outputDir } is removed` ) ; } if ( outputDir ) { mkdir ( "-p" , join ( outputDir , "themesource/atlas_core" ) ) ; await copyStylesAndAssets ( mode === "start" , outputDir ) ; } } async function copyStylesAndAssets ( watchMode , destination ) { console . info ( `Copying styles and assets...` ) ; const watchArg = watchMode ? "--watch" : "" ; try { await concurrently ( [ { name : "web-themesource-core" , command : `copy-and-watch ${ watchArg } "${ join ( repoRoot , "packages/theming/atlas" , "src/themesource/atlas_core/web/**/*" ) }" "${ join ( destination , "themesource/atlas_core/web" ) }"` } , { name : "public-themesource-core" , command : `copy-and-watch ${ watchArg } "${ join ( repoRoot , "packages/theming/atlas" , "src/themesource/atlas_core/public/**/*" ) }" "${ join ( destination , "themesource/atlas_core/public" ) }"` } , { name : "native-typescript" , command : `tsc ${ watchArg } --project tsconfig-native.json --outDir "${ destination }"` } , { name : "native-design-properties-and-manifest" , command : `copy-and-watch ${ watchArg } "${ join ( repoRoot , "packages/theming/atlas" , "src/themesource/atlas_core/native/**/*.json" ) }" "${ join ( destination , "themesource/atlas_core/native" ) }"` } ] , { killOthers : [ "failure" ] } ) ; console . log ( "Copying styles and assets has completed successfully" ) ; } catch ( commands ) { const commandInfo = commands . map ( ( command ) => `{ name: ${ command . command . name }, exit code: ${ command . exitCode }}` ) ; throw new Error ( `One or more commands failed:\n${ commandInfo . join ( "\n" ) }` ) ; } }