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

e2-cli

v1.2.3

Published

compile any file with ejs

Downloads

11

Readme

e2-cli

Compile any file with ejs!

npm package npm downloads github

img

img

安装

$ npm install -g e2-cli

使用

$ npx e2-cli

首次使用会创建两个文件和一个文件夹。

  • e2.config.json: 配置文件,用户存放模版和数据
  • .e2.data.json: 每个人独立的数据文件(需要添加到 .gitignore)
  • e2-tpl: 默认模版文件,可以按照需求自由定制

基础模版

/* e2.config.json */
{
  "component": {
    /* 非必须,会在模版列表显示, ${_description || component} */
    "_description": "添加组件",
    /* 非必须,ejs 编译的时候会附加到 e2 作用域下 */
    "_data": {},
    /* 非必须,需要用户输入的数据 */
    "_ask": [
      {
        "message": "请输入组件名称:",
        "name": "componentName"
      }
    ],
    /* 必须,模版列表 */
    "template": [
      {
        /* 是包含 . 开头的文件 */
        "dot": "false | true",
        "from": "e2-tpl/components/Component",
        "to": "src/components/<%= e2.componentName %>"
      }
    ]
  }
}

npx e2-cli 命名的时候会在模版列表里面看到 component 选项,选择即可使用。

使用之后会将 from 文件或文件夹通过 ejs 编译到 to 目录下。 fromto 内也可以使用 ejs 语法。

需要询问用户数据的信息,可以在 _ask 里面配置,具体语法可以参考 inquirer.

所以 ejs 中的数据会同时有 {..._data, ..._ask }

数据源

/* e2.config.json */
{
  "_data": {
    "version": "1.0.0",
    "authorName": "undefined"
  },
  "component": "/* others */"
}
/* .e2.data.json */
{
  "authorName": "你的名字"
}

e2.config.json 的一级目录下的 _data.e2.data.json 的数据会被合并之后附加到所有模版的数据中。

.e2.data.json 不一样的地方区别在于同一个项目,不同的用户拥有不同的数据,需要添加到 .gitignore.

内置数据

  • <%= e2.date %>: 使用模版时候的日期
  • <%= e2.ttc() %>: 首字母大写 (text-transform: capitalize;
  • <%= e2.ttl() %>: 全小写 (text-transform: lowercase;)

所有最后在 ejs 中的数据实际为:

{
    ...'内置数据', 
    ...'e2.config.json._data', 
    ...'.e2.data.json', 
    ...'e2.config.json[templateName]._data', 
    ...'e2.config.json[templateName]._ask'
}