Giter Site home page Giter Site logo

custom-template-generator's Introduction

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

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:

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

custom-template-generator's People

Contributors

m2omou avatar neo97online avatar

Stargazers

Serhan Coşkun avatar Robert S. avatar yuuma avatar Nicholas Zacca avatar  avatar Nan avatar  avatar

Watchers

James Cloos avatar  avatar Vadym Tomilenko avatar

custom-template-generator's Issues

generator function doesn't return promise

I want to do some action immediately after the file generation. Currently, there is no option to check if the file generation is successful. I am using timeout as a workaround but that's not a good solution. See the below example, I am getting the console before the file generation.

`generator({
componentName: 'nidhi',
customTemplatesUrl: './templates/',
dest: 'cypress',
templateName: 'component',
autoIndent: true,
data: {
uiconfig: JSON.stringify({
test: 42,
lolo: {
pop: 42,
storme: 2,
},
}),
},
})

console.log("print it after the generation complete")
`

Creation of files not working on Windows

This is currently broken in Windows... When I try generating, I get this error:

{ Error: ENOENT: no such file or directory, open 'C:\code\forge\src\testing\C:\code\forge\templates\component\testing.module.ts'
    at Error (native)
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\code\\forge\\src\\testing\\C:\\code\\forge\\templates\\component\\testing.module.ts' }

It looks like it's appending the root directory of my hard-drive twice. I will make a PR to fix this.

Cannot create deep named paths

Using a deeply named path, like templates/component/{component}-list/{component}-list.ts does not work. I'm getting this error:

{ Error: ENOENT: no such file or directory, open 'C:\code\forge\src\testing\testing-list\{component}-list.component.ts'
    at Error (native)
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\code\\forge\\src\\testing\\testing-list\\{component}-list.component.ts' }

I'll make a pull request for this issue as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.