text: const commander = require('commander')
  const envinfo = require('envinfo');
  const path = require('path')
  const chalk = require('chalk').default
  const validateProjectName = require('validate-npm-package-name')
  const packageJson = require('../package.json');
  let projectName;
  
  const program = new commander.Command(packageJson.name)
    .version(packageJson.version,'-v, --version')
    .arguments('<project-name>')
    .usage(`${chalk.green('<project-name>')} [options]`)
    .action((name,cmd) => {
      console.log(name,cmd.info)
      projectName = name;
    })
    .option('-i, --info', 'print environment debug info')
    .parse(process.argv)
  
  //输出环境参数
  if (program.info) {
    console.log(chalk.bold('\nEnvironment Info:'));
    return envinfo
      .run(
        {
          System: ['OS', 'CPU'],
          Binaries: ['Node', 'npm', 'Yarn'],
          Browsers: ['Chrome', 'Edge', 'Internet Explorer', 'Firefox', 'Safari'],
          npmPackages: ['react', 'react-dom', 'react-scripts'],
          npmGlobalPackages: ['csh-cli'],
        },
        {
          duplicates: true,
          showNotFound: true,
        }
      )
      .then(console.log);
  }
  
  if (typeof projectName === 'undefined'){
    console.error('Please specify the project directory:');
    console.log(
      `  ${chalk.cyan(program.name())} ${chalk.green('<project-name>')}`
    );
    console.log();
    console.log('For example:');
    console.log(`  ${chalk.cyan(program.name())} ${chalk.green('my-react-app')}`);
    console.log();
    console.log(
      `Run ${chalk.cyan(`${program.name()} --help`)} to see all options.`
    );
    process.exit(1);
  }
  
  function printValidationResults(results) {
    if (typeof results !== 'undefined') {
      results.forEach(error => {
        console.error(chalk.red(`  *  ${error}`));
      });
    }
  }
  
  function checkAppName(appName) {
    const validationResult = validateProjectName(appName);
    if (!validationResult.validForNewPackages) {
      console.error(
        `Could not create a project called ${chalk.red(
          `"${appName}"`
        )} because of npm naming restrictions:`
      );
      printValidationResults(validationResult.errors);
      printValidationResults(validationResult.warnings);
      process.exit(1);
    }
  
    // TODO: there should be a single place that holds the dependencies
    const dependencies = ['react', 'react-dom', 'react-scripts'].sort();
    if (dependencies.indexOf(appName) >= 0) {
      console.error(
        chalk.red(
          `We cannot create a project called ${chalk.green(
            appName
          )} because a dependency with the same name exists.\n` +
          `Due to the way npm works, the following names are not allowed:\n\n`
        ) +
        chalk.cyan(dependencies.map(depName => `  ${depName}`).join('\n')) +
        chalk.red('\n\nPlease choose a different project name.')
      );
      process.exit(1);
    }
  }
  
  function createApp(name) {
    const root = path.resolve(name);
    const appName = path.basename(root);
    checkAppName(appName);
  }
  
  createApp(projectName)
  