Coder Social home page Coder Social logo

steveafrost / generate-template-files Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codebelt/generate-template-files

0.0 1.0 0.0 104 KB

A generator to create custom template files for your applications

License: MIT License

JavaScript 8.37% TypeScript 91.63%

generate-template-files's Introduction

generate-template-files

NPM version Downloads

A generator to create custom template files for all your boilerplate, scaffolding, skeleton, templating code that you need to create over and over again.

Found this usefull? give it a ⭐

Install

With NPM:

$ npm install generate-template-files

With Yarn:

$ yarn add generate-template-files

Usage

Check out the examples folder or create a file called generate.js. The file can be named anything you want. In that file add in the example code below. Then you can do node generate.js once you added your template files.

const generateTemplateFiles = require('generate-template-files');

generateTemplateFiles([
    {
        option: 'Create Redux Store',
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/ngrx/',
        },
        stringReplacers: ['~Component~', '~Model~'],
        output: {
            path: './src/app/stores/~Component~(lowerCase)',
            pathAndFileNameDefaultCase: '(kebabCase)',
        },
    },
    {
        option: 'Create Ngrx Action',
        defaultCase: '(pascalCase)',
        entry: {
            folderPath: './tools/templates/ngrx/~Component~.action.ts',
        },
        stringReplacers: ['~Component~', '~Model~'],
        output: {
            path: './src/app/stores/~Component~(lowerCase)/~Component~(pascalCase)Action.ts',
            pathAndFileNameDefaultCase: '(kebabCase)',
        },
    },
]);

Checkout the examples folder but I usually create a tools folder and place my generate.js and templates files in there. I also add a script task ("generate": "node ./tools/generate.js") to my package.json file.

┣━ package.json
┣━ src
┗━ tools/
   ┣━ generate.js
   ┗━ templates/
      ┣━ SomeFile.js
      ┗━ ~Component~(pascalCase)Action.ts

API

The generateTemplateFiles method takes an array of IConfigItem items.

IConfigItem

  • option - The name of the option to choose when asked.
  • defaultCase - The default Case Converters you want to use with the Replacer Slots in your template files. Default is (noCase).
  • entry.folderPath - Path to a folder of files or a single template file.
  • stringReplacers - An array of Replacer Slots used to replace content in your files and file paths.
  • output.path - The desired out put path for your generated files. You can use Case Converters and Replacer Slots to make the path somewhat dynamic.
  • output.pathAndFileNameDefaultCase - The Case Converters you want to use for the file path and file name(s).

Replacer Slots

Replacer Slots are unique string value(s) that you want other string data to replace.

For example you can use something like this in your template files and/or in the file path names.

  • ~replacerSlot~
  • {{something else}}
  • __AnythingYouWant__

Case Converters

Case Converters allows you to transform the entered in string value.

For example if you enter in "product reducer" for ~replacerSlot~ and in your template you had ~replacerSlot~(pascalCase). You will get ProductReducer.

Lets say you entered in Lives down BY the River with one of the converters:

(noCase)        // Lives down BY the River
(camelCase)     // livesDownByTheRiver
(constantCase)  // LIVES_DOWN_BY_THE_RIVER
(dotCase)       // lives.down.by.the.river
(kebabCase)     // lives-down-by-the-river
(lowerCase)     // livesdownbytheriver
(pascalCase)    // LivesDownByTheRiver
(pathCase)      // lives/down/by/the/river
(sentenceCase)  // Lives down by the river
(snakeCase)     // lives_down_by_the_river
(titleCase)     // Lives Down By The River

One Rule - No spaces between the Replacer Slots and the Case Converters.

generate-template-files's People

Contributors

codebelt avatar

Watchers

James Cloos avatar

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.