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

burt-cli

v0.0.1

Published

cli

Downloads

2

Readme

commander: 要解析用户的参数

const program = rquire('commander');
// 解析用户传递过来的参数
program.parse(process.argv);
// 版本号
program.version(pkg.version);
  1. 定义全局选项 使用option()定义全局选项,可以定义多个全局选项。第一个参数为选项的名称和别名,需要使用空格来分割。第二个参数为该选项的描述信息。第三个参数为选项默认值。
program
  .option("-d, --debug", "是否开启调试模式", false)
  // -e/--env后跟的字符,将存到envName属性中
  .option("-e, --envName <envName>", "获取环境变量名称", 'production');
  1. 获取选项键值对 使用opts()获取解析命令行参数后的选项键值对,属性名为选项的长标识
const opts = program.opts();
console.log(opts) // => {debug: false, envName: 'production'}
  1. 定义命令
  • 方式一:使用command()注册命令,<> 表示该参数是必须的。 description()定义该命令的描述信息。 alias()定义该命令的别名。 option()定义该命令的选项,用法与全局选项一致。 action()定义该命令要做的事情。
const clone = program.command("clone <source>");
clone
  // 命令描述
  .description("command clone")
  // 别名
  .alias("c")
  // 命令的选项
  .option("-f --force", "是否强制克隆", false)
  // 要做的事
  .action((source, cmdObj) => {
  // cmdObj-命令行键值对
  // mock-项目是否已克隆
  const cloned = true;
  if (cloned) {
    // 强制覆盖
    if (cmdObj.force) {
      console.log("项目已克隆,将强制覆盖");
      handleClone(source)
    } else {
      console.log("克隆失败!该项目已克隆");
    }
  } else {
    handleClone(source)
  }
});
function handleClone(source) {
  console.log("cloning...");
  console.log(`cloneSource is ${source}`);
  console.log("opts:", program.opts());
}
  • 方式二:使用addCommand()注册子命令 先定义一个Command对象,然后定义该对象的子命令。最后使用program.addCommand() 将该命令加入到主命令中
const service = new commander.Command("service");
service
.command("start [port]")
.description("start a new service at some port")
.action((port) => {
console.log("do service start", port);
});
service
.command("stop")
.description("stop service")
.action(() => {
console.log("stop service");
});
program.addCommand(service);
  1. 监听用户输入--help事件
program.on('--help', () => {
  console.log('哈哈哈')
})

拉取你自己的所有项目列出来,让用户选,安装哪个项目,选完后再列出来所有的版本号,可能还需要用户配置一些数据来结合渲染我的项目

  1. developer.github.com/v3/ 文档
// 获取组织下的仓库
// 例如:https://api.github.com/orgs/zhu-cli/repos
// 获取某一个项目的所有版本号
// 例如:https://api.github.com/repos/zhu-cli/vue-simple-template/tags


const axios = require('axios');

// 获取项目列表
const fetchRepoList = async () => {
  const { data } = await axios.get('https://api.github.com/orgs/zhu-cli/repos');
  return data;
}

// 在获取之前 显示loading 关闭loading
// ora 插件
const ora = require('ora')
const spinner = ora('加载中...')
spinner.start() // 开始

spinner.succeed() // 完成
  1. 下载仓库插件:download-git-repo
const { promisify } = require('utils')
let downloadGitRepo = require('download-git-repo')
downloadGitRepo = promisify(downloadGitRepo) // 将downloadGitRepo转换为promise对象

// 下载仓库 repo:仓库名 tag:版本号
const download = async (repo, tag) => {
  let api = `zhu-cli/${repo}`;
  if(tag){
    api += `#${tag}`;
  }
  downloadGitRepo(api, '项目名称')
}
  1. 拷贝目录文件插件 ncp
let ncp = require('ncp')
ncp(result, path.resolve(projectName))