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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ime-cli

v0.0.5

Published

demo project for learn node comand line.

Readme

ime-cli node命令行工具程序开发

node开发命令行程序越来越常见,基于node底层而开发前端工具越来越多。基本上包括前端开发方方面面。现在简单看一下一个入门级的node命令工具开发的全过程。

预览 ime-cli 程序

$ npm install -g ime-cli
$ ime -h 
$ ime dict -q "hello" // 翻译 hello
$ ime weather -c "上海" // 查询上海天气 hello

步骤

1.安装node、npm程序

2.写一个js可执行脚本 ./bin/ime ,(文件在首行添加)

    #!/usr/bin/env node

3.修改 ime 文件的执行权限

    chmod 755 ime   // 需要下载 git,使用 git-bash 命令行执行 

4.编辑package.json的文件, bin 字段,并添加相关依赖包

 "name": "ime-cli",
 "version": "0.0.1",
 "bin": {
    "ime": "./bin/ime"
  },
 "dependencies": {
    "axios": "^0.15.2",
    "colors": "^1.1.2",
    "commander": "^2.9.0",
    "inquirer": "^1.2.2",
    "lodash": "^4.16.5",
    "shelljs": "^0.7.5",
    "cli-table":"^0.3.1"
  }

5.编写主要逻辑放于 ./cmds目录下,并测试自己的程序

    $ ./bin/ime [command] [options]
    excample : 
         $ ./bin/ime -h
         $ ./bin/ime init
         $ ./bin/ime dict -l
         $ ./bin/ime dict -q "hello"

6.执行 npm link 将命令pkg中bin字段设置命令链接到全局,如果 npm link 报错,可以执行 npm install -g .(这个步骤不是必须的,可以跳过,直接进入第7步 )

    /** 
     * 本地可以执行以下命令,但是别人不能npm install -g ime-cli 下载使用
    */
    $ ime -h
    $ ime init
    $ ime dict -l
    $ ime dict -s "hello"

7.将本地命令行发布到npm中,其他小伙伴就可以在任何地方下载使用

  • npm config set registry https://registry.npmjs.org 将当前的npm镜像,切换为npmjs官方镜像
  • npm adduser 如果之前没有npmjs账号就新建一个账号(注意!!!这里需要用一定记住,user账号和密码,方便下一次发布新版本使用,发布新版本必须相同账号发布。如果记不住,将不能用这个npm包名字再次发布,只能换一个npm名字发布。切记)
  • npm login 有账号直接登录
  • npm bulish 一定要确保发布的包的名字唯一。不唯一的话需要修改一个唯一的名字。注意每一次发布的时候,需要修改一下version版本号, 这样已经下载过改cli的小伙伴,可以直接npm update就可以检测最新的代码改动。

依赖包

  • commander node命令行包,是tj大神作品。用nodejs包装了基于bash风格的命令行程序,所需要的格式,只需要几个超级简单的api就可以获得用户指令,并响应相应操作。
  • inquirer node命令行与用户交互的包,提供基于一个cli的可视化交互界面,包含input,checkbox,editor,confirm等等模式,可以验证用户输入,提供友好的cli界面。
  • shelljs 用nodejs封装的bash的基本操作,包含cd、rm、mv、cp、touch、exec等等,良好的跨平台性。能够非常方便的操作计算里的文件和执行安装服务。
  • lodash js基本数据操作的工具包,不包含dom操作
  • axios 将http请求包装成Promise对象,有点类似于jq的$.ajax()。
  • colors 修改node命令行界面输出 文本颜色。
  • cli-table 命令行输出表格

示例

example 目录下有很多演示文件,可以分别执行看一下效果,并拿到自己项目中使用

  • example/commander/example
  • example/inquirer/example

commander例子 查看

   $ cd example/commander/example 
   $ ./coercion -h 
   ...

inquirer例子 查看

   $ cd example/inquirer
   $ npm install 
   $ cd ./example
   $ node bottom-bar.js
   ...