Skip to content

Commit b731435

Browse files
When building "dotnet new" templates, always prebuild and include client-side 'dist' files for all templates, because dotnet new can't run arbitrary post-generation steps
1 parent 1bf2838 commit b731435

File tree

1 file changed

+13
-6
lines changed
  • templates/package-builder/src/build

1 file changed

+13
-6
lines changed

templates/package-builder/src/build/build.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ const isWindows = /^win/.test(process.platform);
1212
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', 'Dockerfile', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx', '.xproj'];
1313
const yeomanGeneratorSource = './src/yeoman';
1414

15-
// For the Angular 2 template, we want to bundle prebuilt dist dev-mode files, because the VS template can't auto-run
15+
// To support the "dotnet new" templates, we want to bundle prebuilt dist dev-mode files, because "dotnet new" can't auto-run
1616
// webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
1717
// scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
18-
const runWebpackInDevModeScripts = [
18+
const commonTemplatePrepublishSteps = [
1919
'npm install',
2020
'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js',
2121
'node node_modules/webpack/bin/webpack.js'
2222
];
23+
const commonForceInclusionRegex = /^(wwwroot|ClientApp)\/dist\//; // Files to be included in template, even though gitignored
2324

2425
const templates: { [key: string]: { dir: string, dotNetNewId: string, displayName: string, prepublish?: string[], forceInclusion?: RegExp } } = {
25-
'angular': { dir: '../../templates/Angular2Spa/', dotNetNewId: 'Angular', displayName: 'Angular', prepublish: runWebpackInDevModeScripts, forceInclusion: /^(wwwroot|ClientApp)\/dist\// },
26+
'angular': { dir: '../../templates/Angular2Spa/', dotNetNewId: 'Angular', displayName: 'Angular' },
2627
'aurelia': { dir: '../../templates/AureliaSpa/', dotNetNewId: 'Aurelia', displayName: 'Aurelia' },
2728
'knockout': { dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js' },
2829
'react-redux': { dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux' },
2930
'react': { dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.js' }
3031
};
3132

33+
3234
function isTextFile(filename: string): boolean {
3335
return textFileExtensions.indexOf(path.extname(filename).toLowerCase()) >= 0
3436
|| textFileExtensions.indexOf(path.basename(filename)) >= 0;
@@ -108,7 +110,7 @@ function buildYeomanNpmPackage(outputRoot: string) {
108110
];
109111
_.forEach(templates, (templateConfig, templateName) => {
110112
const outputDir = path.join(outputTemplatesRoot, templateName);
111-
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements, templateConfig.forceInclusion);
113+
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
112114
});
113115

114116
// Also copy the generator files (that's the compiled .js files, plus all other non-.ts files)
@@ -134,7 +136,7 @@ function buildDotNetNewNuGetPackage() {
134136
const contentReplacements = [];
135137
_.forEach(templates, (templateConfig, templateName) => {
136138
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
137-
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements, templateConfig.forceInclusion);
139+
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
138140

139141
// Add the .template.config dir and its contents
140142
const templateConfigDir = path.join(templateOutputDir, '.template.config');
@@ -152,7 +154,7 @@ function buildDotNetNewNuGetPackage() {
152154
sources: [{
153155
source: './',
154156
target: './',
155-
exclude: ['.deployment', '.template.config/**', 'project.json', '*.xproj']
157+
exclude: ['.deployment', '.template.config/**', 'project.json', '*.xproj', '**/_placeholder.txt']
156158
}],
157159
symbols: {
158160
sdkVersion: {
@@ -196,6 +198,11 @@ function buildDotNetNewNuGetPackage() {
196198
function runAllPrepublishScripts() {
197199
Object.getOwnPropertyNames(templates).forEach(templateKey => {
198200
const templateInfo = templates[templateKey];
201+
202+
// First run standard prepublish steps
203+
runScripts(templateInfo.dir, commonTemplatePrepublishSteps);
204+
205+
// Second, run any template-specific prepublish steps
199206
if (templateInfo.prepublish) {
200207
runScripts(templateInfo.dir, templateInfo.prepublish);
201208
}

0 commit comments

Comments
 (0)