@@ -119,23 +119,25 @@ class MyGenerator extends yeoman.Base {
119119 // Exclude test-specific files (unless the user has said they want tests)
120120 const isTestSpecificFile = testSpecificPaths . some ( regex => regex . test ( outputFn ) ) ;
121121 if ( this . _answers . tests || ! isTestSpecificFile ) {
122- const inputFullPath = path . join ( templateRoot , fn ) ;
122+ let inputFullPath = path . join ( templateRoot , fn ) ;
123+ let destinationFullPath = this . destinationPath ( outputFn ) ;
123124 if ( path . basename ( fn ) === 'package.json' ) {
124125 // Special handling for package.json, because we rewrite it dynamically
126+ const tempPath = destinationFullPath + '.tmp' ;
125127 this . fs . writeJSON (
126- this . destinationPath ( outputFn ) ,
128+ tempPath ,
127129 rewritePackageJson ( JSON . parse ( fs . readFileSync ( inputFullPath , 'utf8' ) ) , this . _answers . tests ) ,
128130 /* replacer */ null ,
129131 /* space */ 2
130132 ) ;
131- } else {
132- // Regular file - copy as template
133- this . fs . copyTpl (
134- inputFullPath ,
135- this . destinationPath ( outputFn ) ,
136- this . _answers
137- ) ;
133+ inputFullPath = tempPath ;
138134 }
135+
136+ this . fs . copyTpl (
137+ inputFullPath ,
138+ destinationFullPath ,
139+ this . _answers
140+ ) ;
139141 }
140142 } ) ;
141143 }
@@ -196,7 +198,7 @@ function rewritePackageJson(contents, includeTests) {
196198
197199 // Delete any script called 'test'
198200 const scripts = contents . scripts ;
199- if ( scripts . test ) {
201+ if ( scripts && scripts . test ) {
200202 delete scripts . test ;
201203 if ( Object . getOwnPropertyNames ( scripts ) . length === 0 ) {
202204 delete contents . scripts ;
0 commit comments