• Stars
    star
    2,419
  • Rank 18,911 (Top 0.4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple yet powerful template-based Scaffolding tools.
CAZ

A simple yet powerful template-based Scaffolding tools for my personal productivity.

Build Status Coverage Status License NPM Version Node Version
Code Style NPM Downloads Install Size Repo Size Dependencies Status


English | 简体中文

Introduction

CAZ (Create App Zen)

It's a a simple template-based Scaffolding tools for my personal productivity, inspired by Yeoman & Vue CLI 2 & etc.

  • pronounced: [kæz] 📷
  • written: CAZ / caz

For more introduction, please refer to the How it works.

Features

  • Easy to use
  • Light-weight
  • Still powerful
  • High efficiency
  • Zero dependencies
  • Template-based
  • Configurable
  • Extensible
  • TypeScript
  • Use modern API

I'll give you specific reasons later.

Table of Contents

Getting Started

Prerequisites

  • Node.js (>= 14.14 required, >= 16.13 preferred)
  • npm (>= 7.x) or pnpm (>= 6.x) or yarn (>= 1.22)
  • Git (>= 2.0)

Installation

# install it globally
$ npm install -g caz

# or yarn
$ yarn global add caz

Quick Start

Create new project from a template.

$ caz <template> [project] [-f|--force] [-o|--offline]

# caz with an official template
$ caz <template> [project]

# caz with a github repo
$ caz <owner>/<repo> [project]

If you only use it occasionally, I recommend that you use npx to run caz directly.

$ npx caz <template> [project] [-f|--force] [-o|--offline]

Options

  • -f, --force: Overwrite if the target exists
  • -o, --offline: Try to use an offline template

Recipes

GitHub Repo Templates

$ caz nm my-project

The above command pulls the template from caz-templates/nm, then prompts for some information according to the configuration of this template, and generate the project at ./my-project.

$ caz nm#typescript my-project

By running this command, CAZ will pulls the template from typescript branch of caz-templates/nm.

Use Custom templates

$ caz zce/nm my-project

The above command pulls the template from zce/nm. This means that you can also pull templates from your public GitHub repository.

Public repository is necessary.

Local Templates

Instead of a GitHub repo, you can also use a template on your local file system.

e.g.

$ caz ~/local/template my-project

The above command use the template from ~/local/template.

Remote ZIP Templates

Instead of a GitHub repo, you can also use a template with a zip file uri.

e.g.

$ caz https://cdn.zce.me/boilerplate.zip my-project

The above command will download & extract template from https://cdn.zce.me/boilerplate.zip.

Offline Mode

$ caz nm my-project --offline

By running this command, CAZ will try to find a cached version of nm template or download from GitHub if it's not yet cached.

Prompts Override

CAZ allows you to specify prompt response answers through cli parameters.

$ caz minima my-project --name my-proj

By running this command, you don't have to answer the next name prompts.

Debug Mode

$ caz nm my-project --debug

--debug parameter will open the debug mode.

In debug mode, once an exception occurs, the exception details will be automatically output. This is very helpful in finding errors in the template.

List Available Templates

Show all available templates:

$ caz list [owner] [-j|--json] [-s|--short]

Arguments

  • [owner]: GitHub orgs or user slug, default: 'caz-templates'

Options

  • -j, --json: Output with json format
  • -s, --short: Output with short format

Official Templates

Current available templates list:

Maybe more: https://github.com/caz-templates

You can also run $ caz list to see all available official templates in real time.

All templates are currently hosted on GitHub, Chinese users can use the mirror on coding.net.

Advanced

Configuration

CAZ will read the configuration file in ~/.cazrc, default config:

; template download registry
; {owner} & {name} & {branch} will eventually be replaced by the corresponding value.
registry = https://github.com/{owner}/{name}/archive/{branch}.zip
; template offlicial organization name
official = caz-templates
; default template branch name
branch = master

This means that you can customize the configuration by modifying the configuration file.

For example, in your ~/.cazrc:

registry = https://gitlab.com/{owner}/{name}/archive/{branch}.zip
official = faker
branch = main

Then run the following command:

$ caz nm my-project

The above command will download & extract template from https://gitlab.com/faker/nm/archive/main.zip.

Mirror for Chinese

Due to network limitations, the template download may time out, you can consider using the mirror repository I configured on coding.net.

~/.cazrc:

registry = https://zce.coding.net/p/{owner}/d/{name}/git/archive/{branch}
official = caz

Socks Proxy

CAZ supports socks proxy config.

~/.cazrc:

proxy = socks5://127.0.0.1:1080

or environment variable:

$ ALL_PROXY=socks5://127.0.0.1:1080 caz nm my-project

Create Your Template

$ caz template my-template

The above command will pulls the template from caz-templates/template, and help you create your own CAZ template.

To create and distribute your own template, please refer to the How to create template.

Maybe fork an official template is also a good decision.

Create Your Scaffold

# install it locally
$ npm install caz

# or yarn
$ yarn add caz

with ESM and async/await:

import caz from 'caz'

try {
  const template = 'nm'
  // project path (relative cwd or full path)
  const project = 'my-project'
  const options = { force: false, offline: false }
  // scaffolding by caz...
  await caz(template, project, options)
  // success created my-project by nm template
} catch (e) {
  // error handling
  console.error(e)
}

or with CommonJS and Promise:

const { default: caz } = require('caz')

const template = 'nm'
// project path (relative cwd or full path)
const project = 'my-project'
const options = { force: false, offline: false }
// scaffolding by caz...
caz(template, project, options)
  .then(() => {
    // success created my-project by nm template
  })
  .catch(e => {
    // error handling
    console.error(e)
  })

This means that you can develop your own scaffolding module based on it.

To create and distribute your own scaffolding tools, please refer to the How to create scaffolding tools based on CAZ.

References

caz(template, project?, options?)

Create new project from a template

template

  • Type: string
  • Details: template name, it can also be a template folder path

project

  • Type: string
  • Details: project name, it can also be a project folder path
  • Default: '.'

options

  • Type: object
  • Details: options & prompts override
  • Default: {}
force
  • Type: boolean
  • Details: overwrite if the target exists
  • Default: false
offline
  • Type: boolean
  • Details: try to use an offline template
  • Default: false
[key: string]
  • Type: any
  • Details: cli options to override prompts

Motivation

👉 🛠

Joking: I want to make wheels ;P

The real reason is that I think I need a scaffolding tool that is more suitable for my personal productivity. The existing tools have more or less certain limitations because of their different starting points.

Nothing else.

Concepts

How It Works

Scaffolding flow

P.S. The picture is from the Internet, but I have forgotten the specific source, sorry to the author.

Main Workflow

The core code is based on the middleware mechanism provided by zce/mwa.

The following middleware will be executed sequentially.

  1. confirm - Confirm destination by prompts.
  2. resolve - Resolve template from remote or local filesystem.
  3. load - Install template dependencies, load template config by require.
  4. inquire - Inquire template prompts by prompts.
  5. setup - Only apply template setup hook function.
  6. prepare - Filter out unnecessary files and prepare all files to be generated.
  7. rename - Rename each file if the filename contains interpolations.
  8. render - Render the contents of each file if template.
  9. emit - Emit files to destination.
  10. install - Execute npm | yarn | pnpm install command if necessary.
  11. init - Execute git init && git add && git commit command if necessary.
  12. complete - Only apply template complete hook function.

Built With

  • adm-zip - A Javascript implementation of zip for nodejs. Allows user to create or extract zip files both in memory or to/from disk
  • cac - Simple yet powerful framework for building command-line apps.
  • env-paths - Get paths for storing things like data, config, cache, etc
  • fast-glob - It's a very fast and efficient glob library for Node.js
  • ini - An ini encoder/decoder for node
  • lodash - Lodash modular utilities.
  • node-fetch - A light-weight module that brings Fetch API to node.js
  • ora - Elegant terminal spinner
  • prompts - Lightweight, beautiful and user-friendly prompts
  • semver - The semantic version parser used by npm.
  • validate-npm-package-name - Give me a string and I'll tell you if it's a valid npm package name

Roadmap

The following are the features I want to achieve or are under development:

  • config command
  • cache command
  • all lifecycle hooks
  • console output (colorful & verbose)
  • more and more official templates

See the open issues for a list of proposed features (and known issues).

Contributing

  1. Fork it on GitHub!
  2. Clone the fork to your own machine.
  3. Checkout your feature branch: git checkout -b my-awesome-feature
  4. Commit your changes to your own branch: git commit -am 'Add some feature'
  5. Push your work back up to your fork: git push -u origin my-awesome-feature
  6. Submit a Pull Request so that we can review your changes.

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

License

Distributed under the MIT License. See LICENSE for more information. © 汪磊

More Repositories

1

fearless

A dashboard scaffolding based on Vue.js 3.x & TypeScript created by Vite.
TypeScript
1,281
star
2

weapp-example

微信小程序示例教程
696
star
3

dashboard

A dashboard scaffolding based on Vue.js 3.0 created by Vite.
Vue
547
star
4

weapp-boilerplate

一个为微信小程序开发准备的基础骨架。A boilerplate application for wechat weapp runtime.
JavaScript
546
star
5

api-proxy

466
star
6

velite

Turns Markdown / MDX, YAML, JSON, or others into app's data layer with Zod schema.
TypeScript
377
star
7

weapp-todos

一个简单的任务清单小程序, awesome weapp demo, todos, todolist
JavaScript
279
star
8

music-player

a music player by express & angular || vue
JavaScript
179
star
9

weapp-locally

A locally app demo for wechat mini-program runtime.
JavaScript
171
star
10

weapp-beauty

一个测颜值的小程序,只为最美的你~
JavaScript
85
star
11

caz-prev

A simple yet powerful template-based Scaffolding tools.
TypeScript
85
star
12

html5up

HTML5 UP! Responsive HTML5 and CSS3 Site Templates
CSS
68
star
13

vue-devtools

An electron devtools extension for debugging Vue.js applications.
JavaScript
61
star
14

webpack-demo

webpack tutorials demo
JavaScript
53
star
15

dashboard-server

A JSON file RESTful API with authorization based on json-server
JavaScript
51
star
16

x-pages

A simple static pages development workflow (static site generator maybe)
JavaScript
47
star
17

vite-essentials

Vite essentials
JavaScript
42
star
18

baixiu

baixiu proj
PHP
38
star
19

zce-cli

A CLI tool for my personal productivity, Scaffolding tools move to zce/caz 👉
JavaScript
37
star
20

angular-boilerplate

JavaScript
33
star
21

vuejs-3-examples

Some examples of Vue.js 3.0.
Vue
28
star
22

electron-boilerplate

🚧 A boilerplate application for Electron runtime
TypeScript
24
star
23

baixiu-docs

baixiu proj documents
20
star
24

asar-updater

An auto updater for electron asar
JavaScript
17
star
25

tcb

All my tencent cloudbase sources.
HTML
17
star
26

ajax-tutorial

AJAX 网络编程基础教程
17
star
27

windows-st-portable

Sublime Text 3 portable version include some package(汪磊的Sublime Text 3绿色便携版,包括一些常用插件)
Python
17
star
28

angular-moviecat

moviecat by angular stack
JavaScript
15
star
29

newshop

基于 Node.js 中间层前后端分离架构方案实现的电商系统前台,UI 的 Code 由于时间的关系用的是别人堆出来的,有点乱~
TSQL
14
star
30

locally-server

A JSON file RESTful API based on json-server for zce/weapp-locally & zce/quickapp-locally
HTML
14
star
31

zce-gulp-demo

HTML
13
star
32

music-player-pages

A special feeling music player page
HTML
13
star
33

quickapp-locally

🚧 🚧 一个快应用的示例项目
12
star
34

itcast-tms

Itcast Teaching Management System
JavaScript
12
star
35

creative-theme

A personal blogging theme for Ghost, inspired by Casper
JavaScript
12
star
36

short

A short url service.
HTML
11
star
37

pages-store

GitHub Pages Storage Adapter for Ghost
JavaScript
10
star
38

web-essential-docs

Web 开发基础手册,以 PHP 为例
10
star
39

mobile-remote-control

smart phone remote control with node.js and socket.io
JavaScript
10
star
40

pages-boilerplate

Always a pleasure scaffolding your awesome static sites.
HTML
9
star
41

koa-xtpl

A node.js wrapper around xtemplate engine (easier for Koa 2)
JavaScript
9
star
42

generate-weapp-page

Auto generate wechat weapp page
JavaScript
8
star
43

mwa

TypeScript
7
star
44

qiniu-store

Qiniu Storage for Ghost
JavaScript
7
star
45

weapp-demo

微信小程序示例教程,案例涉及某瓣,所以下线了:https://github.com/zce/weapp-douban
7
star
46

github-hosts

6
star
47

reborn-pages

zce.me site pages
CSS
6
star
48

quickapp-boilerplate

6
star
49

oauth2-example

oauth2 server & client example
JavaScript
6
star
50

learning-webpack

Learning Webpack
JavaScript
6
star
51

babel

babel-core browser lib
JavaScript
5
star
52

chrome-markdown

Preview GitHub Flavored Markdown in Chrome
JavaScript
5
star
53

clean-blog

HTML
5
star
54

todos

Examples of any framework
JavaScript
5
star
55

quickapp

🚧 🚧 🚧 一个帮你管理 hap-tools(快应用开发工具)依赖项并封装其编译功能的模块,开箱即用,减少痛苦
JavaScript
5
star
56

feedback

A feedback system using electron
JavaScript
4
star
57

windows-st-portable-x64

汪磊的 sublime text 3 portable include some package
Python
4
star
58

react-ssr-demo

React SSR demo
JavaScript
4
star
59

learning-vue

Learning Vue.js
HTML
4
star
60

micua

C#
4
star
61

typora-reborn

reborn theme for Typora
CSS
4
star
62

newshop-live

随堂代码,完整版移步:
CSS
3
star
63

teachable-machine

JavaScript
3
star
64

zce

The zce personal info CLI
JavaScript
3
star
65

angular-todomvc

HTML
3
star
66

baixiu-pages

alibaixiu pages
HTML
3
star
67

jysrt

Extract srt contents from Jianying Pro projects.
HTML
3
star
68

webpack-multi-entry

HTML
3
star
69

minima.css

A personal minimalist CSS framework for myself, inspired by Mifa based on Milligram.
CSS
3
star
70

macos-st-packages

macOS Sublime Text 3 packages backup
Python
3
star
71

gatsby-plugin-minify

A Gatsby plugin to easily minify all result.
JavaScript
3
star
72

mock-prompt

mock inquirer prompt
JavaScript
3
star
73

m2i-cli

📝 ⇢ 🌄 A minimalist markdown to image converter
TypeScript
3
star
74

x-pages-example

An example of x-pages (Deprecated: See zce/pages-boilerplate#x-pages instead)
HTML
3
star
75

baixiu-backup

baixiu proj 👉
PHP
2
star
76

recorder

JavaScript
2
star
77

dashboard-pages

A dashboard pages
JavaScript
2
star
78

create-v-app

Create Vue apps with no build configuration.
JavaScript
2
star
79

osx-st-packages

macOS sublime text 3 packages backup
Python
2
star
80

create-pages

Set up a modern pages project by running one command.
JavaScript
2
star
81

on-line

Deprecated, Check if the internet connection is up 👉
JavaScript
2
star
82

zce.github.io

zce’s homepage
HTML
2
star
83

graphql-demo

JavaScript
2
star
84

node-xtemplate

A node.js wrapper around xtemplate engine
JavaScript
2
star
85

zce-react-app

JavaScript
2
star
86

m2i-server

A service to convert markdown to image.
HTML
2
star
87

douban-api-docs

2
star
88

Weibo

React Native Sina Weibo
Objective-C
2
star
89

ooh-node

Ooh node~
JavaScript
2
star
90

fakers

fake data in the browser and node.js
JavaScript
1
star
91

chrome-apps

JavaScript
1
star
92

simple-theme

A Simple Theme for Sublime Text, base on Theme - Soda
JavaScript
1
star
93

embed-parser

A parser for get embed data from url
JavaScript
1
star
94

reborn-mvc

A CoC MVC web framework for node.js
JavaScript
1
star
95

vue-ssr-demo

Vue.js SSR Demo
JavaScript
1
star
96

rime

汪磊(iceStone)的 Rime 输入法配置
Makefile
1
star
97

qrcode-server

QRCode Generator Server
TypeScript
1
star
98

node-mvc

node mvc from asp.net mvc
JavaScript
1
star
99

aeroplane

JavaScript
1
star
100

desktop-ui

desktop style pages
CSS
1
star