@@ -11,8 +11,17 @@ const isWindows = /^win/.test(process.platform);
11
11
const textFileExtensions = [ '.gitignore' , 'template_gitignore' , '.config' , '.cs' , '.cshtml' , 'Dockerfile' , '.html' , '.js' , '.json' , '.jsx' , '.md' , '.nuspec' , '.ts' , '.tsx' , '.xproj' ] ;
12
12
const yeomanGeneratorSource = './src/yeoman' ;
13
13
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 \/ / } ,
16
25
'aurelia' : { dir : '../../templates/AureliaSpa/' , dotNetNewId : 'Aurelia' , displayName : 'Aurelia' } ,
17
26
'knockout' : { dir : '../../templates/KnockoutSpa/' , dotNetNewId : 'Knockout' , displayName : 'Knockout.js' } ,
18
27
'react-redux' : { dir : '../../templates/ReactReduxSpa/' , dotNetNewId : 'ReactRedux' , displayName : 'React.js and Redux' } ,
@@ -161,21 +170,25 @@ function buildDotNetNewNuGetPackage() {
161
170
rimraf . sync ( './tmp' ) ;
162
171
}
163
172
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` )
178
189
}
179
190
191
+ rimraf . sync ( './dist' ) ;
192
+ runAllPrepublishScripts ( ) ;
180
193
buildYeomanNpmPackage ( ) ;
181
194
buildDotNetNewNuGetPackage ( ) ;
0 commit comments