Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds support for generating SubTemplates.
The primary goal of subTemplates is to support lists of identical items within a template. Like a list of fields, args, or props. Multiple subTemplates can be defined for the same variable so the user can enter the variables once and have them applied in different ways throughout their templates. This results in a lists of lists output.
Use Cases:
propsvariable with two subTemplates: one to place them in a PropTypes definition, and one to place them in a destructured list in the render function. The user will only need to type out a list of props likefirstName, image, addressStras a variable and they can get :I added a new folder called
examplesthat has an example of this working in it.Technical Implementation Notes:
Variables have a new property:
subTemplates.variables with subTemplates are parsed as lists IE -
firstName, image, addressStrWhen generated the subTemplate config will be applied against every entry in the list:
firstName,image,addressStrSubTemplates are an array and each subTemplate has
file, as, variableAlias, joinChars;file- The name of the file located in thesubTemplatesfolder. IE -propTypeField.jsas- The name of the variable this specific subTemplate will be installed at. IE -propTypeFieldDefsvariableAlias- The variable name in the subTemplate file that will be replaced with the value from the list. IE -propNamejoinChars- The characters to use to join the results of all iterations. IE -\r\nor,VariableTable has a second list called _aliases that takes each subTemplate
asproperty and aliases it to the variable. This list is used to lookup variable names that should be processed as subTemplates.When generating files we take two passes now: First to process subTemplates and second to process non-subTemplates. This lets us use any other variable name inside our subTemplates.