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

@zenghj/saber-cli

v0.0.7

Published

Saber-cli is a project scaffold tool used to scaffold your project based on [saber-cli-templates](https://github.com/saber-cli-templates).

Downloads

4

Readme

[toc]

Saber-cli

Saber-cli is a project scaffold management tool used to scaffold your project based on specific template sources. The default registry is saber-cli-templates. And you can switch to your personal template registry source.That's really awesome!

Install

# install saber-cli
yarn global add @zenghj/saber-cli

Create a Project

# create a new project based on specific template
saber init templateName projectName

Usage

Usage: saber [options] [command]
# saber-dev [options] [command] (print some logs for dev)

Options:
  -V, --version  output the version number
  -c, --clone    use git clone
  -p, --private  directly git clone from private repository, make sure you have access to the repository
  -h, --help     output usage information

Commands:
  init|i         generate a new project
  config|cfg     config .saberrc
  list|ls        list available templates
  version|v      current cli version

Usage:
  - saber init templateName projectName     create a project from a template
  - saber config set <k> <v>                set config
  - saber config set registry $registryUri  set a template registry
  - saber config get <k>                    get config[k]
  - saber config get                        get total config
  - saber config reset                      reset total config
  - saber config select-registry            select registry from config.registries
  - saber config sr                         abbreviation of "saber config select-registry"
  - saber list                              list available templates
  - saber ls                                abbreviation of "saber list"
  - saber version                           current cli version
  - saber v                                 abbreviation of "saber version"

You can use saber config set registry {registrySource} to change templates' downloading source. Then it will get template from ${registrySource}/${templateName}

Download template from private gitlab

If you don't want to put your template on public git platform like github, you can set the private registry source first and then use saber init -p ${templateName} ${projectName}. It will directly execute shell script to clone the repository from the private registry. But make sure you have access to the private repository.

Supported templates

comming soon...

Develop template

The template repository should have files like below:

├── README.md // template description
├── meta.json // config custom field here
└── template // project template files
    └── anything you like!

meta.json

meta.json is where you define some magic things, which looks like this:

{
  "prompts": {
    "name": {
      "type": "string",
      "required": true,
      "label": "Project name"
    },
    "description": {
      "type": "string",
      "required": true,
      "label": "Project description",
      "default": "A demo project"
    },
    "author": {
      "type": "string",
      "label": "Author"
    },
    "license": {
      "type": "string",
      "label": "License",
      "default": "MIT",
      "validate": "function(answer) {var licenses = ['LGPL', 'MIT', 'GPL']; if (!licenses.includes(answer)) {return `License should be one of ${licenses}`} return true}"
    },
    "test_checkbox": {
      "type": "checkbox",
      "label": "test_checkbox",
      "choices": [
        {
          "value": "A",
          "name": "A"
        },
        {
          "checked": true,
          "value": "B",
          "name": "B"
        }
      ]
    },
    "include_filters_dir": {
      "type": "confirm",
      "label": "test_confirm"
    }
  },
  "skipInterpolation": [
    "skip/**"
  ],
  "filters": {
    "filters/**": "data.include_filters_dir === true"
  },
  "completeMessage": "To get started:\n\n  cd {{destDirName}}\n  npm install\n  npm run dev"
}

The meta option interface:

type MetaOption = {
  prompts?: MetaPrompts;// prompts to show when initializing the project
  filters?: MetaFilters; // include some files only when satisfy some condition
  skipInterpolation?: string|string[]; // files not render with meta data,just simply copy
  completeMessage?: string; // displaying message when completing (when `complete` is not defined)
  complete?: (metadata: Object) => any; // callback function when completing
}
prompts

use prompts field to define everything you need to know when initial the template. the prompt interface looks like below:

type MetaPrompt = {
  type: string; // prompt type, see https://www.npmjs.com/package/inquirer
  message?: string; // tips message
  label?: string; // tips message, same as `message`
  required?: boolean; // whether be required or not
  default?: any; // default value
  when?: string; // if `when` expression value is true, then this prompt will show
  choices?: any[]; // needed when type is like 'list', 'checkbox' and so on
  validate?: string | ((...args: any[]) => boolean|string); // validate the input value
}

filters

filters interface:

type MetaFilters = {
  // propName is fileblob tell whether the file will be detect or not
  // the value is an expression return a boolean,
  // if it is false, then the file will be not be generated in the final project.
  // filename blob pattern see https://www.npmjs.com/package/minimatch
  [propName: string]: string // filenameBlob: conditionExpression
}

skipInterpolation

skipInterpolation tell the files which will be skiped during rendering files with handlebarsjs. See multimatch for match patterns.

Render template

We use handlebarsjs to render template content with meta data. So learn the handlebarsjs template syntax at first.

Develop

yarn link