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

template-generation

v0.1.9

Published

Automatically generate files based on templates

Downloads

5

Readme

template-generation

根据模板文件自动生成新文件,减少无用的重复劳动力

只需编写模板文件(支持简易的模板语法),配置需要的变量,即可快速生成新的模板/页面文件,提高开发效率

Install

$ npm i template-generation --dev
// or
$ yarn add template-generation --dev

Usage

引入:

const Generator = require('template-generation')

example

// script.js
new Generator({
  promptList: [
    {
      type: 'input',
      message: '请输入该页面的标题',
      name: 'title'
    }
  ],
  outputName: '',
  outputPath: './demo',
  templatePath: './test'
})
// package.json
"scripts": {
  "new": "node ./script.js"
},

params

Generator构造函数接受一个配置对象,配置对象有四个参数

  • 第一个参数是 Inquirer.js 的问题数组
  • 第二个参数是输出文件名(仅在输入模板 templatePath 为文件时有效)
  • 第三个参数是输出文件路径(输入为相对路径时,是相对于运行脚本的位置)
  • 第四个参数是模板文件路径

模板文件可以使用模板语法: 其中注意插入的变量名要与 Inquirer.js 的问题数组变量名相对应

// 插入变量名(一定要添加this开头)
<%= this.title %>

// 插入代码
<% if( this.title  ) {%>
const c = 10
<%}%>