0.1.2 • Published 6 years ago

custom-template-generator v0.1.2

Weekly downloads
214
License
ISC
Repository
-
Last release
6 years ago

template-generator

npm version

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

BEFORE YOU INSTALL: please read the prerequisites

npm install custom-template-generator

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

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

Usage

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

ScaffoldTypeUsage
componentNamestringName of the component
customTemplatesUrlstringLocation of the custom templates folder
deststringDestination of generated templates files
templateNamestringTemplate name
autoIndentbooleanDefault set to false, will indent the whole file. Only works with js and ts files.
autoIndentExtensionsarrayThe list of extensions file to indent. Default 'js', 'ts'
dataobjectThis custom meta data can be injected in the custom template using '{}'

Meta data

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

NameDescription
nameComponent name
Namecapitalized component name

Demo

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

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

The following template {component}.interface.ts:

// 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

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

Will generate this file

// 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