@@ -119,23 +119,25 @@ class MyGenerator extends yeoman.Base {
119
119
// Exclude test-specific files (unless the user has said they want tests)
120
120
const isTestSpecificFile = testSpecificPaths . some ( regex => regex . test ( outputFn ) ) ;
121
121
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 ) ;
123
124
if ( path . basename ( fn ) === 'package.json' ) {
124
125
// Special handling for package.json, because we rewrite it dynamically
126
+ const tempPath = destinationFullPath + '.tmp' ;
125
127
this . fs . writeJSON (
126
- this . destinationPath ( outputFn ) ,
128
+ tempPath ,
127
129
rewritePackageJson ( JSON . parse ( fs . readFileSync ( inputFullPath , 'utf8' ) ) , this . _answers . tests ) ,
128
130
/* replacer */ null ,
129
131
/* space */ 2
130
132
) ;
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 ;
138
134
}
135
+
136
+ this . fs . copyTpl (
137
+ inputFullPath ,
138
+ destinationFullPath ,
139
+ this . _answers
140
+ ) ;
139
141
}
140
142
} ) ;
141
143
}
@@ -196,7 +198,7 @@ function rewritePackageJson(contents, includeTests) {
196
198
197
199
// Delete any script called 'test'
198
200
const scripts = contents . scripts ;
199
- if ( scripts . test ) {
201
+ if ( scripts && scripts . test ) {
200
202
delete scripts . test ;
201
203
if ( Object . getOwnPropertyNames ( scripts ) . length === 0 ) {
202
204
delete contents . scripts ;
0 commit comments