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

create-quick

v1.6.0

Published

约定代替编码的脚手架搭建工具

Downloads

15

Readme


介绍

create-quick对脚手架核心业务进行封装,使用者只需关心脚手架的内容,约定代替编码的方式更灵活、迅速的创建脚手架

演示

npm create quick
# or
npm init quick
# or
npx create-quick

约定

templates文件夹就是我们脚手架模板存放的地方,里面使用约定代替配置的方式,有着以下约定

  • templates文件夹里面的第一层为模板名,例如:templates/vue3、templates/nest
  • 模板名里面有着三个文件夹,分别是baseoptionsejs(可通过配置变量自定义命名)
  • options文件夹里面的各种选项里面的文件目录需要跟base目录一一对应
  • options里面的package.json会和base的package.json进行合并,其他文件全是替换
  • options里面的ejsData.js为参数变量,用于给ejs模板引擎渲染的,同时里面可以定义一个回调函数,到该options执行完成之后会调用回调函数,可以接收两个值,一个是新项目路径,一个是config参数。该文件也不会添加到base里(可通过配置变量自定义命名)
  • ejs文件夹为模板引擎,里面的文件目录也是和base目录一一对应,例如:main.ts.ejs文件名最终合并到base里面的名字为main.ts,也会覆盖base

核心函数createTemplate接收三个参数:

const config: configType = {	// 渲染参数
    projectName: 'default-project',
    template: 'vue3',
    ejsVarAilas: 'config-text.js',
    options: ['pinia', 'prettier', 'vue-router']
}

const templatesRoot = path.resolve(__dirname, './templates')	// 模板文件夹path

createTemplate(config, templatesRoot, ({ newProjectPath }) => {
    // 渲染完成的回调函数
    console.log(`创建完成,新项目路径为${newProjectPath}`)
})

仓库里面的入口文件index.ts询问方式可以自定义,你只需要将数据给到createTemplate渲染函数即可

渲染流程

1. 数据传递createTemplate函数

2. createTemplate函数内部设置参数默认值

3. 复制Base文件夹进入目标路径

4. 递归Options文件夹下面的所有ejsData.js文件并获得它们的Key,因为ejs模板存在不存在的Key会报错(考虑换一个)

5. 根据数据里的options渲染指定的插件,并且加载插件目录下的ejsData.js数据

6. 渲染Ejs文件夹

7. 调用收尾函数 (重置package.json文件)

8. 调用用户的回调函数

renderTemplate下面有三个文件夹 baseejsoptions

第一步:直接递归复制base

第二步:递归options里面所有的ejsData.js数据,但是并不赋值,将Key记录,因为ejs不能渲染不存在的Key

第三步:传递过来的options数据选择需要的进行options文件夹进行复制,并且读取里面的ejsData.js数据

第四步:根据ejsData.js数据进行渲染ejs文件夹所有文件

第五步:调用内部收尾函数

第六步:调用渲染函数的回调函数

TODO:修改渲染代码,ejsData.js里的回调函数数据不全、文档未完善

快速上手

前往最小化demo仓库 create-mini-quick

疑问交流

QQ群: qian-cli(746382337)