mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Produce correct package.json from generator-aspnetcore-spa
This commit is contained in:
@@ -119,23 +119,25 @@ 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(
|
|
||||||
inputFullPath,
|
|
||||||
this.destinationPath(outputFn),
|
|
||||||
this._answers
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.fs.copyTpl(
|
||||||
|
inputFullPath,
|
||||||
|
destinationFullPath,
|
||||||
|
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user