Executes 'npm install -g npm' upgrading npm
@param  {string} version - The version to be installed (npm install npm@{version})
@return {Promise.<stderr[], stdout[]>} - stderr and stdout received from the PS1 process
173603
function runSimpleUpgrade (version) {
  return new Promise((resolve) => {
    let npmCommand = (version) ? `npm install -g npm@${version}` : 'npm install -g npm'
    let stdout = []
    let stderr = []
    let child

    try {
      child = spawn('powershell.exe', [ '-NoProfile', '-NoLogo', npmCommand ])
    } catch (error) {
      // This is dirty, but the best way for us to try/catch right now
      resolve({ error })
    }

    child.stdout.on('data', (data) => stdout.push(data.toString()))
    child.stderr.on('data', (data) => stderr.push(data.toString()))

    child.on('exit', () => resolve({ stderr, stdout }))

    child.stdin.end()
  })
}
1154344
function exec_command0(losk_version) {
    console.log(colors.cyan('Check update package...'));
    exec('npm outdated -json --long',
    (error, stdout, stderr) => {
        countpackege = 0;
        lengmass = 0;
        var massfordelete = new Array();
        massfordelete.fill(0);


        if (error !== null) {
            console.log(`exec error 1 : ${error}`);
        } else {
            if (stdout != "") {
                obj = JSON.parse(stdout);
                keys = Object.keys(obj);
                // [LATEST]
                //l------------------------------------------------------------------
                if (losk_version == 'latest') {
                    for (var i = 0 ; keys.length > i ; i++) {
                        //filter
                        //f----------------------------------------------------------
                        if (obj[keys[i]].latest > obj[keys[i]].current && obj[keys[i]].wanted <= obj[keys[i]].latest) {
                            countpackege = countpackege + 1;
                        }
                        if (obj[keys[i]].current == obj[keys[i]].latest && obj[keys[i]].wanted <= obj[keys[i]].latest) {
                            massfordelete[i] = keys[i];
                        }
                        if (obj[keys[i]].wanted > obj[keys[i]].latest) {
                            massfordelete[i] = keys[i];
                        }
                        //f----------------------------------------------------------

                        //start
                        //s----------------------------------------------------------
                        if (i == keys.length - 1 && countpackege != 0) {
                            for (var i2 = 0 ; massfordelete.length > i2 ; i2++) {
                                delete obj[massfordelete[i2]];
                            }
                            keys = Object.keys(obj);
                            exec_command1();
                        } else if (i == keys.length - 1 && countpackege == 0) {
                            for (var i3 = 0 ; massfordelete.length > i3 ; i3++) {
                                delete obj[massfordelete[i3]];
                            }
                            console.log(colors.cyan('Completed!'));
                        }
                        //s----------------------------------------------------------
                    }
                }
                //l------------------------------------------------------------------


                // [WANTED]
                //w------------------------------------------------------------------
                if (losk_version == 'wanted') {
                    if (obj[keys[i]].wanted > obj[keys[i]].current) {
                        xec_command1_wanted();
                        //....
                        //
                        // Will be updated
                        //
                        //....
                    }
                }
                //w------------------------------------------------------------------
            } else {
                console.log(colors.cyan('Completed!'));
            }
        }
    });
}
7198
function toDrupalMajorVersion(version) {
    var regex = /^(\d+)\.\d+\.[x\d+]/;
    var match = version.match(regex)
    if (match) {
      return match[1] + '.x';
    }

    return version;
  }
727499
async function _expectPackageVersion(args) {
  const packageVersion = require(
    path.resolve(__dirname, '../../package.json')
  ).version;
  await _expectSuccessMessage(args, `${packageVersion}\n`);
}
1098330
function getAvailableNPMVersions () {
  return new Promise((resolve, reject) => {
    exec('npm view npm versions --json', (err, stdout) => {
      if (err) {
        let error = 'We could not show latest available versions. Try running this script again '
        error += 'with the version you want to install (npm-windows-upgrade --npm-version 3.0.0)'
        return reject(error)
      }

      resolve(JSON.parse(stdout))
    })
  })
}
1327551
function() {
    return dexec( 'cd ' + this.settings.git + '; npm install' ).done(function( stdout, stderr ) {
        log( 'npm install successful' );
        log.extra( stdout, stderr );
      });
  }
709203
function processNpmLine(line) {
    if (swig.argv.useYarn) {
      try {
        processYarnLine(line);
      } catch (e) {
        // NOTE: Some output lines come joined together. Splitting them here
        // and processing them one by one.
        if (/\n/.test(line)) {
          const lines = line.split(/\n/);
          lines.forEach((_line) => {
            processYarnLine(_line);
          });
        }
      }
      return;
    }

    line = swig.log.strip(line).trim();

    swig.log.verbose(line);

    let moduleName;

    if (regex.requested.test(line)) {
      moduleName = line.replace(regex.requested, '$1');

      swig.log.verbose(`${swig.log.padding + swig.log.padding + '→'.white}  ${moduleName}`);
    } else if (regex.installed.test(line)) {
      moduleName = line.replace(regex.installed, '$3 v$4');

      if (!_.contains(downloaded, moduleName)) {
        downloaded.push(moduleName);

        swig.log(`${swig.log.strip(swig.log.symbols.download).green}  ${moduleName}`);
      }
    } else if (regex.fourohfour.test(line)) {
      swig.log();
      swig.log.error('install', `Module not found: ${line.replace(regex.fourohfour, '$1')}`);
    } else if (regex.noversion.test(line)) {
      swig.log();
      swig.log.error('install', line.replace(regex.noversion, '$1'));
      swig.log('\nTry specifying a different version. use `npm view <module>` to display available versions for a module.\n');
    } else if (regex.error.test(line)) {
      swig.log();
      swig.log.error('install', line.replace(regex.error, '$1'));
    }
  }
660094
function getNpm() {
    let execResult;
    let version;
    let version3;
    let npm;
    if (shell.which('npm')) {
        execResult = shell.exec('npm --version', { silent: true });
        if (execResult.code === 0) {
            version = execResult.stdout;
        }
    }

    if (version !== null && semver.satisfies(version, '>= 3.0.0')) {
        npm = 'npm';
    }

    if (!npm) {
        if (shell.which('npm3')) {
            execResult = shell.exec('npm3 --version', { silent: true });
            if (execResult.code === 0) {
                version3 = execResult.stdout;
            }
        }

        if (version3 === null) {
            npm = 'npm';
        } else {
            npm = 'npm3';
        }
    }
    return npm;
}
960021
function getInstalledPlatformVersion(projectPath, platform) {
    var platformJsonPath = path.join(projectPath, 'platforms', 'platforms.json')
    if (fileExistsSync(platformJsonPath)) {
        var platformsJson = require(path.join(projectPath, 'platforms', 'platforms.json'));
        return Q(platformsJson[platform]);
    } else {
        return exec(path.join(projectPath, 'platforms', platform, 'cordova', 'version')).then(function (result) {
            return result[0].replace(/\r?\n|\r/g, '');
        });
    }
}
5631
function cb (err) {
    if (cb.done) return
    cb.done = true
    if (err) {
      log.warn('install', 'got an error, rolling back install')
      // roll-back the install if anything went wrong
      gyp.commands.remove([ release.versionDir ], function () {
        callback(err)
      })
    } else {
      callback(null, release.version)
    }
  }
85599
async function checkNewVersion() {
    try {
        const file = path.join(constants.GLOBAL_DIR, constants.GLOBAL_INFO);

        // If it does not exist, create it.
        if (!fs.existsSync(file)) {
            createFile({
                name: file,
                source: `{"lastCheckForUpdate": 0}\n`,
            });
        }

        // Read info file
        const json = fs.readJsonSync(file, 'utf8');
        const lastCheckForUpdate = json.lastCheckForUpdate;

        // Show update message
        if (lastCheckForUpdate + (6 * 3600 * 1000) < Date.now()) {
            const latestVersion = await request(`${constants.FIREBASE_DATABASE_URL}/version/cli/latest.json`);
            if (latestVersion && latestVersion !== 'null' && latestVersion !== `"${pjson.version}"`) {
                const scale = pjson.version.length + latestVersion.length - 10;

                console.log();
                console.log(`${`   ┏`.yellow}${`─`.repeat(scale + 45).yellow}${`┓`.yellow}`);
                console.log(`${`   │`.yellow}${` `.repeat(scale + 45)}${`│`.yellow}`);
                console.log(`${`   │`.yellow}${`      Update available ${pjson.version} -> `}${`${latestVersion}`.green}${`        │`.yellow}`);
                console.log(`${`   │`.yellow}${`  Run `}${`npm i -g google-apps-script`.red}${` to update`}${` `.repeat(scale + 2)}${`│`.yellow}`);
                console.log(`${`   │`.yellow}${` `.repeat(scale + 45)}${`│`.yellow}`);
                console.log(`${`   ┗`.yellow}${`─`.repeat(scale + 45).yellow}${`┛`.yellow}`);
                console.log();
            }

            // Update lastCheckForUpdate
            json.lastCheckForUpdate = Date.now();
            createFile({
                name: file,
                source: JSON.stringify(json),
            });
            return true;
        }
        return false;
    } catch (err) {
        err.origin = 'checkNewVersion';
        await error.log(err);
        return false;
    }
}
455671
function parseVersion(v) {
  const [
    , // Full match of no interest.
    major = null,
    sub = null,
    minor = null,
  ] = /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-.*)?$/.exec(v);
  if (major === null || sub === null || minor === null) {
    const err = new Error(`Invalid version string (${v})!`);
    logger.error(err);
    throw err;
  }

  return {
    major,
    sub,
    minor,
  };
}
1230339
function execDependencyInstall () {

	console.log('\nExecuting npm install command...');

	return new Promise(function(resolve, reject){

		var child = require('child_process').spawn('npm', ['install'], {
			cwd: process.cwd,
			detached: false,
			env: process.env,
			stdio: [process.stdin, process.stdout, process.stderr]
		});

		child.on('error', function (error) {
			console.error(colors.bold.red('ERROR: Could not install the required modules:'));
			console.error(error.stack.toString());
			process.exit(255);
		});

		child.on('close', function (exit_code) {
			if (exit_code !== 0) {
				console.error(colors.bold.red('\nERROR: npm install has been failed.'));
				process.exit(255);
			}
			console.log('\nnpm install has been completed.\n\n');
			resolve(true);
		});

	});

}
906796
function outputVersion () {
  fs.readFile(path.join(__dirname, '/../package.json'), function (err, data) {
    if (err) {
      console.log(err.toString())
    } else {
      const pkg = JSON.parse(data)
      const version = pkg && pkg.version ? pkg.version : 'unknown'
      console.log(version)
    }
    process.exit(0)
  })
}
1344231
protected static Requirement caretRequirement(String version, Semver.SemverType type) {
        if (type != Semver.SemverType.NPM) {
            throw new SemverException("The caret requirements are only compatible with NPM.");
        }
        Semver semver = new Semver(version, type);
        Requirement req1 = new Requirement(new Range(extrapolateVersion(semver), Range.RangeOperator.GTE), null, null, null);

        String next;
        if (semver.getMajor() == 0) {
            if (semver.getMinor() == null) {
                next = "1.0.0";
            } else if (semver.getMinor() == 0) {
                if (semver.getPatch() == null) {
                    next = "0.1.0";
                } else {
                    next = "0.0." + (semver.getPatch() + 1);
                }
            } else {
                next = "0." + (semver.getMinor() + 1) + ".0";
            }
        } else {
            next = (semver.getMajor() + 1) + ".0.0";
        }
        Requirement req2 = new Requirement(new Range(next, Range.RangeOperator.LT), null, null, null);

        return new Requirement(null, req1, RequirementOperator.AND, req2);
    }
1351493
function bumpVersion() {
  const versionList = gitVersionInfo(packageJson.version);
  const targetBranch = 'master';
  const repoURL = packageJson.repository.url.replace(/(?:git\+|\.git)/g, '');

  gitPorcelainStatus()
    .then(status => {
      if (status.currentBranch !== targetBranch) {
        log.error(
          `${chalk.bold('Working on the wrong branch!')}`,
          `All tags must be created on ${chalk.bold(targetBranch)} branch. Please push your work and`,
          `create a Pull Request to ${chalk.bold(targetBranch)}. Then you can continue this process.`
        );
      }

      if (!status.clean) {
        log.error(`${chalk.bold('Working dirty!')}`, 'Please commit before trying again!');
      }

      log.info(`Current version in package.json is ${chalk.bold(versionList.current)}\n`);

      return inquirer.prompt([
        {
          type: 'list',
          name: 'newVersion',
          message: 'How would you like to bump it?',
          choices: versionList.prompt
        }
      ]);
    })
    .then(answers => {
      packageJson.version = answers.newVersion;
      packageLock.version = answers.newVersion;

      // Update Package files
      return Promise.all([
        promiseWriteFile(path.join(cwd, 'package.json'), packageJson, 2),
        promiseWriteFile(path.join(cwd, 'package-lock.json'), packageLock, 2)
      ]);
    })
    .then(([rewritePKG, rewritePKGLOCK]) => {
      log.success(
        `Version bumped in the following file:`,
        `${figures.arrowRight} ${rewritePKG.fileName}`,
        `${figures.arrowRight} ${rewritePKGLOCK.fileName}`
      );

      return gitTagsInfo(`v${packageJson.version}`);
    })
    .then(([tagsList, firstCommit]) =>
      changelog(
        // Object with all the tags info.
        tagsList,
        // First commit.
        firstCommit.trim(),
        // URL of the repository.
        repoURL,
        // Name of the repository.
        capitalize(packageJson.name.replace(/-/g, ' '))
      )
    )
    .then(result => {
      var filesToAdd = ['changelog/', 'package.json', 'package-lock.json'];
      var resultLog = result.reduce((prev, { fileName }) => prev.concat(`${figures.arrowRight} ${fileName}`), []);

      log.success(`Changelog:`, ...resultLog);

      log.info(`Pushing new tag to ${chalk.bold('origin')}...`);

      return git(`add ${filesToAdd.join(' ')}`);
    })
    .then(() => {
      var commitMessage = `Bump version to ${packageJson.version}`;

      return git(`commit -m "${commitMessage}"`, gitParseOutput);
    })
    .then(status => {
      log(...status);

      return git(`push origin ${targetBranch}`, gitParseOutput);
    })
    .then(status => {
      log(...status);

      return git(`tag -a -m "Tag version ${packageJson.version}." "v${packageJson.version}"`);
    })
    .then(() => git('git push origin --tags', gitParseOutput))
    .then(status => {
      var publicURL = `${repoURL}/releases/tag/v${packageJson.version}`;

      log(...status);

      log.success(`Release v${packageJson.version} was generated!`);

      log(`Please go to: ${chalk.underline(publicURL)}`, 'to describe the new changes/features added in this release.');

      return opn(publicURL, { wait: false });
    })
    .catch(log.error);
}
721053
function _getWindowsVersion () {
  return new Promise((resolve, reject) => {
    const command = 'systeminfo | findstr /B /C:"OS Name" /C:"OS Version"'
    exec(command, (error, stdout) => {
      if (error) {
        reject(error)
      } else {
        resolve(stdout)
      }
    })
  })
}