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


const libraries = [
    /* ph.join(__dirname, `node_modules`, `@telerik`, `kendo-draggable`),

    ph.join(__dirname, `node_modules`, `@progress`, `kendo-schematics`),
    ph.join(__dirname, `node_modules`, `@progress`, "kendo-common"),
    ph.join(__dirname, `node_modules`, `@progress`, `kendo-popup-common`),

    ph.join(__dirname, `node_modules`, `@progress`, `kendo-angular-common`),
    ph.join(__dirname, `node_modules`, `@progress`, `kendo-angular-l10n`),
    ph.join(__dirname, `node_modules`, `@progress`, `kendo-angular-popup`),
    ph.join(__dirname, `node_modules`, `@progress`, `kendo-angular-progressbar`),
    ph.join(__dirname, `node_modules`, `@progress`, `kendo-angular-layout`),
    ph.join(__dirname, `node_modules`, `@progress`, `kendo-angular-menu`), */
]

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`, `--async`, `false`]
    
    const RES = cp.spawnSync(CMD, ARGS)

    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())
        }
    }

})