bunny-cli/bin/demo.js

98 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
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"); // 生成艺术字
figlet("Hello World!!", function (err, data) {
if (err) {
console.log("Something went wrong...");
console.dir(err);
return;
}
console.log(data);
});
figlet.text(
"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);
},
);
console.log(
figlet.textSync("Boo!", {
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
}),
);
setTimeout(() => {
spinner.color = "red";
spinner.text = "网络较慢,请稍后...";
}, 1000);
setTimeout(() => {
spinner.succeed("下载成功!!!");
}, 2000);
setTimeout(() => {
spinner.fail("下载失败!!!");
}, 3000);
inquirer
.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
}
});
console.log(chalk.red("文字颜色"));
program.name("bunny-cli").usage("<command> [options]");
program
.option("-d, --debug", "output extra debugging")
.option("-s, --small", "small pizza size")
.option("-p, --pizza-type <type>", "flavour of pizza");
program
.command("clone <source> [destination]")
.description("clone a repository into a newly created directory")
.action((source, destination) => {
console.log(source, destination);
});
program.parse(process.argv);
const options = program.opts();
console.log(options);