Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/w3tecch/template-gen
A flexible template generator to create files by templates. Generate for example components, routes, service with a simple command and by your own templates.
https://github.com/w3tecch/template-gen
aurelia cli generate generator rc-configuration template template-library
Last synced: 3 days ago
JSON representation
A flexible template generator to create files by templates. Generate for example components, routes, service with a simple command and by your own templates.
- Host: GitHub
- URL: https://github.com/w3tecch/template-gen
- Owner: w3tecch
- License: mit
- Created: 2018-03-17T20:40:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-18T19:05:23.000Z (over 6 years ago)
- Last Synced: 2024-11-10T08:37:24.924Z (6 days ago)
- Topics: aurelia, cli, generate, generator, rc-configuration, template, template-library
- Language: JavaScript
- Homepage:
- Size: 55.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Template Generator
A delightful way to have a flexible template generator for all sorts of templates
Heavily inspired by Angular CLI and the Aurelia CLI.
Made with ❤️ by w3tech, David Weber and contributors
## ❯ Why
It's tedious to always copy & past the same file or file content over and over again. In addition the content has be clean up over and over because mostly we need a clean version of the content. This module can be used as a cli or integrated into any node based project.
## ❯ Table of Contents
- [Installation](#-installation)
- [Getting Started](#-getting-started)
- [RC configuration](#-rc-configuration)## ❯ Installation
### As global CLI
You can install this module globally by
```shell
npm install -g template-gen
```Have a look at [RC configuration](#-RC-configuration) how you can setup a template path.
### As project dependency
Add this module to your project dependencies
```shell
npm install template-gen --save-dev
```then add the following entry to your npm scripts
```json
{
"tg": "tg -d ./templates"
}
```## ❯ Getting Started
### Setup a template file
First you need to create a template folder. We recommend to use `templates` as name as this module will look for this folder automatically.
```shell
mkdir templates
```
> Alternatively you can pass the template path with parameter as shown in the installation instructions.
Next we need a template file. Create a file (e.g. `controller.js`) within the `templates` folder with the following content
```javascript
module.exports = {
name: 'Controller',
description: 'Creating a controller',
target: 'controllers',
wrapFolder: params => `${params.controller.toLowerCase()}`,
parameters: [
{
type: 'text',
name: 'controller',
message: 'Whats the controller name?'
},
{
type: 'confirm',
name: 'haveConstructor',
message: 'With a constructor?'
}
],
files: [
{
template: params => {
return `export default class ${params.controller} {
someAttribute = '';` +
(params.haveConstructor ? `constructor () {
}` : '') +
`
}
`;
},
fileName: params => `${params.controller}Controller.ts`
},
{
template: () => '',
fileName: params => `${params.controller}Controller.html`
}
]
}
```
> Don't forget to create the `controllers` folder
| Attribute | Description |
| -------------- | ----------- |
| name | The name to enter or select in the CLI |
| description | Will be shown after you selected the name in the CLI |
| target | The target directory from the root where the file will be created in |
| wrapFolder | Should be undefined or a function which returns the parent folder name |
| parameters | The CLI prompts to ask the user, you can use this [prompts](https://github.com/terkelg/prompts) options |
| files.template | The content of the generated file |
| files.fileName | The file name of the generated file |> The parameters attribute can be a object or an array of [prompts](https://github.com/terkelg/prompts) options.
### Usage
With the above example setup you can now run
```shell
npm run tg
```Then you will be asked for the template parameters and finally create the file.
### Use Parameters
If you have template like the above with name `Controller` and prompt `controller` then you could use this to execute without prompts
```shell
npm run tg -- Controller --controller User --haveConstructor true
```Or just if you just like to create a controller with prompts
```shell
npm run tg Controller
```## ❯ RC configuration
In you project root you can create a file named `.tgrc` to configure you template path
```shell
{
"path": "./templates"
}
```## ❯ Related Projects
- [aurelia-typescript-boilerplate](https://github.com/w3tecch/aurelia-typescript-boilerplate) - An Aurelia starter kit with TypeScript
- [express-typescript-boilerplate](https://github.com/w3tecch/express-typescript-boilerplate) - An express starter kit with TypeScript## ❯ License
[MIT](/LICENSE)