|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
| 3 | +/* eslint-disable no-console */ |
| 4 | +const chalk = require('chalk'); |
| 5 | +const envinfo = require('envinfo'); |
3 | 6 | const { program } = require('commander'); |
4 | 7 | const run = require('./lib/index').default; |
5 | 8 |
|
| 9 | +const packageJson = require('./package.json'); |
| 10 | + |
| 11 | +let packageName; |
| 12 | + |
6 | 13 | program |
| 14 | + .version(packageJson.version) |
7 | 15 | .name('npx @kdcsoftware/create-nodejs') |
8 | | - .usage('<package-name>') |
9 | | - .arguments('<package-name>', 'Name of your package') |
10 | | - .action(function (packageName) { |
11 | | - // console.log(packageName); |
12 | | - run({ packageName }); |
13 | | - }); |
14 | | - |
15 | | -program.parse(process.argv); |
| 16 | + .usage(`${chalk.green('<package-name>')}`) |
| 17 | + .arguments('<package-name>') |
| 18 | + .option('--info', 'print environment debug info') |
| 19 | + .action((name) => { |
| 20 | + packageName = name; |
| 21 | + }) |
| 22 | + .parse(process.argv); |
| 23 | + |
| 24 | +if (program.info) { |
| 25 | + console.log(chalk.bold('\nEnvironment Info:')); |
| 26 | + console.log( |
| 27 | + `\n current version of ${packageJson.name}: ${packageJson.version}` |
| 28 | + ); |
| 29 | + console.log(` running from ${__dirname}`); |
| 30 | + return envinfo |
| 31 | + .run( |
| 32 | + { |
| 33 | + System: ['OS', 'CPU'], |
| 34 | + Binaries: ['Node', 'npm', 'Yarn'], |
| 35 | + Browsers: ['Chrome', 'Edge', 'Internet Explorer', 'Firefox', 'Safari'], |
| 36 | + npmGlobalPackages: ['@kdcsoftware/create-nodejs'], |
| 37 | + }, |
| 38 | + { |
| 39 | + duplicates: true, |
| 40 | + showNotFound: true, |
| 41 | + } |
| 42 | + ) |
| 43 | + .then(console.log); |
| 44 | +} |
| 45 | + |
| 46 | +if (typeof packageName === 'undefined') { |
| 47 | + console.error('Please specify the project directory:'); |
| 48 | + console.log( |
| 49 | + ` ${chalk.cyan(program.name())} ${chalk.green('<project-directory>')}` |
| 50 | + ); |
| 51 | + console.log(); |
| 52 | + console.log('For example:'); |
| 53 | + console.log( |
| 54 | + ` ${chalk.cyan(program.name())} ${chalk.green('my-awesome-package')}` |
| 55 | + ); |
| 56 | + console.log(); |
| 57 | + console.log( |
| 58 | + `Run ${chalk.cyan(`${program.name()} --help`)} to see all options.` |
| 59 | + ); |
| 60 | + return process.exit(1); |
| 61 | +} |
| 62 | + |
| 63 | +run({ packageName }); |
| 64 | + |
| 65 | +return process.exit(0); |
0 commit comments