Ozeebee's fork of caz template-based project generator / scaffolding tool.
Goal of the fork:
- Allow optional installation of template dependencies (templates don't depend anymore on Caz dependencies -- unless you want to)
- Report error when template loading fails because of a module error
To install template dependencies, pass the -t
or --tpldeps
flag on the command line.
If you use this option, you must not share dependencies of your template with caz ones as described here.
The author(s) of caz prefer not to install template dependencies to "ensure that the templates are simple and take less space" (as described here).
While this is a noble goal and may accomodate simple use cases, it means you cannot use any third party library except the ones caz uses by itself (and provided you implement their 'trick' to re-use their dependencies).
This can be very limitating for more sophisticated templates or ones that just need one or two additional libraries.
Therefore, this forks allows the optional installation of template dependencies while keeping the original behaviour if this is not needed.
npx ozeebee/caz [template] -t
This fork is not published to the npm registry.
So, to use it from Github with npx
, we have to commit the transpiled code as well.
- Build with
npm run build_
- Commit and publish
There is a bug in npm/npx that makes the npx
command fail with a Github repo if there is a script called build
or prepare
in package.json
(which is the case).
This happens only when running npx on a remote repo.
That's the reason why these npm scripts have been renamed to build_
and prepare_
(until this bug is fixed in npx).
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.
- Easy to use
- Light-weight
- Still powerful
- High efficiency
- Less dependencies
- Template-based
- Configurable
- Extensible
- TypeScript
- Use modern API
I'll give you specific reasons later.
- Introduction
- Usage
- Build and publish
- Internals
- Table of Contents
- Getting Started
- Recipes
- Advanced
- References
- Motivation
- About
- Roadmap
- Contributing
- License
# install it globally
$ npm install -g caz
# or yarn
$ yarn global add caz
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]
-f, --force
: Overwrite if the target exists-o, --offline
: Try to use an offline template
$ 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.
$ 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.
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
.
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
.
$ 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.
CAZ allows you to specify prompt response answers through cli parameters.
$ caz minima my-project --name my-proj
$ 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.
Show all available templates
$ caz list [owner] [-j|--json] [-s|--short]
[owner]
: GitHub orgs or user slug, default:'caz-templates'
-j, --json
: Output with json format-s, --short
: Output with short format
Current available templates list:
- template - for creating caz templates.
- nm - for creating node modules.
- react - for creating modern react app.
- vue - for creating modern vue.js app.
- vite - for creating vue.js app powered by vite.
- electron - π§ for creating electron app.
- mp - π§ for creating wechat mini-programs.
- jekyll - π§ for creating jekyll site.
- x-pages - for creating x-pages static site.
Maybe more: https://github.com/caz-templates
You can also run
$ caz list
to see all available official templates in real time.
$ 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.
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
.
# install it locally
$ npm install caz
# or yarn
$ yarn add caz
with ESM and async/await:
import caz from 'caz'
;(async () => {
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.
Create new project from a template
- Type:
string
- Details: template name
- Type:
string
- Details: project name
- Default:
'.'
- Type:
object
- Details: options & prompts override
- Default:
{}
Type: boolean
Details: overwrite if the target exists
Default: false
Type: boolean
Details: try to use an offline template
Default: false
Type: any
Details: cli options to override prompts
π π β
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.
Nothing else.
P.S. The picture is from the Internet, but I have forgotten the specific source, sorry to the author.
The core code is based on the middleware mechanism provided by zce/mwa.
The following middleware will be executed sequentially.
- confirm - Confirm destination by prompts.
- resolve - Resolve template from remote or local.
- load - Load template config by require.
- inquire - Inquire template prompts by prompts.
- setup - Apply template setup hook.
- prepare - Prepare all template files.
- rename - Rename file if necessary.
- render - Render file if template.
- emit - Emit files to destination.
- install - Execute
npm | yarn | pnpm install
command. - init - Execute
git init && git add && git commit
command. - complete - Apply template complete hook.
- 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
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).
- Fork it on GitHub!
- Clone the fork to your own machine.
- Checkout your feature branch:
git checkout -b my-awesome-feature
- Commit your changes to your own branch:
git commit -am 'Add some feature'
- Push your work back up to your fork:
git push -u origin my-awesome-feature
- 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!
Distributed under the MIT License. See LICENSE for more information. Β© ζ±ͺη£