-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·87 lines (80 loc) · 2.51 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env node
const chalk = require('chalk');
const figlet = require('figlet');
const envinfo = require('envinfo');
const { program } = require('commander');
// eslint-disable-next-line import/no-unresolved
const run = require('./lib/index').default;
const packageJson = require('./package.json');
const { log } = console;
let packageName;
log(
figlet.textSync('KDCio', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default',
})
);
log(`Running version: ${chalk.green(packageJson.version)}`);
log(); // blank line
program
.version(packageJson.version)
.name(`npx ${packageJson.name}`)
.usage(`${chalk.green('package-name')}`)
.arguments('[package-name]')
.option('--no-bundle', 'do not bundle the build output')
.option('-g, --git-origin <remote-url>', 'add git remote url as origin')
.option('-i, --info', 'print environment debug info')
.option('-v, --verbose', 'verbose output')
.action((name) => {
packageName = name;
})
.on('--help', () => {
log('');
log('Example:');
log(` ${chalk.cyan(program.name())} ${chalk.green('my-awesome-package')}`);
})
.parse(process.argv);
const createPackage = async () => {
try {
const { bundle, gitOrigin, verbose } = program;
await run({ packageName, bundle, gitOrigin, verbose });
log(chalk.green('\n\nYour package is ready!\n\n'));
log(chalk.blue(`\tcd ${packageName}`));
log(chalk.blue('\tcode .\n\n'));
log(chalk.green.bold(`Enjoy coding!`));
} catch (error) {
log(chalk.red(chalk.bold('Error: '), error.message));
}
};
if (program.info) {
log(chalk.bold('\nEnvironment Info:'));
log(`\n current version of ${packageJson.name}: ${packageJson.version}`);
log(` running from ${__dirname}`);
envinfo
.run(
{
System: ['OS', 'CPU'],
Binaries: ['Node', 'npm', 'Yarn'],
Browsers: ['Chrome', 'Edge', 'Internet Explorer', 'Firefox', 'Safari'],
npmGlobalPackages: [`${packageJson.name}`],
},
{
duplicates: true,
showNotFound: true,
}
)
.then(log);
} else if (typeof packageName === 'undefined') {
// eslint-disable-next-line no-console
console.error('Please specify the project name:');
log(` ${chalk.cyan(program.name())} ${chalk.green('project-directory')}`);
log();
log('For example:');
log(` ${chalk.cyan(program.name())} ${chalk.green('my-awesome-package')}`);
log();
log(`Run ${chalk.cyan(`${program.name()} --help`)} to see all options.`);
process.exit(1);
} else {
createPackage();
}