Skip to content
This repository has been archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
#37 less strict
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonLi8 committed Jan 20, 2020
1 parent eb99a97 commit 737eb60
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ module.exports = ( () => {
let value;

// Three different types of schema. See REPLACEMENT_STRINGS_SCHEMA for more documentation.
if ( Array.isArray( schema ) ) {
if ( schema && Array.isArray( schema ) ) {
value = UserConfig.parseNestedJSONValue( 'PACKAGE_JSON', schema, replacementString );
}
else if ( Object.getPrototypeOf( schema ) === Object.prototype ) {
else if ( schema && Object.getPrototypeOf( schema ) === Object.prototype ) {
value = schema.parse( UserConfig.parseNestedJSONValue( 'PACKAGE_JSON', schema.path, replacementString ) );
}
else { // schema was null type, but wasn't registered.
Expand Down Expand Up @@ -140,8 +140,12 @@ module.exports = ( () => {
// circular dependency problems.
this.registerRunTimeReplacementValue( 'COPYRIGHT_YEARS', require( './Copyright' ).computeCopyrightYears( outputFilePath ) );

// Get the replacement strings in the template file that are registered in REPLACEMENT_STRINGS_SCHEMA.
const replacementStrings = Util.getInnerDelimeterStrings( template, '{{', '}}' )
.filter( str => str in REPLACEMENT_STRINGS_SCHEMA );

// Replace each replacement string (wrapped with brackets {{}}) in the template file with the replacement value.
Util.getInnerDelimeterStrings( template, '{{', '}}' ).forEach( replacementString => {
replacementStrings.forEach( replacementString => {

// Parse the replacement value and replace all template values.
const replacementValue = Generator.getReplacementValue( replacementString );
Expand Down

0 comments on commit 737eb60

Please sign in to comment.