vue-cli-template-jbc
v1.0.2
Published
vue template on wechat develope
Downloads
8
Readme
公司的业务范围较广,为了快速构建项目,自建一个简单cli,步骤如下:
创建cli项目
创建cli目录,并使用npm init创建package.json文件:
mkdir vue-cli-template-jbc && cd vue-cli-template-jbc
npm init
在交互询问中输入相应参数,其中name参数检验npm中是否已占用,如创建好的package.json文件如下,其中bin为cli调用的命令名称,main为入口js:
{
"name": "vue-cli-template-jbc",
"version": "1.0.2",
"description": "vue template on wechat develope",
"main": "index.js",
"bin": {
"jbc-cli": "./index.js"
},
"scripts": {
"test": "jbc-vue"
},
"repository": {
"type": "git",
"url": "git+https://github.com/labsInsight/vue-cli-template-jbc.git"
},
"keywords": [
"vue"
],
"author": "jbc-web",
"license": "MIT",
"bugs": {
"url": "https://github.com/labsInsight/vue-cli-template-jbc/issues"
},
"homepage": "https://github.com/labsInsight/vue-cli-template-jbc#readme",
"dependencies": {
"commander": "^2.15.1",
"git-clone": "^0.1.0",
"shelljs": "^0.8.2",
"tracer": "^0.9.0"
}
}
由于入口为index.js,所以创建index.js文件,并写入如下内容:
#!/usr/bin/env node
const clone = require('git-clone')
const program = require('commander')
const shell = require('shelljs');
const log = require('tracer').colorConsole()
program
.version('1.0.0')
.description('Jbc Vue(兼容微信和h5)应用模板工程的cli')
program
.command('* init <project> <tpl>')
.action(function(tpl, project) {
log.info('目前jbc-vue支持h5和小程序两种模板,示例:jbc-cli init myproject --wechat | --mini-program')
if (tpl && project) {
let pwd = shell.pwd()
let url;
if(tpl == '--wechat'){
url = `https://github.com/labsInsight/vue-cli-template-jbc.git`;
}else{
url = `https://github.com/labsInsight/vue-cli-template-jbc.git`;
}
log.info(`正在${url}拉取模板代码 ...`)
clone(url, pwd + `/${project}`, null, function() {
shell.rm('-rf', pwd + `/${project}/.git`)
log.info('模板工程建立完成')
})
} else {
log.error('正确命令例子:jbc-cli init myproject --amd')
}
})
program.parse(process.argv)
意思是根据不同的命令参数,拉取不同多脚手架模版,可以观察到require到依赖模块,所以npm里添加依赖配置,执行命令:
npm i commander --save
npm i git-clone --save
npm i shelljs --save
npm i tracer --save
安装并测试cli
执行如下命令全局安装即可:
npm i 上述jbc-cli项目的本地 -g
安装完成,测试:
jbc-cli init vue-cli-template-jbc --wechat
发布到npm
1、先到npm网站注册一个账号,去关联邮箱收取邮件并验证邮箱。 (doraemon-xiaoshu xiaoshu2006)
2、在命令行登录npm,输入下述命令,随后填入注册时的信息:
npm adduser
3、发布提交:
npm publish
4、若发布失败,检查是否使用npm的源,如使用cnpm等第三方源的切换回npm源。
使用
1、下载cli工具
npm i -g vue-cli-template-jbc
2、初始化工程
jbc-cli init jbc-base-project --wechat