src/config/resolveConfig.js
async function resolveBinary(binaryName) {
  let nodeModulesPath = `./node_modules/.bin/${binaryName}`;
  if (await exists(nodeModulesPath)) {
    return nodeModulesPath;
  } else {
    try {
      await exec(`which ${binaryName}`);
      return binaryName;
    } catch (e) {
      console.log(`${binaryName} binary not found on the PATH or in node_modules.`);
      let rl = readline.createInterface(process.stdin, process.stdout);
      let answer = await rl.question(`Run "npm install -g ${binaryName}"? [Y/n] `);
      rl.close();
      if (answer.toLowerCase().startsWith('n')) {
        throw new CLIError(`${binaryName} must be installed.`);
      }
      console.log(`Installing ${binaryName} globally...`);
      await execLive(`npm install -g ${binaryName}`);
      console.log(`Successfully installed ${binaryName}\n`);
      return binaryName;
    }
  }
}
async function resolveBinary(binaryName) {
  let nodeModulesPath = `./node_modules/.bin/${binaryName}`;
  if (await exists(nodeModulesPath)) {
    return nodeModulesPath;
  } else {
    try {
      await exec(`which ${binaryName}`);
      return binaryName;
    } catch (e) {
      console.log(`${binaryName} binary not found on the PATH or in node_modules.`);
      let rl = readline.createInterface(process.stdin, process.stdout);
      let answer = await rl.question(`Run "npm install -g ${binaryName}"? [Y/n] `);
      rl.close();
      if (answer.toLowerCase().startsWith('n')) {
        throw new CLIError(`${binaryName} must be installed.`);
      }
      console.log(`Installing ${binaryName} globally...`);
      await execLive(`npm install -g ${binaryName}`);
      console.log(`Successfully installed ${binaryName}\n`);
      return binaryName;
    }
  }
}
async function resolveBinary ( binaryName ) { let nodeModulesPath = ` ${ binaryName } ` ; if ( await exists ( nodeModulesPath ) ) { return nodeModulesPath ; } else { try { await exec ( ` ${ binaryName } ` ) ; return binaryName ; } catch ( e ) { console . log ( ` ${ binaryName } ` ) ; let rl = readline . createInterface ( process . stdin , process . stdout ) ; let answer = await rl . question ( ` ${ binaryName } ` ) ; rl . close ( ) ; if ( answer . toLowerCase ( ) . startsWith ( 'n' ) ) { throw new CLIError ( ` ${ binaryName } ` ) ; } console . log ( ` ${ binaryName } ` ) ; await execLive ( ` ${ binaryName } ` ) ; console . log ( ` ${ binaryName } \n ` ) ; return binaryName ; } } }
Determine the shell command that can be used to run the given binary,
prompting to globally install it if necessary.
Determine the shell command that can be used to run the given binary prompting to globally install it if necessary .