@@ -12,25 +12,28 @@ const isWindows = /^win/.test(process.platform);
1212const textFileExtensions = [ '.gitignore' , 'template_gitignore' , '.config' , '.cs' , '.cshtml' , '.csproj' , '.html' , '.js' , '.json' , '.jsx' , '.md' , '.nuspec' , '.ts' , '.tsx' ] ;
1313const yeomanGeneratorSource = './src/yeoman' ;
1414
15- // To support the "dotnet new" templates, we want to bundle prebuilt dist dev-mode files, because "dotnet new" can't auto-run
16- // webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
17- // scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
18- const commonTemplatePrepublishSteps = [
19- 'npm install' ,
20- 'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js' ,
21- 'node node_modules/webpack/bin/webpack.js'
22- ] ;
15+ const dotNetPackages = {
16+ builtIn : 'Microsoft.DotNet.Web.Spa.ProjectTemplates' ,
17+ extra : 'Microsoft.AspNetCore.SpaTemplates'
18+ } ;
19+
2320const commonForceInclusionRegex = / ^ ( w w w r o o t | C l i e n t A p p ) \/ d i s t \/ / ; // Files to be included in template, even though gitignored
2421
25- const templates : { [ key : string ] : { dir : string , dotNetNewId : string , displayName : string , prepublish ?: string [ ] , forceInclusion ?: RegExp } } = {
26- 'angular' : { dir : '../../templates/AngularSpa/' , dotNetNewId : 'Angular' , displayName : 'Angular' } ,
27- 'aurelia' : { dir : '../../templates/AureliaSpa/' , dotNetNewId : 'Aurelia' , displayName : 'Aurelia' } ,
28- 'knockout' : { dir : '../../templates/KnockoutSpa/' , dotNetNewId : 'Knockout' , displayName : 'Knockout.js' } ,
29- 'react-redux' : { dir : '../../templates/ReactReduxSpa/' , dotNetNewId : 'ReactRedux' , displayName : 'React.js and Redux' } ,
30- 'react' : { dir : '../../templates/ReactSpa/' , dotNetNewId : 'React' , displayName : 'React.js' } ,
31- 'vue' : { dir : '../../templates/VueSpa/' , dotNetNewId : 'Vue' , displayName : 'Vue.js' }
32- } ;
22+ interface TemplateConfig {
23+ dir : string ;
24+ dotNetNewId : string ;
25+ dotNetPackageId : string ;
26+ displayName : string ;
27+ }
3328
29+ const templates : { [ key : string ] : TemplateConfig } = {
30+ 'angular' : { dotNetPackageId : dotNetPackages . builtIn , dir : '../../templates/AngularSpa/' , dotNetNewId : 'Angular' , displayName : 'Angular' } ,
31+ 'aurelia' : { dotNetPackageId : dotNetPackages . extra , dir : '../../templates/AureliaSpa/' , dotNetNewId : 'Aurelia' , displayName : 'Aurelia' } ,
32+ 'knockout' : { dotNetPackageId : dotNetPackages . extra , dir : '../../templates/KnockoutSpa/' , dotNetNewId : 'Knockout' , displayName : 'Knockout.js' } ,
33+ 'react-redux' : { dotNetPackageId : dotNetPackages . builtIn , dir : '../../templates/ReactReduxSpa/' , dotNetNewId : 'ReactRedux' , displayName : 'React.js and Redux' } ,
34+ 'react' : { dotNetPackageId : dotNetPackages . builtIn , dir : '../../templates/ReactSpa/' , dotNetNewId : 'React' , displayName : 'React.js' } ,
35+ 'vue' : { dotNetPackageId : dotNetPackages . extra , dir : '../../templates/VueSpa/' , dotNetNewId : 'Vue' , displayName : 'Vue.js' }
36+ } ;
3437
3538function isTextFile ( filename : string ) : boolean {
3639 return textFileExtensions . indexOf ( path . extname ( filename ) . toLowerCase ( ) ) >= 0
@@ -111,7 +114,17 @@ function buildYeomanNpmPackage(outputRoot: string) {
111114 rimraf . sync ( tempRoot ) ;
112115}
113116
114- function buildDotNetNewNuGetPackage ( ) {
117+ function buildDotNetNewNuGetPackages ( outputDir : string ) {
118+ const dotNetPackageIds = _ . values ( dotNetPackages ) ;
119+ dotNetPackageIds . forEach ( packageId => {
120+ const dotNetNewNupkgPath = buildDotNetNewNuGetPackage ( packageId ) ;
121+
122+ // Move the .nupkg file to the output dir
123+ fs . renameSync ( dotNetNewNupkgPath , path . join ( outputDir , path . basename ( dotNetNewNupkgPath ) ) ) ;
124+ } ) ;
125+ }
126+
127+ function buildDotNetNewNuGetPackage ( packageId : string ) {
115128 const outputRoot = './dist/dotnetnew' ;
116129 rimraf . sync ( outputRoot ) ;
117130
@@ -124,6 +137,11 @@ function buildDotNetNewNuGetPackage() {
124137 ] ;
125138 const contentReplacements = [ ] ;
126139 _ . forEach ( templates , ( templateConfig , templateName ) => {
140+ // Only include templates matching the output package ID
141+ if ( templateConfig . dotNetPackageId !== packageId ) {
142+ return ;
143+ }
144+
127145 const templateOutputDir = path . join ( outputRoot , 'Content' , templateName ) ;
128146 writeTemplate ( templateConfig . dir , templateOutputDir , contentReplacements , filenameReplacements , commonForceInclusionRegex ) ;
129147
@@ -134,8 +152,8 @@ function buildDotNetNewNuGetPackage() {
134152 fs . writeFileSync ( path . join ( templateConfigDir , 'template.json' ) , JSON . stringify ( {
135153 author : 'Microsoft' ,
136154 classifications : [ 'Web' , 'MVC' , 'SPA' ] ,
137- groupIdentity : `Microsoft.AspNetCore.SpaTemplates .${ templateConfig . dotNetNewId } ` ,
138- identity : `Microsoft.AspNetCore.SpaTemplates .${ templateConfig . dotNetNewId } .CSharp` ,
155+ groupIdentity : `${ packageId } .${ templateConfig . dotNetNewId } ` ,
156+ identity : `${ packageId } .${ templateConfig . dotNetNewId } .CSharp` ,
139157 name : `MVC ASP.NET Core with ${ templateConfig . displayName } ` ,
140158 preferNameDirectory : true ,
141159 primaryOutputs : [ { path : `${ sourceProjectName } .csproj` } ] ,
@@ -213,8 +231,11 @@ function buildDotNetNewNuGetPackage() {
213231 // Invoke NuGet to create the final package
214232 const yeomanPackageVersion = JSON . parse ( fs . readFileSync ( path . join ( yeomanGeneratorSource , 'package.json' ) , 'utf8' ) ) . version ;
215233 writeTemplate ( './src/dotnetnew' , outputRoot , [
234+ { from : / \{ p a c k a g e I d \} / g, to : packageId } ,
216235 { from : / \{ v e r s i o n \} / g, to : yeomanPackageVersion } ,
217- ] , [ ] , null ) ;
236+ ] , [
237+ { from : / .* \. n u s p e c $ / , to : `${ packageId } .nuspec` } ,
238+ ] , null ) ;
218239 const nugetExe = path . join ( process . cwd ( ) , './bin/NuGet.exe' ) ;
219240 const nugetStartInfo = { cwd : outputRoot , stdio : 'inherit' } ;
220241 if ( isWindows ) {
@@ -233,19 +254,18 @@ function buildDotNetNewNuGetPackage() {
233254
234255function runAllPrepublishScripts ( ) {
235256 Object . getOwnPropertyNames ( templates ) . forEach ( templateKey => {
236- const templateInfo = templates [ templateKey ] ;
237-
238- // First run standard prepublish steps
239- runScripts ( templateInfo . dir , commonTemplatePrepublishSteps ) ;
240-
241- // Second, run any template-specific prepublish steps
242- if ( templateInfo . prepublish ) {
243- runScripts ( templateInfo . dir , templateInfo . prepublish ) ;
244- }
257+ // To support the "dotnet new" templates, we want to bundle prebuilt dist dev-mode files, because "dotnet new" can't auto-run
258+ // webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
259+ // scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
260+ runPrepublishScripts ( templates [ templateKey ] . dir , [
261+ 'npm install' ,
262+ 'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js' ,
263+ 'node node_modules/webpack/bin/webpack.js'
264+ ] ) ;
245265 } ) ;
246266}
247267
248- function runScripts ( rootDir : string , scripts : string [ ] ) {
268+ function runPrepublishScripts ( rootDir : string , scripts : string [ ] ) {
249269 console . log ( `[Prepublish] In directory: ${ rootDir } ` ) ;
250270 scripts . forEach ( script => {
251271 console . log ( `[Prepublish] Running: ${ script } ` ) ;
@@ -262,10 +282,7 @@ rimraf.sync(distDir);
262282mkdirp . sync ( artifactsDir ) ;
263283runAllPrepublishScripts ( ) ;
264284buildYeomanNpmPackage ( yeomanOutputRoot ) ;
265- const dotNetNewNupkgPath = buildDotNetNewNuGetPackage ( ) ;
266-
267- // Move the .nupkg file to the artifacts dir
268- fs . renameSync ( dotNetNewNupkgPath , path . join ( artifactsDir , path . basename ( dotNetNewNupkgPath ) ) ) ;
285+ buildDotNetNewNuGetPackages ( artifactsDir ) ;
269286
270287// Finally, create a .tar.gz file containing the built generator-aspnetcore-spa.
271288// The CI system can treat this as the final built artifact.
0 commit comments