pkgscript.js
function install(items, callback) {

    var item = items[next],
        command = item.command,
        args = item.args,
        admin = item.admin,
        spawnopt = (item.spawnopt || {}),
        print;


    // set the spawn object according to the passed admin argument
    admin = setSpawnObject(admin);

    // run the command
    if (isLinux) {
        if (admin) {
            // use sudo
            args.unshift(command);
            print = args.join(" ");
            logger.console.log("[package-script] Running Installer command: " + print);

            sudoopt.spawnOptions = {};
            jsutils.Object.copy(spawnopt, sudoopt.spawnOptions);
            cprocess = spawn(args, sudoopt);
        } else {
            //use child_process
            print = args.join(" ");
            logger.console.log("[package-script] Running Installer command: " + command + " " + print);
            cprocess = spawn(command, args, spawnopt);
        }
    } else {
        args.unshift(command);
        args.unshift("/c");
        command = "cmd";
        print = [command, args.join(" ")].join(" ");
        logger.console.log("[package-script] Running Installer command: " + print);
        cprocess = spawn(command, args, spawnopt);

    }

    // -- Spawn Listeners
    cprocess.stdout.on('data', function (data) {
        var log = 'CAT Installer: ' + data;
        logger.logall(log);
    });

    cprocess.stderr.on('data', function (data) {
        if (data && (new String(data)).indexOf("npm ERR") != -1) {
            logger.logall('Package Script : ' + data);
        } else {
            logger.log2file('Package Script : ' + data);
        }
    });

    cprocess.on('close', function (code) {
        logger.log2file('Package Script Complete ' + code);
        next++;
        if (next < size) {
            install(items, callback);

        } else {
            // callback
            if (callback && _.isFunction(callback)) {
                callback.call(this, code);

            }
        }
    });
}
function install(items, callback) {

    var item = items[next],
        command = item.command,
        args = item.args,
        admin = item.admin,
        spawnopt = (item.spawnopt || {}),
        print;


    // set the spawn object according to the passed admin argument
    admin = setSpawnObject(admin);

    // run the command
    if (isLinux) {
        if (admin) {
            // use sudo
            args.unshift(command);
            print = args.join(" ");
            logger.console.log("[package-script] Running Installer command: " + print);

            sudoopt.spawnOptions = {};
            jsutils.Object.copy(spawnopt, sudoopt.spawnOptions);
            cprocess = spawn(args, sudoopt);
        } else {
            //use child_process
            print = args.join(" ");
            logger.console.log("[package-script] Running Installer command: " + command + " " + print);
            cprocess = spawn(command, args, spawnopt);
        }
    } else {
        args.unshift(command);
        args.unshift("/c");
        command = "cmd";
        print = [command, args.join(" ")].join(" ");
        logger.console.log("[package-script] Running Installer command: " + print);
        cprocess = spawn(command, args, spawnopt);

    }

    // -- Spawn Listeners
    cprocess.stdout.on('data', function (data) {
        var log = 'CAT Installer: ' + data;
        logger.logall(log);
    });

    cprocess.stderr.on('data', function (data) {
        if (data && (new String(data)).indexOf("npm ERR") != -1) {
            logger.logall('Package Script : ' + data);
        } else {
            logger.log2file('Package Script : ' + data);
        }
    });

    cprocess.on('close', function (code) {
        logger.log2file('Package Script Complete ' + code);
        next++;
        if (next < size) {
            install(items, callback);

        } else {
            // callback
            if (callback && _.isFunction(callback)) {
                callback.call(this, code);

            }
        }
    });
}
function install ( items , callback ) { var item = items [ next ] , command = item . command , args = item . args , admin = item . admin , spawnopt = ( item . spawnopt || { } ) , print ; // set the spawn object according to the passed admin argument admin = setSpawnObject ( admin ) ; // run the command if ( isLinux ) { if ( admin ) { // use sudo args . unshift ( command ) ; print = args . join ( " " ) ; logger . console . log ( "[package-script] Running Installer command: " + print ) ; sudoopt . spawnOptions = { } ; jsutils . Object . copy ( spawnopt , sudoopt . spawnOptions ) ; cprocess = spawn ( args , sudoopt ) ; } else { //use child_process print = args . join ( " " ) ; logger . console . log ( "[package-script] Running Installer command: " + command + " " + print ) ; cprocess = spawn ( command , args , spawnopt ) ; } } else { args . unshift ( command ) ; args . unshift ( "/c" ) ; command = "cmd" ; print = [ command , args . join ( " " ) ] . join ( " " ) ; logger . console . log ( "[package-script] Running Installer command: " + print ) ; cprocess = spawn ( command , args , spawnopt ) ; } // -- Spawn Listeners cprocess . stdout . on ( 'data' , function ( data ) { var log = 'CAT Installer: ' + data ; logger . logall ( log ) ; } ) ; cprocess . stderr . on ( 'data' , function ( data ) { if ( data && ( new String ( data ) ) . indexOf ( "npm ERR" ) != - 1 ) { logger . logall ( 'Package Script : ' + data ) ; } else { logger . log2file ( 'Package Script : ' + data ) ; } } ) ; cprocess . on ( 'close' , function ( code ) { logger . log2file ( 'Package Script Complete ' + code ) ; next ++ ; if ( next < size ) { install ( items , callback ) ; } else { // callback if ( callback && _ . isFunction ( callback ) ) { callback . call ( this , code ) ; } } } ) ; }
Run a single spawn operation according to the given configuration

@param items The passed configuration items
@param callback The functionality to be called on complete
Run a single spawn operation according to the given configuration