@@ -4,6 +4,7 @@ import * as yeoman from 'yeoman-generator';
44import * as uuid from 'node-uuid' ;
55import * as glob from 'glob' ;
66import * as semver from 'semver' ;
7+ import * as chalk from 'chalk' ;
78import { execSync } from 'child_process' ;
89import npmWhich = require( 'npm-which' ) ;
910const yosay = require ( 'yosay' ) ;
@@ -42,6 +43,20 @@ const templates = [
4243 { value : 'react-redux' , name : 'React with Redux' , tests : false }
4344] ;
4445
46+ // Once everyone is on .csproj-compatible tooling, we might be able to remove the global.json files and eliminate
47+ // this SDK choice altogether. That would be good because then it would work with whatever SDK version you have
48+ // installed. For now, we need to specify an SDK version explicitly, because there's no support for wildcards, and
49+ // preview3+ tooling doesn't support project.json at all.
50+ const sdkChoices = [ {
51+ value : '1.0.0-preview2-1-003177' , // Current released version
52+ name : 'project.json' + chalk . gray ( ' (compatible with .NET Core tooling preview 2 and Visual Studio 2015)' ) ,
53+ includeFiles : [ / ^ p r o j e c t .j s o n $ / , / \. x p r o j $ / ]
54+ } , {
55+ value : '1.0.0-preview3-004056' , // Version that ships with VS2017RC
56+ name : '.csproj' + chalk . gray ( ' (compatible with .NET Core tooling preview 3 and Visual Studio 2017)' ) ,
57+ includeFiles : [ / \. c s p r o j $ / ]
58+ } ] ;
59+
4560class MyGenerator extends yeoman . Base {
4661 private _answers : any ;
4762 private _optionOrPrompt : YeomanPrompt ;
@@ -65,8 +80,13 @@ class MyGenerator extends yeoman.Base {
6580 name : 'framework' ,
6681 message : 'Framework' ,
6782 choices : templates
68- } ] , frameworkAnswer => {
69- const frameworkChoice = templates . filter ( t => t . value === frameworkAnswer . framework ) [ 0 ] ;
83+ } , {
84+ type : 'list' ,
85+ name : 'sdkVersion' ,
86+ message : 'What type of project do you want to create?' ,
87+ choices : sdkChoices
88+ } ] , firstAnswers => {
89+ const frameworkChoice = templates . filter ( t => t . value === firstAnswers . framework ) [ 0 ] ;
7090 const furtherQuestions = [ {
7191 type : 'input' ,
7292 name : 'name' ,
@@ -84,9 +104,10 @@ class MyGenerator extends yeoman.Base {
84104 }
85105
86106 this . _optionOrPrompt ( furtherQuestions , answers => {
87- answers . framework = frameworkAnswer . framework ;
107+ answers . framework = firstAnswers . framework ;
88108 this . _answers = answers ;
89- this . _answers . framework = frameworkAnswer . framework ;
109+ this . _answers . framework = firstAnswers . framework ;
110+ this . _answers . sdkVersion = firstAnswers . sdkVersion ;
90111 this . _answers . namePascalCase = toPascalCase ( answers . name ) ;
91112 this . _answers . projectGuid = this . options [ 'projectguid' ] || uuid . v4 ( ) ;
92113 done ( ) ;
@@ -95,7 +116,8 @@ class MyGenerator extends yeoman.Base {
95116 }
96117
97118 writing ( ) {
98- var templateRoot = this . templatePath ( this . _answers . framework ) ;
119+ const templateRoot = this . templatePath ( this . _answers . framework ) ;
120+ const chosenSdk = sdkChoices . filter ( sdk => sdk . value === this . _answers . sdkVersion ) [ 0 ] ;
99121 glob . sync ( '**/*' , { cwd : templateRoot , dot : true , nodir : true } ) . forEach ( fn => {
100122 // Token replacement in filenames
101123 let outputFn = fn . replace ( / t o k e n r e p l a c e \- ( [ ^ \. \/ ] * ) / g, ( substr , token ) => this . _answers [ token ] ) ;
@@ -105,9 +127,14 @@ class MyGenerator extends yeoman.Base {
105127 outputFn = path . join ( path . dirname ( fn ) , '.gitignore' ) ;
106128 }
107129
108- // Exclude test-specific files (unless the user has said they want tests)
130+ // Decide whether to emit this file
109131 const isTestSpecificFile = testSpecificPaths . some ( regex => regex . test ( outputFn ) ) ;
110- if ( this . _answers . tests || ! isTestSpecificFile ) {
132+ const isSdkSpecificFile = sdkChoices . some ( sdk => sdk . includeFiles . some ( regex => regex . test ( outputFn ) ) ) ;
133+ const matchesChosenSdk = chosenSdk . includeFiles . some ( regex => regex . test ( outputFn ) ) ;
134+ const emitFile = ( matchesChosenSdk || ! isSdkSpecificFile )
135+ && ( this . _answers . tests || ! isTestSpecificFile ) ;
136+
137+ if ( emitFile ) {
111138 let inputFullPath = path . join ( templateRoot , fn ) ;
112139 let destinationFullPath = this . destinationPath ( outputFn ) ;
113140 if ( path . basename ( fn ) === 'package.json' ) {
0 commit comments