@@ -11,8 +11,17 @@ const isWindows = /^win/.test(process.platform);
1111const textFileExtensions = [ '.gitignore' , 'template_gitignore' , '.config' , '.cs' , '.cshtml' , 'Dockerfile' , '.html' , '.js' , '.json' , '.jsx' , '.md' , '.nuspec' , '.ts' , '.tsx' , '.xproj' ] ;
1212const yeomanGeneratorSource = './src/yeoman' ;
1313
14- const templates : { [ key : string ] : { dir : string , dotNetNewId : string , displayName : string , forceInclusion ?: RegExp } } = {
15- 'angular-2' : { dir : '../../templates/Angular2Spa/' , dotNetNewId : 'Angular' , displayName : 'Angular 2' , forceInclusion : / ^ ( w w w r o o t | C l i e n t A p p ) \/ d i s t \/ / } ,
14+ // For the Angular 2 template, we want to bundle prebuilt dist dev-mode files, because the VS template can't auto-run
15+ // webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
16+ // scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
17+ const runWebpackInDevModeScripts = [
18+ 'npm install' ,
19+ 'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js' ,
20+ 'node node_modules/webpack/bin/webpack.js'
21+ ] ;
22+
23+ const templates : { [ key : string ] : { dir : string , dotNetNewId : string , displayName : string , prepublish ?: string [ ] , forceInclusion ?: RegExp } } = {
24+ 'angular-2' : { dir : '../../templates/Angular2Spa/' , dotNetNewId : 'Angular' , displayName : 'Angular 2' , prepublish : runWebpackInDevModeScripts , forceInclusion : / ^ ( w w w r o o t | C l i e n t A p p ) \/ d i s t \/ / } ,
1625 'aurelia' : { dir : '../../templates/AureliaSpa/' , dotNetNewId : 'Aurelia' , displayName : 'Aurelia' } ,
1726 'knockout' : { dir : '../../templates/KnockoutSpa/' , dotNetNewId : 'Knockout' , displayName : 'Knockout.js' } ,
1827 'react-redux' : { dir : '../../templates/ReactReduxSpa/' , dotNetNewId : 'ReactRedux' , displayName : 'React.js and Redux' } ,
@@ -161,21 +170,25 @@ function buildDotNetNewNuGetPackage() {
161170 rimraf . sync ( './tmp' ) ;
162171}
163172
164- // TODO: Instead of just showing this warning, improve build script so it actually does build them
165- // in the correct format. Can do this once we've moved away from using ASPNETCORE_ENVIRONMENT to
166- // control the build output mode. The templates we warn about here are the ones where we ship some
167- // files that wouldn't normally be under source control (e.g., /wwwroot/dist/*).
168- const templatesWithForceIncludes = Object . getOwnPropertyNames ( templates )
169- . filter ( templateName => ! ! templates [ templateName ] . forceInclusion ) ;
170- if ( templatesWithForceIncludes . length > 0 ) {
171- console . warn ( `
172- ---
173- WARNING: Ensure that the following templates are already built in the configuration desired for publishing.
174- For example, build the dist files in debug mode.
175- TEMPLATES: ${ templatesWithForceIncludes . join ( ', ' ) }
176- ---
177- ` ) ;
173+ function runAllPrepublishScripts ( ) {
174+ Object . getOwnPropertyNames ( templates ) . forEach ( templateKey => {
175+ const templateInfo = templates [ templateKey ] ;
176+ if ( templateInfo . prepublish ) {
177+ runScripts ( templateInfo . dir , templateInfo . prepublish ) ;
178+ }
179+ } ) ;
180+ }
181+
182+ function runScripts ( rootDir : string , scripts : string [ ] ) {
183+ console . log ( `[Prepublish] In directory: ${ rootDir } ` ) ;
184+ scripts . forEach ( script => {
185+ console . log ( `[Prepublish] Running: ${ script } ` ) ;
186+ childProcess . execSync ( script , { cwd : rootDir , stdio : 'inherit' } ) ;
187+ } ) ;
188+ console . log ( `[Prepublish] Done` )
178189}
179190
191+ rimraf . sync ( './dist' ) ;
192+ runAllPrepublishScripts ( ) ;
180193buildYeomanNpmPackage ( ) ;
181194buildDotNetNewNuGetPackage ( ) ;
0 commit comments