@@ -4,6 +4,7 @@ import * as yeoman from 'yeoman-generator';
4
4
import * as uuid from 'node-uuid' ;
5
5
import * as glob from 'glob' ;
6
6
import * as semver from 'semver' ;
7
+ import * as chalk from 'chalk' ;
7
8
import { execSync } from 'child_process' ;
8
9
import npmWhich = require( 'npm-which' ) ;
9
10
const yosay = require ( 'yosay' ) ;
@@ -42,6 +43,20 @@ const templates = [
42
43
{ value : 'react-redux' , name : 'React with Redux' , tests : false }
43
44
] ;
44
45
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
+
45
60
class MyGenerator extends yeoman . Base {
46
61
private _answers : any ;
47
62
private _optionOrPrompt : YeomanPrompt ;
@@ -65,8 +80,13 @@ class MyGenerator extends yeoman.Base {
65
80
name : 'framework' ,
66
81
message : 'Framework' ,
67
82
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 ] ;
70
90
const furtherQuestions = [ {
71
91
type : 'input' ,
72
92
name : 'name' ,
@@ -84,9 +104,10 @@ class MyGenerator extends yeoman.Base {
84
104
}
85
105
86
106
this . _optionOrPrompt ( furtherQuestions , answers => {
87
- answers . framework = frameworkAnswer . framework ;
107
+ answers . framework = firstAnswers . framework ;
88
108
this . _answers = answers ;
89
- this . _answers . framework = frameworkAnswer . framework ;
109
+ this . _answers . framework = firstAnswers . framework ;
110
+ this . _answers . sdkVersion = firstAnswers . sdkVersion ;
90
111
this . _answers . namePascalCase = toPascalCase ( answers . name ) ;
91
112
this . _answers . projectGuid = this . options [ 'projectguid' ] || uuid . v4 ( ) ;
92
113
done ( ) ;
@@ -95,7 +116,8 @@ class MyGenerator extends yeoman.Base {
95
116
}
96
117
97
118
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 ] ;
99
121
glob . sync ( '**/*' , { cwd : templateRoot , dot : true , nodir : true } ) . forEach ( fn => {
100
122
// Token replacement in filenames
101
123
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 {
105
127
outputFn = path . join ( path . dirname ( fn ) , '.gitignore' ) ;
106
128
}
107
129
108
- // Exclude test-specific files (unless the user has said they want tests)
130
+ // Decide whether to emit this file
109
131
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 ) {
111
138
let inputFullPath = path . join ( templateRoot , fn ) ;
112
139
let destinationFullPath = this . destinationPath ( outputFn ) ;
113
140
if ( path . basename ( fn ) === 'package.json' ) {
0 commit comments