{"id":14070205,"url":"https://github.com/codeBelt/generate-template-files","last_synced_at":"2025-07-30T07:30:51.297Z","repository":{"id":41322211,"uuid":"160280617","full_name":"codeBelt/generate-template-files","owner":"codeBelt","description":"A simple generator to create custom template files for any application","archived":false,"fork":false,"pushed_at":"2023-05-27T19:44:01.000Z","size":2059,"stargazers_count":213,"open_issues_count":15,"forks_count":31,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-30T00:30:36.906Z","etag":null,"topics":["boilerplate-template","case-converters","generated-code","javascript","scaffold-template","skeleton-template","templates","templating","typescript"],"latest_commit_sha":null,"homepage":"https://medium.com/@robertsavian/generate-template-files-with-ease-19b320615359","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeBelt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-12-04T01:55:10.000Z","updated_at":"2024-11-21T19:15:15.000Z","dependencies_parsed_at":"2024-04-13T02:44:41.679Z","dependency_job_id":"bc6e43b1-3e2e-4e81-a02e-957f9fba4ced","html_url":"https://github.com/codeBelt/generate-template-files","commit_stats":{"total_commits":176,"total_committers":8,"mean_commits":22.0,"dds":"0.38068181818181823","last_synced_commit":"c3e07c19f48d5add020e143506f504d43345db8f"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeBelt%2Fgenerate-template-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeBelt%2Fgenerate-template-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeBelt%2Fgenerate-template-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeBelt%2Fgenerate-template-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeBelt","download_url":"https://codeload.github.com/codeBelt/generate-template-files/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228061819,"owners_count":17863370,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boilerplate-template","case-converters","generated-code","javascript","scaffold-template","skeleton-template","templates","templating","typescript"],"created_at":"2024-08-13T07:07:33.655Z","updated_at":"2024-12-04T11:31:27.072Z","avatar_url":"https://github.com/codeBelt.png","language":"TypeScript","readme":"# `generate-template-files`\n\n[![NPM version][npm-img]][npm-url] [![Downloads][downloads-img]][npm-url]\n\nA simple generator that is independent of any language. Create custom boilerplate, scaffolding, skeleton, and templating code files that you need to create over and over again. All you need is [NodeJS](https://nodejs.org) installed to get started.\n\n\u003e Find this useful? Give it a :star:\n\n![gif image created with licecap](./examples/generate.gif)\n\nMedium Article - [Generate Template Files with Ease](https://medium.com/@robertsavian/generate-template-files-with-ease-19b320615359)\n\n## Install\n\nWith [NPM](http://npmjs.com):\n\n```command\n$ npm install generate-template-files\n```\n\nWith [Yarn](https://yarnpkg.com):\n\n```command\n$ yarn add generate-template-files\n```\n\n## Usage\n\n1. Check out the `examples` folder or create a file called `generate.js`. Note that this file name is flexible.\n2. In that file, add in the example code below.\n3. Run `node generate.js` within Terminal (Mac) or Powershell (Win) once you've added your template files.\n\n```js\nconst { generateTemplateFiles } = require('generate-template-files');\n\nconst config = require('../package.json');\n\ngenerateTemplateFiles([\n  {\n    option: 'Create Redux Store',\n    defaultCase: '(pascalCase)',\n    entry: {\n      folderPath: './tools/templates/react/redux-store/',\n    },\n    stringReplacers: ['__store__', { question: 'Insert model name', slot: '__model__' }],\n    output: {\n      path: './src/stores/__store__(lowerCase)',\n      pathAndFileNameDefaultCase: '(kebabCase)',\n      overwrite: true,\n    },\n  },\n  {\n    option: 'Create Reduce Action',\n    defaultCase: '(pascalCase)',\n    entry: {\n      folderPath: './tools/templates/react/redux-store/__store__Action.ts',\n    },\n    stringReplacers: ['__store__', '__model__'],\n    dynamicReplacers: [\n      { slot: '__version__', slotValue: config.version },\n      { slot: '__description__', slotValue: config.description },\n    ],\n    output: {\n      path: './src/stores/__store__/__store__(lowerCase)/__store__(pascalCase)Action.ts',\n      pathAndFileNameDefaultCase: '(kebabCase)',\n    },\n    onComplete: (results) =\u003e {\n      console.log(`results`, results);\n    },\n  },\n]);\n```\n\nAs outlined in the `examples` folder, I prefer to create a `tools` folder and place `generate.js` w/ `templates` files in there. Additionally, I'll add a script task (`\"generate\": \"node ./tools/generate.js\"`) to my `package.json` file for convienent running of the generator using `npm run generate` or `yarn generate`.\n\n```\n┣━ package.json\n┣━ src\n┗━ tools/\n   ┣━ generate.js\n   ┗━ templates/\n      ┣━ SomeFile.js\n      ┗━ __name__(pascalCase)Action.ts\n```\n\n## API\n\nThe `generateTemplateFiles` function takes an array of `IConfigItem` items.\n\n#### `IConfigItem`\n\n- `option` - The name of the option to choose when asked.\n- `defaultCase` - The default [Case Converters](#case-converters) to use with the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) in the template files. Default is `(noCase)`.\n- `entry.folderPath` - Path to a folder of files or a single template file.\n\n- `stringReplacers` - An array of [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) used to replace content in the designated `entry.folderPath`.\n- `dynamicReplacers` - (Optional) An array of IReplacer used to replace content in the designated `entry.folderPath`.\n- `output.path` - The desired output path for generated files. [Case Converters](#case-converters) and [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) can be used to make the path somewhat dynamic.\n- `output.pathAndFileNameDefaultCase` - The [Case Converters](#case-converters) to use for the file path and file name(s).\n- `output.overwrite` - (Optional) When `true` it will overwrite any files that are named the same.\n- `onComplete` - (Optional) Takes a callback function that is called once the file(s) have been outputted. A [IResults](#iresults) object will be passed to the callback.\n\n###### Example\n\n```javascript\n{\n    option: 'Create Redux Store',\n    defaultCase: '(pascalCase)',\n    entry: {\n        folderPath: './tools/templates/react/redux-store/',\n    },\n    stringReplacers: ['__store__', { question: 'Insert model name', slot: '__model__' }],\n    dynamicReplacers: [\n        {slot:'__version__', slotValue: config.version},\n        {slot:'__description__', slotValue: config.description}\n    ],\n    output: {\n        path: './src/stores/__store__(lowerCase)',\n        pathAndFileNameDefaultCase: '(kebabCase)',\n    },\n    onComplete: (results) =\u003e {\n        console.log(results);\n    },\n},\n```\n\n#### `IResults`\n\nBelow is an example of what you receive from the `onComplete` callback. It has the output path, list of files created and the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) with the value entered.\n\n- `output.path` - The file(s) output path\n- `output.files` - List of files created\n- `stringReplacers` - List of [Replacer Slots](#replacer-slots-or-ireplacerslotquestion); name and values entered during the setup process\n\n###### Example data you would get from the onComplete callback\n\n```javascript\n{\n    output: {\n        path: './src/stores/some-thing',\n        files: [\n            './src/stores/some-thing/SomeThingModule.ts',\n            './src/stores/some-thing/SomeThingModuleAction.ts',\n            './src/stores/some-thing/SomeThingModuleGetter.ts',\n            './src/stores/some-thing/SomeThingModuleMutation.ts',\n            './src/stores/some-thing/SomeThingService.ts',\n            './src/stores/some-thing/models/actions/ISomeThingState.ts',\n            './src/stores/some-thing/models/actions/OtherThingResponseModel.ts'\n        ]\n    },\n    stringReplacers: [\n        {\n            slot: '__store__',\n            slotValue: 'some thing'\n        },\n        {\n            slot: '__model__',\n            slotValue: 'other thing'\n        }\n    ]\n}\n```\n\n### Replacer Slots or IReplacerSlotQuestion\n\n[Replacer Slots](#replacer-slots-or-ireplacerslotquestion) are unique string value(s) to be replaced by the generator. An array of string values and/or `IReplacerSlotQuestion` objects can be used.\n\n```javascript\nstringReplacers: ['__store__', { question: 'Insert model name', slot: '__model__' }];\n```\n\nReplacer slot can be any string value you want to use. You can use something like this in your template files and/or in the file path names.\n\n- `~replacerSlot~`\n- `{{something else}}`\n- `__AnythingYouWant__`\n\n#### `IReplacerSlotQuestion`\n\nBelow is an example of a `IReplacerSlotQuestion`\n\n```javascript\n{question: 'Insert model name', slot: '__model__'}\n```\n\n- `question` - The question to ask the use what value should be used for the replacer `slot`\n- `slot` - The string value for the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion)\n\n#### Dynamic Replacer Slots\n\nIf you have data that is dynamically generated, or you have hard coded values you can use the `dynamicReplacers`:\n\n```javascript\ndynamicReplacers: [\n  {slot:'__description__', slotValue: config.description}\n],\n```\n\n### Case Converters\n\n[Case Converters](#case-converters) transform the string value entered upon use of the generator.\n\nExample\n\n- In the generator template `__replacerSlot__` is appended by the `(pascalCase)` converter such as `__replacerSlot__(pascalCase)`.\n- When the generator is ran, the string `\"product reducer\"` is provided for `__replacerSlot__`.\n- As a result, the converter will produce `ProductReducer`.\n\nHere is the string `Lives down BY the River` with each of the converters:\n\n```js\n// If you typed in 'Lives down BY the River' for the a Replacer Slot named '__replacerSlot__' and\n// used one of the optional Case Converters you would get the following:\n\n__replacerSlot__(noCase)       // Lives down BY the River\n__replacerSlot__(camelCase)    // livesDownByTheRiver\n__replacerSlot__(constantCase) // LIVES_DOWN_BY_THE_RIVER\n__replacerSlot__(dotCase)      // lives.down.by.the.river\n__replacerSlot__(kebabCase)    // lives-down-by-the-river\n__replacerSlot__(lowerCase)    // livesdownbytheriver\n__replacerSlot__(pascalCase)   // LivesDownByTheRiver\n__replacerSlot__(pathCase)     // lives/down/by/the/river\n__replacerSlot__(sentenceCase) // Lives down by the river\n__replacerSlot__(snakeCase)    // lives_down_by_the_river\n__replacerSlot__(titleCase)    // Lives Down By The River\n\n// Note: you can set a 'defaultCase' converter in IConfigItem so all\n// Replacer Slots without a Case Converter will be transformed the same way.\n__replacerSlot__; //                LivesDownByTheRiver\n```\n\nYou may also specify the case using an underscores-only syntax e.g. `PascalCase__`:\n\n```js\n__replacerSlot__NoCase__       // Lives down BY the River\n__replacerSlot__CamelCase__    // livesDownByTheRiver\n__replacerSlot__ConstantCase__ // LIVES_DOWN_BY_THE_RIVER\n__replacerSlot__DotCase__      // lives.down.by.the.river\n__replacerSlot__KebabCase__    // lives-down-by-the-river\n__replacerSlot__LowerCase__    // livesdownbytheriver\n__replacerSlot__PascalCase__   // LivesDownByTheRiver\n__replacerSlot__PathCase__     // lives/down/by/the/river\n__replacerSlot__SentenceCase__ // Lives down by the river\n__replacerSlot__SnakeCase__    // lives_down_by_the_river\n__replacerSlot__TitleCase__    // Lives Down By The River\n```\nTake your [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) `__replacerSlot__`, the [Case Converters](#case-converters) `PascalCase__` and combine them together to make `__replacerSlot__PascalCase__`.\n\nOne Rule: no spaces between the [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) and [Case Converters](#case-converters). If there is a space, [Case Converters](#case-converters) will not work.\n\n- :white_check_mark: `__name__(camelCase)` OR `__name__CamelCase__`\n- :x: `__name__ (camelCase)` OR `__name__ CamelCase__`\n\n## Batch Usage\n\nYou can use `generate-template-files` to generate your template files programmatically, without any interactive prompts. This mode does not support `stringReplacers`.\n\nThe following example will generate the component, unit tests, and the SCSS module in one do.\n\n```js\n// generateTemplateFile.js\nconst { generateTemplateFilesBatch } = require('generate-template-files');\n\nconst componentWithInterface = (componentName, componentScope = 'common') =\u003e {\n  generateTemplateFilesBatch([\n    {\n      option: 'Component',\n      defaultCase: '(pascalCase)',\n      entry: {\n        folderPath: './tools/templates/react/component',\n      },\n      dynamicReplacers: [\n        { slot: '__name__', slotValue: componentName },\n        { slot: '__scope__', slotValue: componentScope },\n      ],\n      output: {\n        path: `./src/component/__scope__(camelCase)`,\n        pathAndFileNameDefaultCase: '(pascalCase)',\n      },\n    },\n    {\n      option: 'Component Interface',\n      defaultCase: '(pascalCase)',\n      entry: {\n        folderPath: './tools/templates/react/I__interface__.ts',\n      },\n      dynamicReplacers: [\n        { slot: '__interface__', slotValue: componentName },\n        { slot: '__scope__', slotValue: componentScope },\n      ],\n      output: {\n        path: `./src/component/__scope__(camelCase)/I__interface__.ts`,\n        pathAndFileNameDefaultCase: '(pascalCase)',\n      },\n    },\n  ]).catch(() =\u003e {\n    console.log('Build Error');\n  });\n};\n```\n\n## Command Line Usage\n\nYou can use `generate-template-files` with the command line to generate your template files.\n\n```js\n// generate.js\nconst { generateTemplateFilesCommandLine } = require('generate-template-files');\n\ngenerateTemplateFilesCommandLine([\n  {\n    option: 'Create Reduce Action',\n    defaultCase: '(pascalCase)',\n    entry: {\n      folderPath: './tools/templates/react/redux-store/__store__Action.ts',\n    },\n    stringReplacers: ['__store__', '__model__'],\n    dynamicReplacers: [\n      { slot: '__version__', slotValue: config.version },\n      { slot: '__description__', slotValue: config.description },\n    ],\n    output: {\n      path: './src/stores/__store__/__store__(lowerCase)/__store__(pascalCase)Action.ts',\n      pathAndFileNameDefaultCase: '(kebabCase)',\n    },\n  },\n]);\n```\n\n###### Minimum Options\n\n```txt\nnode ./tools/generate.js create-reduce-action __store__=some-name __model__=some-other-name\n```\n\n###### All Options\n\n```txt\nnode ./tools/generate.js create-reduce-action __store__=some-name __model__=some-other-name --outputpath=./src/here --overwrite\n```\n\n**Command LIne Script Overview**\n\n- `node ./tools/generate.js` - Runs the `generate-template-files` library\n- `create-reduce-action` - The template name; It uses the same option name in the [IConfigItem](#iconfigitem) but converts all options names to kebab-case. For example `option: 'Create Reduce Action'` will be converted to `create-reduce-action` when using the command line\n- `__store__=some-name` - Are [Replacer Slots](#replacer-slots-or-ireplacerslotquestion) and will be converted to `{ slot: \"__store__\", slotValue: \"some-name\" }`\n- `--outputpath=./src/here` - Will override the `output.path` in the [IConfigItem](#iconfigitem)\n- `--overwrite` - Will overwrite files if the files already exists\n\n[npm-url]: https://npmjs.org/package/generate-template-files\n[downloads-img]: http://img.shields.io/npm/dm/generate-template-files.svg?style=flat-square\n[npm-img]: http://img.shields.io/npm/v/generate-template-files.svg?style=flat-square\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcodeBelt%2Fgenerate-template-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FcodeBelt%2Fgenerate-template-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcodeBelt%2Fgenerate-template-files/lists"}