cbd-cli
A simple CLI for scaffolding cbd zhuanti projects
Last updated 9 months ago by skdream .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cbd-cli -g
SYNC missed versions from official npm registry.

cbd-cli

A simple CLI for scaffolding projects.

Installation

Prerequisites: Node.js (>=4.x, 6.x preferred) and Git.

$ npm install -g cbd-cli

Usage

$ cbd init <template-name> <project-name>

Example:

$ cbd init zhuanti my-project

$ cbd -h

  Usage: cbd <command> [options]
  
  Commands:
    init        从模板中初始化一个新项目
    list        可用模板列表
    deploy      发布到生产环境
    help [cmd]  display help for [cmd]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number

$  cbd deploy

  Usage: cbd-deploy <remote-dir> [dir-name]

  Options:

    -h, --help   output usage information
    -f, --force  重置密码

  Examples:

    # 发布到zhuanti release目录下的my-project目录
    $ cbd deploy release my-project

    # 发布到zhuanti release目录下的默认本地文件夹名目录
    $ cbd deploy release

    # 发布到zhuanti release/wx目录下的默认本地文件夹名目录
    $ cbd deploy release/wx


$ cbd list

  可用模板列表:

  ★  zhuanti - 专题模板
  ★  getred1 - 红包专题

Custom Templates

It's unlikely to make everyone happy with the official templates. You can simply fork an official template and then use it via cbd-cli with:

cbd init username/repo my-project

Where username/repo is the GitHub repo shorthand for your fork.

The shorthand repo notation is passed to download-git-repo so you can also use things like bitbucket:username/repo for a Bitbucket repo and username/repo#branch for tags or branches.

If you would like to download from a private repository use the --clone flag and the cli will use git clone so your SSH keys are used.

Local Templates

Instead of a GitHub repo, you can also use a template on your local file system:

cbd init ~/fs/path/to-custom-template my-project

Writing Custom Templates from Scratch

  • A template repo must have a template directory that holds the template files.

  • A template repo may have a metadata file for the template which can be either a meta.js or meta.json file. It can contain the following fields:

    • prompts: used to collect user options data;

    • filters: used to conditional filter files to render.

    • completeMessage: the message to be displayed to the user when the template has been generated. You can include custom instruction here.

prompts

The prompts field in the metadata file should be an object hash containing prompts for the user. For each entry, the key is the variable name and the value is an Inquirer.js question object. Example:

{
  "prompts": {
    "name": {
      "type": "string",
      "required": true,
      "message": "Project name"
    }
  }
}

After all prompts are finished, all files inside template will be rendered using Handlebars, with the prompt results as the data.

Conditional Prompts

A prompt can be made conditional by adding a when field, which should be a JavaScript expression evaluated with data collected from previous prompts. For example:

{
  "prompts": {
    "lint": {
      "type": "confirm",
      "message": "Use a linter?"
    },
    "lintConfig": {
      "when": "lint",
      "type": "list",
      "message": "Pick a lint config",
      "choices": [
        "standard",
        "airbnb",
        "none"
      ]
    }
  }
}

The prompt for lintConfig will only be triggered when the user answered yes to the lint prompt.

Pre-registered Handlebars Helpers

Two commonly used Handlebars helpers, if_eq and unless_eq are pre-registered:

{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
Custom Handlebars Helpers

You may want to register additional Handlebars helpers using the helpers property in the metadata file. The object key is the helper name:

module.exports = {
  helpers: {
    lowercase: str => str.toLowerCase()
  }
}

Upon registration, they can be used as follows:

{{ lowercase name }}

File filters

The filters field in the metadata file should be an object hash containing file filtering rules. For each entry, the key is a minimatch glob pattern and the value is a JavaScript expression evaluated in the context of prompt answers data. Example:

{
  "filters": {
    "test/**/*": "needTests"
  }
}

Files under test will only be generated if the user answered yes to the prompt for needTests.

Note that the dot option for minimatch is set to true so glob patterns would also match dotfiles by default.

Skip rendering

The skipInterpolation field in the metadata file should be a minimatch glob pattern. The files matched should skip rendering. Example:

The format needed for a specific official template is:

cbd init '<template-name>#<branch-name>' <project-name>

Example:

cbd init 'webpack-simple#1.0' mynewproject

Current Tags

  • 2.7.6                                ...           latest (9 months ago)

45 Versions

  • 2.7.6                                ...           9 months ago
  • 2.7.4                                ...           9 months ago
  • 2.7.3                                ...           10 months ago
  • 2.7.2                                ...           a year ago
  • 2.7.1                                ...           a year ago
  • 2.7.0                                ...           a year ago
  • 2.5.0                                ...           a year ago
  • 2.4.0                                ...           a year ago
  • 2.3.3                                ...           a year ago
  • 2.3.2                                ...           a year ago
  • 2.3.1                                ...           a year ago
  • 2.3.0                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.12                                ...           2 years ago
  • 2.1.11                                ...           2 years ago
  • 2.1.10                                ...           2 years ago
  • 2.1.9                                ...           2 years ago
  • 2.1.6                                ...           2 years ago
  • 2.1.5                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.4                                ...           2 years ago
  • 2.1.3                                ...           2 years ago
  • 2.1.1                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.9                                ...           2 years ago
  • 2.0.8                                ...           2 years ago
  • 2.0.7                                ...           2 years ago
  • 2.0.6                                ...           2 years ago
  • 2.0.5                                ...           2 years ago
  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 1.1.4                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.9                                ...           3 years ago
  • 1.0.8                                ...           3 years ago
  • 1.0.7                                ...           3 years ago
  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 45
This Week 45
This Month 46
Last Day 0
Last Week 1
Last Month 5
Dependencies (22)
Dev Dependencies (6)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |