npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

参考文献:
自建node的简单cli——san-cli