1.0.0 • Published 12 months ago
template-new-cli v1.0.0
English | 简体中文
Table of Contents
Introductions
CLI to new files by nunjucks template
Blog
comming soon
Features
- Generate files through nunjucks templates
- Provide parameters in two ways: command line and JavaScript file
Install
npm install template-new-cli -g
Template Preparation
Template Directory Structure
.templates
├─ template_file (Template Name) [Single File Template]
│ └─ @@config.js (Template Replacement Parameter List Configuration File)
│ └─ @@params.js (Template Replacement Parameter Object) [optional]
│ └─ file_name.js (Template File)
├─ template_folder (Template Name) [Folder Template]
│ └─ @@config.js (Template Parameter List Configuration File)
│ └─ component_name (Template Folder)
│ └─ file_name.css
│ └─ file_name.html
│ └─ file_name.js
├─ callback.js (Callback)
└─ global.js (Global Parameter)
@@config.js
exports.fileParams = ["file_name"];
exports.templateParams = [];
@@params.js
module.exports = () => {
return {
fileParams:{
file_name: 'helloworld',
},
templateParams:{
content: 'hello',
}
};
};
Template Language
use nunjucks
Usage
Init
To confirm the location of .templates
folder, an initialization operation needs to be performed in the directory where .templates
folder is located
tp-new init
Normal Create
Enter the directory where you want to create the file and execute
tp-new new
Create By ComponentName
Enter the directory where you want to create the file and execute
tp-new new [Template Name]
Use Params From Global
config global.js
module.exports = () => {
return {
prefix: "tp",
}
}
Enter the directory where you want to create the file and execute
tp-new new [Template Name]
Use Params From File
update @@config.js
exports.fileParams = [];
exports.templateParams = [];
update @@params.js
module.exports = () => {
return {
fileParams:{
file_name: 'helloworld',
},
templateParams:{
}
};
};
Enter the directory where you want to create the file and execute
tp-new new [Template Name] -p [Path Of Params File]
ChangeLog
License
1.0.0
12 months ago