2023-12-22 12:59:57 +08:00
|
|
|
#!/usr/bin/env node
|
2023-12-22 17:38:13 +08:00
|
|
|
const { program } = require('commander'); // 命令行提示工具
|
|
|
|
const chalk = require('chalk'); // 终端输出颜色变化
|
|
|
|
const inquirer = require('inquirer'); // 交互选项
|
|
|
|
const ora = require('ora'); // loading效果
|
|
|
|
const spinner = ora('Loading unicorns').start(); // 注意要使用x几版本因为不支持
|
|
|
|
const figlet = require('figlet'); // 生成艺术字
|
2023-12-22 12:59:57 +08:00
|
|
|
|
2023-12-22 17:38:13 +08:00
|
|
|
figlet('Hello World!!', function (err, data) {
|
|
|
|
if (err) {
|
|
|
|
console.log('Something went wrong...');
|
|
|
|
console.dir(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(data);
|
2023-12-22 12:59:57 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
figlet.text(
|
2023-12-22 17:38:13 +08:00
|
|
|
'Boo!',
|
|
|
|
{
|
|
|
|
font: 'Ghost',
|
|
|
|
horizontalLayout: 'default',
|
|
|
|
verticalLayout: 'default',
|
|
|
|
width: 80,
|
|
|
|
whitespaceBreak: true,
|
|
|
|
},
|
|
|
|
function (err, data) {
|
|
|
|
if (err) {
|
|
|
|
console.log('Something went wrong...');
|
|
|
|
console.dir(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(data);
|
|
|
|
},
|
2023-12-22 12:59:57 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
console.log(
|
2023-12-22 17:38:13 +08:00
|
|
|
figlet.textSync('Boo!', {
|
|
|
|
font: 'Ghost',
|
|
|
|
horizontalLayout: 'default',
|
|
|
|
verticalLayout: 'default',
|
|
|
|
width: 80,
|
|
|
|
whitespaceBreak: true,
|
|
|
|
}),
|
2023-12-22 12:59:57 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2023-12-22 17:38:13 +08:00
|
|
|
spinner.color = 'red';
|
|
|
|
spinner.text = '网络较慢,请稍后...';
|
2023-12-22 12:59:57 +08:00
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2023-12-22 17:38:13 +08:00
|
|
|
spinner.succeed('下载成功!!!');
|
2023-12-22 12:59:57 +08:00
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2023-12-22 17:38:13 +08:00
|
|
|
spinner.fail('下载失败!!!');
|
2023-12-22 12:59:57 +08:00
|
|
|
}, 3000);
|
|
|
|
|
|
|
|
inquirer
|
2023-12-22 17:38:13 +08:00
|
|
|
.prompt([
|
|
|
|
/* Pass your questions in here */
|
|
|
|
{ type: 'input', name: 'food', message: '你吃什么', default: '包子' },
|
|
|
|
{ type: 'input', name: 'food', message: '吃辣吗?', default: '微辣' },
|
|
|
|
])
|
|
|
|
.then(answers => {
|
|
|
|
// Use user feedback for... whatever!!
|
|
|
|
console.log(answers);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error.isTtyError) {
|
|
|
|
// Prompt couldn't be rendered in the current environment
|
|
|
|
} else {
|
|
|
|
// Something else went wrong
|
|
|
|
}
|
|
|
|
});
|
2023-12-22 12:59:57 +08:00
|
|
|
|
2023-12-22 17:38:13 +08:00
|
|
|
console.log(chalk.red('文字颜色'));
|
2023-12-22 12:59:57 +08:00
|
|
|
|
2023-12-22 17:38:13 +08:00
|
|
|
program.name('bunny-cli').usage('<command> [options]');
|
2023-12-22 12:59:57 +08:00
|
|
|
|
|
|
|
program
|
2023-12-22 17:38:13 +08:00
|
|
|
.option('-d, --debug', 'output extra debugging')
|
|
|
|
.option('-s, --small', 'small pizza size')
|
|
|
|
.option('-p, --pizza-type <type>', 'flavour of pizza');
|
2023-12-22 12:59:57 +08:00
|
|
|
|
|
|
|
program
|
2023-12-22 17:38:13 +08:00
|
|
|
.command('clone <source> [destination]')
|
|
|
|
.description('clone a repository into a newly created directory')
|
|
|
|
.action((source, destination) => {
|
|
|
|
console.log(source, destination);
|
|
|
|
});
|
2023-12-22 12:59:57 +08:00
|
|
|
|
|
|
|
program.parse(process.argv);
|
|
|
|
|
|
|
|
const options = program.opts();
|
|
|
|
console.log(options);
|