# custom-template-generator

> generate file template

Latest version **0.1.2** (published 2017-11-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install custom-template-generator
pnpm add custom-template-generator
yarn add custom-template-generator
bun add custom-template-generator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2017-11-22 |
| First published | 2017-01-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.0 |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+11 in 2 direct dependencies) |
| Install scripts | no |
| Author | Mourad Sabour |
| Maintainers | m2omou |
| Keywords | template, generator, custom |

## Links

- npm: https://www.npmjs.com/package/custom-template-generator
- npm.io page: https://npm.io/package/custom-template-generator

## Dependencies (7)

- [lodash](https://npm.io/package/lodash.md) 4.17.4
- [mkdirp](https://npm.io/package/mkdirp.md) 0.5.1
- [inquirer](https://npm.io/package/inquirer.md) ^0.4.1
- [js-beautify](https://npm.io/package/js-beautify.md) ^1.6.14
- [string-template](https://npm.io/package/string-template.md) 1.0.0
- [underscore.string](https://npm.io/package/underscore.string.md) ^2.3.3
- [path-complete-extname](https://npm.io/package/path-complete-extname.md) ^0.1.0

## Recent versions

- 0.1.2 (latest) — 2017-11-22
- 0.1.1 — 2017-07-17
- 0.1.0 — 2017-07-07
- 0.0.9 — 2017-06-29
- 0.0.8 — 2017-05-23
- 0.0.7 — 2017-05-23
- 0.0.6 — 2017-05-23
- 0.0.5 — 2017-02-01
- 0.0.4 — 2017-02-01
- 0.0.3 — 2017-01-23
- 0.0.2 — 2017-01-23
- 0.0.1 — 2017-01-21

## README

## template-generator

[![npm version](https://badge.fury.io/js/custom-template-generator.svg)](https://badge.fury.io/js/custom-template-generator)

Help generate template files (angular, nodejs, backbone, java...)

## Prerequisites

This project has a dependencies that require Node to be installed. For help to install Node, go to:

https://nodejs.org

## Table of Contents

* [Installation](#installation)
* [Usage](#usage)

## Installation

**BEFORE YOU INSTALL:** please read the [prerequisites](#prerequisites)
```bash
npm install custom-template-generator
```

Once the plugin has been installed, just need to add this line:

```javascript
var generator = require('custom-template-generator');
```

## Usage


```javascript
var generator = require('custom-template-generator');

generator({
    componentName: "button",
    customTemplatesUrl: './templates/',
    dest: 'src',
    templateName: 'component'
    autoIndent: true,
    data: {
        someStaticData: {},
        size: 42,
        desc: 'this button can talk'
    }
});
```

### Options



Scaffold               | Type      | Usage
---                    |---        | ---
componentName          | `string`  | Name of the component
customTemplatesUrl     | `string`  | Location of the custom templates folder
dest                   | `string`  | Destination of generated templates files
templateName           | `string`  | Template name
autoIndent             | `boolean`  | Default set to false, will indent the whole file. Only works with js and ts files.
autoIndentExtensions   | `array`    | The list of extensions file to indent. Default ['js', 'ts']
data                    | `object` | This custom meta data can be injected in the custom template using '{}'


### Meta data

The meta data helps customize your templates, here are some options:


Name               | Description
---                |---
name               | Component name
Name               | capitalized component name

### Demo

In this repository, use the `demo` folder to test the generator. Here is the folder hierarchy:

<p align="center">
  <img src="https://github.com/m2omou/custom-template-generator/raw/master/demo/demo.png" alt="" />
</p>

To help customized the file name `{component}` will be replace by the componentName defined in the generator parameters. 

The following template `{component}.interface.ts`:

```javascript
// Angular imports
import { ElementRef, Renderer } from '@angular/core';
// Custom imports
import { {Name}Config } from './config/{name}.config';

export interface {Name}Interface<T> {
    /*
     * Model from the {name}.
     */
    model: T;
    /*
     * Stores config for the {name}.
     */
    readonly options: {Name}Config;
    /*
     * init
     */
    ngOnInit(): void;
}

```

By running this function

```javascript
generator({
    componentName: "button",
    customTemplatesUrl: './templates/',
    dest: 'src',
    templateName: 'component'
});
```

Will generate this file

```javascript
// Angular imports
import { ElementRef, Renderer } from '@angular/core';
// Custom imports
import { ButtonConfig } from './config/button.config';

export interface ButtonInterface<T> {
    /*
     * Model from the button.
     */
    model: T;
    /*
     * Stores config for the button.
     */
    readonly options: ButtonConfig;
    /*
     * init
     */
    ngOnInit(): void;
}

```

## License

MIT

---
_Source: https://npm.io/package/custom-template-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
