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

myy-cli

v1.1.2

Published

A command tool

Downloads

7

Readme

mcli脚手架工具

做这个的原因,就是写一些小项目的时候,老是要重新配置,所以写一个可以快速生成项目的

usage

  npm install -g myy-cli
  mcli init hello

总结

涉及到库:commander, chalk, metalsmith, ora, rimraf, download-git-repo, handlebars, inquirer

  1. 利用package.json的bin选项指定命令名和可执行文件的位置

  2. commander.parse之后,会自动执行执行子命令。比如在命令行输入mcli init hello, commander在解析完参数之后,获取第一个参数init,自动拼接成一个新文件名mcli-init,然后尝试寻找mcli-init.js文件来执行。第二个参数hellocommander.args[0]可获取到。所以分成了两个文件

  3. chalk,一个颜色插件,可以改变命令行文字颜色

  4. ora, 显示等待图标的插件

  5. rimraf, 用于删除文件的插件

  6. download-git-repo, 用于从github拷贝模板的插件

  7. inquirer, 提供交互式命令的插件,基本用法可见mcli-init.js文件,每一个问答都会被封装到then的answer里,answer是一个对象,它的key是之前的name字段,value是回答的答案

  8. metalsmith,静态网站生成器,这里可以简单理解为用于批量处理模板

  9. handlebars,模板引擎,具体用法见generator.js,就一行Handlebars.compile(t)(meta),第一个参数是模板字符串,meta是要替换的键值对

8,9主要用于模板插值,为什么要这个,因为想实现init不同的项目名称, 相关文件里的文件名也要对应替换的效果

metalsmith有一个metadata的东西,可以理解为全局的变量对象。把需要替换的键值放进去。

基本流程:mcli init xxx获取xxx为项目名称。检测同名文件夹是否已存在等等,然后交互式命令,确定名称,版本号,简介。这些为要替换的东西,也就是metadata。然后从github拉取模板,下载完成后,用metalsmith和handlebars替换模板内容,结束

UPDATE

  1. 使用cac替代commander,原因是看到了vuepress用了,尝试一下,感觉api更简洁。另外使用高阶函数可以非常有效的解耦代码