/**
 *  To generate the angular app from the codgen-cli
 * 
 * CONSOLE ARGUMENTS:-
 *  nodeVMArgs:String: Node environment params  (Eg: '--max-old-space-size=2040')
 *  ngBuildParams:String: Angular build params (Eg: '--prod=true --source-map=false')
 *  runtimeUIVersion:String: Runtime version (Eg: 10.6.6-next.10243)
 *  appSrc:String: Source folder to generate the angular app (current directory Eg: '.')
 *  appTarget:String: Target folder to save the generated app (Eg: 'target/ui-build/generated-app')
 *  codegenPath:String: Input to the codegen-CLI -->  Codegen installation path to copy the angular-template-app
 *   
 */

const {args, executeSyncCmd, MSG_CODEGEN_LOG, getArgs} = require('./build-util');

/**
 * From codegen-cli generate angular app into the target directory
 */
const generateAngularApp = () => {
    console.log(MSG_CODEGEN_LOG + 'Generating the angular App...');
    let buildArgs = getArgs(args.ngBuildParams.split(' '));
    let deployUrl = 'ng-bundle/';
    if(buildArgs && buildArgs["deploy-url"]){
        deployUrl = buildArgs["deploy-url"];
    }
    let genCmd = 'node ' + args.codegenPath + 'src/codegen-cli.js -s ' + args.appSrc + '  -t ' + args.appTarget + ' --codegenPath ' + args.codegenPath + ' -d ' + deployUrl + (args.pwa === 'true' ? ' --pwa' : '');
    console.log(MSG_CODEGEN_LOG +' Running command ' +genCmd);
    executeSyncCmd(genCmd, null, MSG_CODEGEN_LOG);
    console.log(MSG_CODEGEN_LOG + ' Angular app generated! Path: '+ args.appTarget);
}


const init = () =>{
    generateAngularApp();
}

init();


