@@ -5,16 +5,13 @@ import { isInteractive } from "../common/helpers";
5
5
export class CreateProjectCommand implements ICommand {
6
6
public enableHooks = false ;
7
7
public allowedParameters : ICommandParameter [ ] = [ this . $stringParameter ] ;
8
- private static NgFlavor = "Angular" ;
9
- private static VueFlavor = "Vue.js" ;
10
- private static TsFlavor = "Plain TypeScript" ;
11
- private static JsFlavor = "Plain JavaScript" ;
12
8
private static HelloWorldTemplateKey = "Hello World" ;
13
9
private static HelloWorldTemplateDescription = "A Hello World app" ;
14
10
private static DrawerTemplateKey = "SideDrawer" ;
15
11
private static DrawerTemplateDescription = "An app with pre-built pages that uses a drawer for navigation" ;
16
12
private static TabsTemplateKey = "Tabs" ;
17
13
private static TabsTemplateDescription = "An app with pre-built pages that uses tabs for navigation" ;
14
+ private isInteractionIntroShown = false ;
18
15
19
16
private createdProjectData : ICreateProjectData ;
20
17
@@ -49,18 +46,16 @@ export class CreateProjectCommand implements ICommand {
49
46
selectedTemplate = this . $options . template ;
50
47
}
51
48
52
- if ( ( ! selectedTemplate || ! projectName ) && isInteractive ( ) ) {
53
- this . printInteractiveCreationIntro ( ) ;
54
- }
55
-
56
49
if ( ! projectName && isInteractive ( ) ) {
50
+ this . printInteractiveCreationIntroIfNeeded ( ) ;
57
51
projectName = await this . $prompter . getString ( `${ getNextInteractiveAdverb ( ) } , what will be the name of your app?` , { allowEmpty : false } ) ;
58
52
this . $logger . info ( ) ;
59
53
}
60
54
61
55
projectName = await this . $projectService . validateProjectName ( { projectName : projectName , force : this . $options . force , pathToProject : this . $options . path } ) ;
62
56
63
57
if ( ! selectedTemplate && isInteractive ( ) ) {
58
+ this . printInteractiveCreationIntroIfNeeded ( ) ;
64
59
selectedTemplate = await this . interactiveFlavorAndTemplateSelection ( getNextInteractiveAdverb ( ) , getNextInteractiveAdverb ( ) ) ;
65
60
}
66
61
@@ -84,22 +79,25 @@ export class CreateProjectCommand implements ICommand {
84
79
85
80
private async interactiveFlavorSelection ( adverb : string ) {
86
81
const flavorSelection = await this . $prompter . promptForDetailedChoice ( `${ adverb } , which flavor would you like to use?` , [
87
- { key : CreateProjectCommand . NgFlavor , description : "Learn more at https://angular.io/" } ,
88
- { key : CreateProjectCommand . VueFlavor , description : "Learn more at https://vuejs.org/" } ,
89
- { key : CreateProjectCommand . TsFlavor , description : "Learn more at https://www.typescriptlang.org/" } ,
90
- { key : CreateProjectCommand . JsFlavor , description : "Learn more at https://www.javascript.com/" } ,
82
+ { key : constants . NgFlavorName , description : "Learn more at https://angular.io/" } ,
83
+ { key : constants . VueFlavorName , description : "Learn more at https://vuejs.org/" } ,
84
+ { key : constants . TsFlavorName , description : "Learn more at https://www.typescriptlang.org/" } ,
85
+ { key : constants . JsFlavorName , description : "Learn more at https://www.javascript.com/" } ,
91
86
] ) ;
92
87
return flavorSelection ;
93
88
}
94
89
95
- private printInteractiveCreationIntro ( ) {
96
- this . $logger . info ( ) ;
97
- this . $logger . printMarkdown ( `# Let’s create a NativeScript app!` ) ;
98
- this . $logger . printMarkdown ( `
90
+ private printInteractiveCreationIntroIfNeeded ( ) {
91
+ if ( ! this . isInteractionIntroShown ) {
92
+ this . isInteractionIntroShown = true ;
93
+ this . $logger . info ( ) ;
94
+ this . $logger . printMarkdown ( `# Let’s create a NativeScript app!` ) ;
95
+ this . $logger . printMarkdown ( `
99
96
Answer the following questions to help us build the right app for you. (Note: you
100
97
can skip this prompt next time using the --template option, or the --ng, --vue, --ts,
101
98
or --js flags.)
102
99
` ) ;
100
+ }
103
101
}
104
102
105
103
private async interactiveTemplateSelection ( flavorSelection : string , adverb : string ) {
@@ -110,19 +108,19 @@ or --js flags.)
110
108
} [ ] = [ ] ;
111
109
let selectedTemplate : string ;
112
110
switch ( flavorSelection ) {
113
- case CreateProjectCommand . NgFlavor : {
111
+ case constants . NgFlavorName : {
114
112
selectedFlavorTemplates . push ( ...this . getNgFlavors ( ) ) ;
115
113
break ;
116
114
}
117
- case CreateProjectCommand . VueFlavor : {
115
+ case constants . VueFlavorName : {
118
116
selectedFlavorTemplates . push ( { value : "https://github.com/NativeScript/template-blank-vue/tarball/0.9.0" } ) ;
119
117
break ;
120
118
}
121
- case CreateProjectCommand . TsFlavor : {
119
+ case constants . TsFlavorName : {
122
120
selectedFlavorTemplates . push ( ...this . getTsTemplates ( ) ) ;
123
121
break ;
124
122
}
125
- case CreateProjectCommand . JsFlavor : {
123
+ case constants . JsFlavorName : {
126
124
selectedFlavorTemplates . push ( ...this . getJsTemplates ( ) ) ;
127
125
break ;
128
126
}
@@ -141,74 +139,61 @@ or --js flags.)
141
139
}
142
140
143
141
private getJsTemplates ( ) {
144
- const templates : {
145
- key ?: string ;
146
- value : string ;
147
- description ?: string ;
148
- } [ ] = [ ] ;
149
- templates . push ( {
142
+ const templates = [ {
150
143
key : CreateProjectCommand . HelloWorldTemplateKey ,
151
- value : "tns-template-hello-world" ,
144
+ value : constants . RESERVED_TEMPLATE_NAMES . javascript ,
152
145
description : CreateProjectCommand . HelloWorldTemplateDescription
153
- } ) ;
154
- templates . push ( {
146
+ } ,
147
+ {
155
148
key : CreateProjectCommand . DrawerTemplateKey ,
156
149
value : "tns-template-drawer-navigation" ,
157
150
description : CreateProjectCommand . DrawerTemplateDescription
158
- } ) ;
159
- templates . push ( {
151
+ } ,
152
+ {
160
153
key : CreateProjectCommand . TabsTemplateKey ,
161
154
value : "tns-template-tab-navigation" ,
162
155
description : CreateProjectCommand . TabsTemplateDescription
163
- } ) ;
156
+ } ] ;
157
+
164
158
return templates ;
165
159
}
166
160
167
161
private getTsTemplates ( ) {
168
- const templates : {
169
- key ?: string ;
170
- value : string ;
171
- description ?: string ;
172
- } [ ] = [ ] ;
173
- templates . push ( {
162
+ const templates = [ {
174
163
key : CreateProjectCommand . HelloWorldTemplateKey ,
175
- value : "tns-template-hello-world-ts" ,
164
+ value : constants . RESERVED_TEMPLATE_NAMES . typescript ,
176
165
description : CreateProjectCommand . HelloWorldTemplateDescription
177
- } ) ;
178
- templates . push ( {
166
+ } ,
167
+ {
179
168
key : CreateProjectCommand . DrawerTemplateKey ,
180
169
value : "tns-template-drawer-navigation-ts" ,
181
170
description : CreateProjectCommand . DrawerTemplateDescription
182
- } ) ;
183
- templates . push ( {
171
+ } ,
172
+ {
184
173
key : CreateProjectCommand . TabsTemplateKey ,
185
174
value : "tns-template-tab-navigation-ts" ,
186
175
description : CreateProjectCommand . TabsTemplateDescription
187
- } ) ;
176
+ } ] ;
177
+
188
178
return templates ;
189
179
}
190
180
191
181
private getNgFlavors ( ) {
192
- const templates : {
193
- key ?: string ;
194
- value : string ;
195
- description ?: string ;
196
- } [ ] = [ ] ;
197
- templates . push ( {
182
+ const templates = [ {
198
183
key : CreateProjectCommand . HelloWorldTemplateKey ,
199
- value : "tns-template-hello-world-ng" ,
184
+ value : constants . RESERVED_TEMPLATE_NAMES . angular ,
200
185
description : CreateProjectCommand . HelloWorldTemplateDescription
201
- } ) ;
202
- templates . push ( {
186
+ } ,
187
+ {
203
188
key : CreateProjectCommand . DrawerTemplateKey ,
204
189
value : "tns-template-drawer-navigation-ng" ,
205
190
description : CreateProjectCommand . DrawerTemplateDescription
206
- } ) ;
207
- templates . push ( {
191
+ } ,
192
+ {
208
193
key : CreateProjectCommand . TabsTemplateKey ,
209
194
value : "tns-template-tab-navigation-ng" ,
210
195
description : CreateProjectCommand . TabsTemplateDescription
211
- } ) ;
196
+ } ] ;
212
197
213
198
return templates ;
214
199
}
0 commit comments