const cp = require('child_process');
const ph = require('path');
const os = require('os');

const libraries = [
    /* ph.join(__dirname, `node_modules`, `@angular`, `animations`),
    ph.join(__dirname, `node_modules`, `@angular`, `common`),
    //ph.join(__dirname, `node_modules`, `@angular`, `compiler`),
    ph.join(__dirname, `node_modules`, `@angular`, `core`),
    ph.join(__dirname, `node_modules`, `@angular`, `elements`),
    ph.join(__dirname, `node_modules`, `@angular`, `forms`),
    //ph.join(__dirname, `node_modules`, `@angular`, `localize`),
    ph.join(__dirname, `node_modules`, `@angular`, `platform-browser`),
    ph.join(__dirname, `node_modules`, `@angular`, `router`),

    ph.join(__dirname, `node_modules`, `@angular`, `cdk`),
    ph.join(__dirname, `node_modules`, `@angular`, `material`), */
    
    /* ph.join(__dirname, `node_modules`, `ngx-toastr`),
    ph.join(__dirname, `node_modules`, `@tweenjs`, `tween.js`),
    ph.join(__dirname, `node_modules`, `@iharbeck`, `ngx-virtual-scroller`), */
]

const CMD = os.platform() === 'win32' ? `pnpx.cmd` : `pnpx`;

// --loglevel debug --async false --create-ivy-entry-points --first-only

libraries.forEach(function (lib) {

    //  `--properties`, `es2015`, `browser`, `module`, `main`
    const ARGS = [`ngcc`, `--source`, lib, `--loglevel`, `debug`]
    
    const RES = cp.spawnSync(CMD, ARGS, { stdio: 'inherit' })

    console.log(`status -->`, RES.status)

    if (RES.status !== 0) {

        if (RES.error) {
            console.error(RES.error.toString());
        }

        if (RES.stderr) {
            console.error(RES.stderr.toString())
        }

        process.exit(1)
        
    } else {
        if (RES.stdout) {
            console.info(RES.stdout.toString())
        }
    }

})