Produce correct package.json from generator-aspnetcore-spa

This commit is contained in:
SteveSandersonMS
2016-11-10 08:16:30 -08:00
parent 828ed07cef
commit 4f15bd6c50

View File

@@ -119,24 +119,26 @@ class MyGenerator extends yeoman.Base {
// Exclude test-specific files (unless the user has said they want tests) // Exclude test-specific files (unless the user has said they want tests)
const isTestSpecificFile = testSpecificPaths.some(regex => regex.test(outputFn)); const isTestSpecificFile = testSpecificPaths.some(regex => regex.test(outputFn));
if (this._answers.tests || !isTestSpecificFile) { if (this._answers.tests || !isTestSpecificFile) {
const inputFullPath = path.join(templateRoot, fn); let inputFullPath = path.join(templateRoot, fn);
let destinationFullPath = this.destinationPath(outputFn);
if (path.basename(fn) === 'package.json') { if (path.basename(fn) === 'package.json') {
// Special handling for package.json, because we rewrite it dynamically // Special handling for package.json, because we rewrite it dynamically
const tempPath = destinationFullPath + '.tmp';
this.fs.writeJSON( this.fs.writeJSON(
this.destinationPath(outputFn), tempPath,
rewritePackageJson(JSON.parse(fs.readFileSync(inputFullPath, 'utf8')), this._answers.tests), rewritePackageJson(JSON.parse(fs.readFileSync(inputFullPath, 'utf8')), this._answers.tests),
/* replacer */ null, /* replacer */ null,
/* space */ 2 /* space */ 2
); );
} else { inputFullPath = tempPath;
// Regular file - copy as template }
this.fs.copyTpl( this.fs.copyTpl(
inputFullPath, inputFullPath,
this.destinationPath(outputFn), destinationFullPath,
this._answers this._answers
); );
} }
}
}); });
} }
@@ -196,7 +198,7 @@ function rewritePackageJson(contents, includeTests) {
// Delete any script called 'test' // Delete any script called 'test'
const scripts = contents.scripts; const scripts = contents.scripts;
if (scripts.test) { if (scripts && scripts.test) {
delete scripts.test; delete scripts.test;
if (Object.getOwnPropertyNames(scripts).length === 0) { if (Object.getOwnPropertyNames(scripts).length === 0) {
delete contents.scripts; delete contents.scripts;