@@ -40,7 +40,6 @@ interface TemplateConfig {
4040 rootDir : string ; // Which of the template root directories should be used
4141 name : string ; // Display name
4242 tests : boolean ;
43- mapFilenames ?: { [ pattern : string ] : string | boolean } ;
4443}
4544
4645const templates : TemplateConfig [ ] = [
@@ -52,20 +51,6 @@ const templates: TemplateConfig[] = [
5251 { value : 'vue' , rootDir : 'vue' , name : 'Vue' , tests : false }
5352] ;
5453
55- // Once everyone is on .csproj-compatible tooling, we might be able to remove the global.json files and eliminate
56- // this SDK choice altogether. That would be good because then it would work with whatever SDK version you have
57- // installed. For now, we need to specify an SDK version explicitly, because there's no support for wildcards, and
58- // preview3+ tooling doesn't support project.json at all.
59- const sdkChoices = [ {
60- value : '1.0.0-preview2-1-003177' , // Current released version
61- name : 'project.json' + chalk . gray ( ' (compatible with .NET Core tooling preview 2 and Visual Studio 2015)' ) ,
62- includeFiles : [ / ^ p r o j e c t .j s o n $ / , / \. x p r o j $ / , / _ p l a c e h o l d e r .t x t $ / , / \. d e p l o y m e n t $ / ]
63- } , {
64- value : '1.0.0-preview3-004056' , // Version that ships with VS2017RC
65- name : '.csproj' + chalk . gray ( ' (compatible with .NET Core tooling preview 3 and Visual Studio 2017)' ) ,
66- includeFiles : [ / \. c s p r o j $ / ]
67- } ] ;
68-
6954class MyGenerator extends yeoman . Base {
7055 private _answers : any ;
7156 private _optionOrPrompt : YeomanPrompt ;
@@ -89,11 +74,6 @@ class MyGenerator extends yeoman.Base {
8974 name : 'framework' ,
9075 message : 'Framework' ,
9176 choices : templates
92- } , {
93- type : 'list' ,
94- name : 'sdkVersion' ,
95- message : 'What type of project do you want to create?' ,
96- choices : sdkChoices
9777 } ] , firstAnswers => {
9878 const templateConfig = templates . filter ( t => t . value === firstAnswers . framework ) [ 0 ] ;
9979 const furtherQuestions = [ {
@@ -117,12 +97,9 @@ class MyGenerator extends yeoman.Base {
11797 this . _answers = answers ;
11898 this . _answers . framework = firstAnswers . framework ;
11999 this . _answers . templateConfig = templateConfig ;
120- this . _answers . sdkVersion = firstAnswers . sdkVersion ;
121100 this . _answers . namePascalCase = toPascalCase ( answers . name ) ;
122101 this . _answers . projectGuid = this . options [ 'projectguid' ] || uuid . v4 ( ) ;
123102
124- const chosenSdk = sdkChoices . filter ( sdk => sdk . value === this . _answers . sdkVersion ) [ 0 ] ;
125-
126103 done ( ) ;
127104 } ) ;
128105 } ) ;
@@ -131,7 +108,6 @@ class MyGenerator extends yeoman.Base {
131108 writing ( ) {
132109 const templateConfig = this . _answers . templateConfig as TemplateConfig ;
133110 const templateRoot = this . templatePath ( templateConfig . rootDir ) ;
134- const chosenSdk = sdkChoices . filter ( sdk => sdk . value === this . _answers . sdkVersion ) [ 0 ] ;
135111 glob . sync ( '**/*' , { cwd : templateRoot , dot : true , nodir : true } ) . forEach ( fn => {
136112 // Token replacement in filenames
137113 let outputFn = fn . replace ( / t o k e n r e p l a c e \- ( [ ^ \. \/ ] * ) / g, ( substr , token ) => this . _answers [ token ] ) ;
@@ -141,22 +117,9 @@ class MyGenerator extends yeoman.Base {
141117 outputFn = path . join ( path . dirname ( fn ) , '.gitignore' ) ;
142118 }
143119
144- // Perform any filename replacements configured for the template
145- const mappedFilename = applyFirstMatchingReplacement ( outputFn , templateConfig . mapFilenames ) ;
146- let fileIsExcludedByTemplateConfig = false ;
147- if ( typeof mappedFilename === 'string' ) {
148- outputFn = mappedFilename ;
149- } else {
150- fileIsExcludedByTemplateConfig = ( mappedFilename === false ) ;
151- }
152-
153120 // Decide whether to emit this file
154121 const isTestSpecificFile = testSpecificPaths . some ( regex => regex . test ( outputFn ) ) ;
155- const isSdkSpecificFile = sdkChoices . some ( sdk => sdk . includeFiles . some ( regex => regex . test ( outputFn ) ) ) ;
156- const matchesChosenSdk = chosenSdk . includeFiles . some ( regex => regex . test ( outputFn ) ) ;
157- const emitFile = ( matchesChosenSdk || ! isSdkSpecificFile )
158- && ( this . _answers . tests || ! isTestSpecificFile )
159- && ! fileIsExcludedByTemplateConfig ;
122+ const emitFile = ( this . _answers . tests || ! isTestSpecificFile ) ;
160123
161124 if ( emitFile ) {
162125 let inputFullPath = path . join ( templateRoot , fn ) ;
@@ -265,28 +228,5 @@ function rewritePackageJson(contents, includeTests) {
265228 return contents ;
266229}
267230
268- function applyFirstMatchingReplacement ( inputValue : string , replacements : { [ pattern : string ] : string | boolean } ) : string | boolean {
269- if ( replacements ) {
270- const replacementPatterns = Object . getOwnPropertyNames ( replacements ) ;
271- for ( let patternIndex = 0 ; patternIndex < replacementPatterns . length ; patternIndex ++ ) {
272- const pattern = replacementPatterns [ patternIndex ] ;
273- const regexp = new RegExp ( pattern ) ;
274- if ( regexp . test ( inputValue ) ) {
275- const replacement = replacements [ pattern ] ;
276-
277- // To avoid bug-prone evaluation order dependencies, we only respond to the first name match per file
278- if ( typeof ( replacement ) === 'boolean' ) {
279- return replacement ;
280- } else {
281- return inputValue . replace ( regexp , replacement ) ;
282- }
283- }
284- }
285- }
286-
287- // No match
288- return inputValue ;
289- }
290-
291231declare var module : any ;
292232( module ) . exports = MyGenerator ;
0 commit comments