Gathering detailed insights and metrics for generate-template-files
Gathering detailed insights and metrics for generate-template-files
Gathering detailed insights and metrics for generate-template-files
Gathering detailed insights and metrics for generate-template-files
npm install generate-template-files
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
213 Stars
215 Commits
31 Forks
9 Watching
7 Branches
6 Contributors
Updated on 21 Nov 2024
TypeScript (96.95%)
JavaScript (3.05%)
Cumulative downloads
Total Downloads
Last day
1.6%
5,243
Compared to previous day
Last week
-6.4%
27,062
Compared to previous week
Last month
-13.7%
113,983
Compared to previous month
Last year
16.7%
1,577,990
Compared to previous year
27
generate-template-files
A 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 installed to get started.
Find this useful? Give it a :star:
Medium Article - Generate Template Files with Ease
With NPM:
1$ npm install generate-template-files
With Yarn:
1$ yarn add generate-template-files
examples
folder or create a file called generate.js
. Note that this file name is flexible.node generate.js
within Terminal (Mac) or Powershell (Win) once you've added your template files.1const { generateTemplateFiles } = require('generate-template-files'); 2 3const config = require('../package.json'); 4 5generateTemplateFiles([ 6 { 7 option: 'Create Redux Store', 8 defaultCase: '(pascalCase)', 9 entry: { 10 folderPath: './tools/templates/react/redux-store/', 11 }, 12 stringReplacers: ['__store__', { question: 'Insert model name', slot: '__model__' }], 13 output: { 14 path: './src/stores/__store__(lowerCase)', 15 pathAndFileNameDefaultCase: '(kebabCase)', 16 overwrite: true, 17 }, 18 }, 19 { 20 option: 'Create Reduce Action', 21 defaultCase: '(pascalCase)', 22 entry: { 23 folderPath: './tools/templates/react/redux-store/__store__Action.ts', 24 }, 25 stringReplacers: ['__store__', '__model__'], 26 dynamicReplacers: [ 27 { slot: '__version__', slotValue: config.version }, 28 { slot: '__description__', slotValue: config.description }, 29 ], 30 output: { 31 path: './src/stores/__store__/__store__(lowerCase)/__store__(pascalCase)Action.ts', 32 pathAndFileNameDefaultCase: '(kebabCase)', 33 }, 34 onComplete: (results) => { 35 console.log(`results`, results); 36 }, 37 }, 38]);
As 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
.
┣━ package.json
┣━ src
┗━ tools/
┣━ generate.js
┗━ templates/
┣━ SomeFile.js
┗━ __name__(pascalCase)Action.ts
The generateTemplateFiles
function takes an array of IConfigItem
items.
IConfigItem
option
- The name of the option to choose when asked.
defaultCase
- The default Case Converters to use with the Replacer Slots in the 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 the designated entry.folderPath
.
dynamicReplacers
- (Optional) An array of IReplacer used to replace content in the designated entry.folderPath
.
output.path
- The desired output path for generated files. Case Converters and Replacer Slots can be used to make the path somewhat dynamic.
output.pathAndFileNameDefaultCase
- The Case Converters to use for the file path and file name(s).
output.overwrite
- (Optional) When true
it will overwrite any files that are named the same.
onComplete
- (Optional) Takes a callback function that is called once the file(s) have been outputted. A IResults object will be passed to the callback.
1{ 2 option: 'Create Redux Store', 3 defaultCase: '(pascalCase)', 4 entry: { 5 folderPath: './tools/templates/react/redux-store/', 6 }, 7 stringReplacers: ['__store__', { question: 'Insert model name', slot: '__model__' }], 8 dynamicReplacers: [ 9 {slot:'__version__', slotValue: config.version}, 10 {slot:'__description__', slotValue: config.description} 11 ], 12 output: { 13 path: './src/stores/__store__(lowerCase)', 14 pathAndFileNameDefaultCase: '(kebabCase)', 15 }, 16 onComplete: (results) => { 17 console.log(results); 18 }, 19},
IResults
Below is an example of what you receive from the onComplete
callback. It has the output path, list of files created and the Replacer Slots with the value entered.
output.path
- The file(s) output pathoutput.files
- List of files createdstringReplacers
- List of Replacer Slots; name and values entered during the setup process1{ 2 output: { 3 path: './src/stores/some-thing', 4 files: [ 5 './src/stores/some-thing/SomeThingModule.ts', 6 './src/stores/some-thing/SomeThingModuleAction.ts', 7 './src/stores/some-thing/SomeThingModuleGetter.ts', 8 './src/stores/some-thing/SomeThingModuleMutation.ts', 9 './src/stores/some-thing/SomeThingService.ts', 10 './src/stores/some-thing/models/actions/ISomeThingState.ts', 11 './src/stores/some-thing/models/actions/OtherThingResponseModel.ts' 12 ] 13 }, 14 stringReplacers: [ 15 { 16 slot: '__store__', 17 slotValue: 'some thing' 18 }, 19 { 20 slot: '__model__', 21 slotValue: 'other thing' 22 } 23 ] 24}
Replacer Slots are unique string value(s) to be replaced by the generator. An array of string values and/or IReplacerSlotQuestion
objects can be used.
1stringReplacers: ['__store__', { question: 'Insert model name', slot: '__model__' }];
Replacer 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.
~replacerSlot~
{{something else}}
__AnythingYouWant__
IReplacerSlotQuestion
Below is an example of a IReplacerSlotQuestion
1{question: 'Insert model name', slot: '__model__'}
question
- The question to ask the use what value should be used for the replacer slot
slot
- The string value for the Replacer SlotsIf you have data that is dynamically generated, or you have hard coded values you can use the dynamicReplacers
:
1dynamicReplacers: [ 2 {slot:'__description__', slotValue: config.description} 3],
Case Converters transform the string value entered upon use of the generator.
Example
__replacerSlot__
is appended by the (pascalCase)
converter such as __replacerSlot__(pascalCase)
."product reducer"
is provided for __replacerSlot__
.ProductReducer
.Here is the string Lives down BY the River
with each of the converters:
1// If you typed in 'Lives down BY the River' for the a Replacer Slot named '__replacerSlot__' and
2// used one of the optional Case Converters you would get the following:
3
4__replacerSlot__(noCase) // Lives down BY the River
5__replacerSlot__(camelCase) // livesDownByTheRiver
6__replacerSlot__(constantCase) // LIVES_DOWN_BY_THE_RIVER
7__replacerSlot__(dotCase) // lives.down.by.the.river
8__replacerSlot__(kebabCase) // lives-down-by-the-river
9__replacerSlot__(lowerCase) // livesdownbytheriver
10__replacerSlot__(pascalCase) // LivesDownByTheRiver
11__replacerSlot__(pathCase) // lives/down/by/the/river
12__replacerSlot__(sentenceCase) // Lives down by the river
13__replacerSlot__(snakeCase) // lives_down_by_the_river
14__replacerSlot__(titleCase) // Lives Down By The River
15
16// Note: you can set a 'defaultCase' converter in IConfigItem so all
17// Replacer Slots without a Case Converter will be transformed the same way.
18__replacerSlot__; // LivesDownByTheRiver
You may also specify the case using an underscores-only syntax e.g. PascalCase__
:
1__replacerSlot__NoCase__ // Lives down BY the River 2__replacerSlot__CamelCase__ // livesDownByTheRiver 3__replacerSlot__ConstantCase__ // LIVES_DOWN_BY_THE_RIVER 4__replacerSlot__DotCase__ // lives.down.by.the.river 5__replacerSlot__KebabCase__ // lives-down-by-the-river 6__replacerSlot__LowerCase__ // livesdownbytheriver 7__replacerSlot__PascalCase__ // LivesDownByTheRiver 8__replacerSlot__PathCase__ // lives/down/by/the/river 9__replacerSlot__SentenceCase__ // Lives down by the river 10__replacerSlot__SnakeCase__ // lives_down_by_the_river 11__replacerSlot__TitleCase__ // Lives Down By The River
Take your Replacer Slots __replacerSlot__
, the Case Converters PascalCase__
and combine them together to make __replacerSlot__PascalCase__
.
One Rule: no spaces between the Replacer Slots and Case Converters. If there is a space, Case Converters will not work.
__name__(camelCase)
OR __name__CamelCase__
__name__ (camelCase)
OR __name__ CamelCase__
You can use generate-template-files
to generate your template files programmatically, without any interactive prompts. This mode does not support stringReplacers
.
The following example will generate the component, unit tests, and the SCSS module in one do.
1// generateTemplateFile.js 2const { generateTemplateFilesBatch } = require('generate-template-files'); 3 4const componentWithInterface = (componentName, componentScope = 'common') => { 5 generateTemplateFilesBatch([ 6 { 7 option: 'Component', 8 defaultCase: '(pascalCase)', 9 entry: { 10 folderPath: './tools/templates/react/component', 11 }, 12 dynamicReplacers: [ 13 { slot: '__name__', slotValue: componentName }, 14 { slot: '__scope__', slotValue: componentScope }, 15 ], 16 output: { 17 path: `./src/component/__scope__(camelCase)`, 18 pathAndFileNameDefaultCase: '(pascalCase)', 19 }, 20 }, 21 { 22 option: 'Component Interface', 23 defaultCase: '(pascalCase)', 24 entry: { 25 folderPath: './tools/templates/react/I__interface__.ts', 26 }, 27 dynamicReplacers: [ 28 { slot: '__interface__', slotValue: componentName }, 29 { slot: '__scope__', slotValue: componentScope }, 30 ], 31 output: { 32 path: `./src/component/__scope__(camelCase)/I__interface__.ts`, 33 pathAndFileNameDefaultCase: '(pascalCase)', 34 }, 35 }, 36 ]).catch(() => { 37 console.log('Build Error'); 38 }); 39};
You can use generate-template-files
with the command line to generate your template files.
1// generate.js 2const { generateTemplateFilesCommandLine } = require('generate-template-files'); 3 4generateTemplateFilesCommandLine([ 5 { 6 option: 'Create Reduce Action', 7 defaultCase: '(pascalCase)', 8 entry: { 9 folderPath: './tools/templates/react/redux-store/__store__Action.ts', 10 }, 11 stringReplacers: ['__store__', '__model__'], 12 dynamicReplacers: [ 13 { slot: '__version__', slotValue: config.version }, 14 { slot: '__description__', slotValue: config.description }, 15 ], 16 output: { 17 path: './src/stores/__store__/__store__(lowerCase)/__store__(pascalCase)Action.ts', 18 pathAndFileNameDefaultCase: '(kebabCase)', 19 }, 20 }, 21]);
1node ./tools/generate.js create-reduce-action __store__=some-name __model__=some-other-name
1node ./tools/generate.js create-reduce-action __store__=some-name __model__=some-other-name --outputpath=./src/here --overwrite
Command LIne Script Overview
node ./tools/generate.js
- Runs the generate-template-files
librarycreate-reduce-action
- The template name; It uses the same option name in the 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__store__=some-name
- Are Replacer Slots and will be converted to { slot: "__store__", slotValue: "some-name" }
--outputpath=./src/here
- Will override the output.path
in the IConfigItem--overwrite
- Will overwrite files if the files already existsNo vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/17 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
23 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More