创建自己的脚手架

1.初始化工程 npm init
2.安装 插件npm i commander download-git-repo ora handlebars figlet clear chalk open watch inquirer
3.新建bin目录,创建js文件

! /usr/bin/env node

import { Command } from "commander";
import download from "download-git-repo";
import ora from "ora";
import chalk from "chalk";
import figlet from "figlet";
import version from "../version.js";
const log = (content) => console.log(chalk.green(content));
const program = new Command();
program.version(version.version);

program
.command("init ")
.description("init project ")
.action((name) => {
figlet("qk-cli Welcome!!!", (err, data) => {
log(data);
});
const downloadUrl =
"direct:http://gitlab.rd.com/qike_front_end/qk-template.git";
log(创建项目 ${name});
const process = ora(正在下载....);
process.start();
download(downloadUrl, name, { clone: true }, (err) => {
if (err) {
console.log(err);
} else {
process.text = "下载成功";
process.succeed();
}
});
});

program.parse(process.argv);
4.在package.json中新建bin对象,这里存放之后需要执行的js文件
"bin": {
"qk-cli": "./bin/index.js"
},
5.将包npm link到全局 ,测试 命令
Sudo npm link
6.发布
bash publish.sh
7.sudo npm unlink
8.使用 npm install qk-cli -g
qk-cli init my-app

你可能感兴趣的:(创建自己的脚手架)