创建一个自己的cli

要使用到的库

  • download-git-repo 下载仓库
  • ora 等待进度条
  • commander
  • chalk
    package.json .bin/a:b npm link
    如果要删除 ls /usr/local/bin rm /usr/local/kkb

ora

1
2
3
4
5
const ora = require('ora');
const process = ora(`正在下载....${repo}`);
process.start();
process.fail()
process.succeed()

commander

1
2
3
4
5
6
#!/usr/bin/env node
const program = require('commander')
program.version(require('../package').version, '-v', '--version')
.command('init <name>', 'init project')
.command('refresh','refresh routers...')
program.parse(process.argv)

预览

1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env bash
npm config get registry # 检查仓库镜像库
npm config set registry=http://registry.npmjs.org
echo '请进行登录相关操作:'
npm login # 登陆
echo "-------publishing-------"
npm publish # 发布
npm config set registry=https://registry.npm.taobao.org # 设置为淘宝镜像
echo "发布完成"
exit

简单的参考案例

github.com/su37josephxia/Vue-template

扫一扫,分享到微信

请我喝杯咖啡吧~