@@ -5,16 +5,13 @@ import { isInteractive } from "../common/helpers";
55export class CreateProjectCommand implements ICommand {
66 public enableHooks = false ;
77 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" ;
128 private static HelloWorldTemplateKey = "Hello World" ;
139 private static HelloWorldTemplateDescription = "A Hello World app" ;
1410 private static DrawerTemplateKey = "SideDrawer" ;
1511 private static DrawerTemplateDescription = "An app with pre-built pages that uses a drawer for navigation" ;
1612 private static TabsTemplateKey = "Tabs" ;
1713 private static TabsTemplateDescription = "An app with pre-built pages that uses tabs for navigation" ;
14+ private isInteractionIntroShown = false ;
1815
1916 private createdProjectData : ICreateProjectData ;
2017
@@ -49,18 +46,16 @@ export class CreateProjectCommand implements ICommand {
4946 selectedTemplate = this . $options . template ;
5047 }
5148
52- if ( ( ! selectedTemplate || ! projectName ) && isInteractive ( ) ) {
53- this . printInteractiveCreationIntro ( ) ;
54- }
55-
5649 if ( ! projectName && isInteractive ( ) ) {
50+ this . printInteractiveCreationIntroIfNeeded ( ) ;
5751 projectName = await this . $prompter . getString ( `${ getNextInteractiveAdverb ( ) } , what will be the name of your app?` , { allowEmpty : false } ) ;
5852 this . $logger . info ( ) ;
5953 }
6054
6155 projectName = await this . $projectService . validateProjectName ( { projectName : projectName , force : this . $options . force , pathToProject : this . $options . path } ) ;
6256
6357 if ( ! selectedTemplate && isInteractive ( ) ) {
58+ this . printInteractiveCreationIntroIfNeeded ( ) ;
6459 selectedTemplate = await this . interactiveFlavorAndTemplateSelection ( getNextInteractiveAdverb ( ) , getNextInteractiveAdverb ( ) ) ;
6560 }
6661
@@ -84,22 +79,25 @@ export class CreateProjectCommand implements ICommand {
8479
8580 private async interactiveFlavorSelection ( adverb : string ) {
8681 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/" } ,
9186 ] ) ;
9287 return flavorSelection ;
9388 }
9489
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 ( `
9996Answer the following questions to help us build the right app for you. (Note: you
10097can skip this prompt next time using the --template option, or the --ng, --vue, --ts,
10198or --js flags.)
10299` ) ;
100+ }
103101 }
104102
105103 private async interactiveTemplateSelection ( flavorSelection : string , adverb : string ) {
@@ -110,19 +108,19 @@ or --js flags.)
110108 } [ ] = [ ] ;
111109 let selectedTemplate : string ;
112110 switch ( flavorSelection ) {
113- case CreateProjectCommand . NgFlavor : {
111+ case constants . NgFlavorName : {
114112 selectedFlavorTemplates . push ( ...this . getNgFlavors ( ) ) ;
115113 break ;
116114 }
117- case CreateProjectCommand . VueFlavor : {
115+ case constants . VueFlavorName : {
118116 selectedFlavorTemplates . push ( { value : "https://github.com/NativeScript/template-blank-vue/tarball/0.9.0" } ) ;
119117 break ;
120118 }
121- case CreateProjectCommand . TsFlavor : {
119+ case constants . TsFlavorName : {
122120 selectedFlavorTemplates . push ( ...this . getTsTemplates ( ) ) ;
123121 break ;
124122 }
125- case CreateProjectCommand . JsFlavor : {
123+ case constants . JsFlavorName : {
126124 selectedFlavorTemplates . push ( ...this . getJsTemplates ( ) ) ;
127125 break ;
128126 }
@@ -141,74 +139,61 @@ or --js flags.)
141139 }
142140
143141 private getJsTemplates ( ) {
144- const templates : {
145- key ?: string ;
146- value : string ;
147- description ?: string ;
148- } [ ] = [ ] ;
149- templates . push ( {
142+ const templates = [ {
150143 key : CreateProjectCommand . HelloWorldTemplateKey ,
151- value : "tns-template-hello-world" ,
144+ value : constants . RESERVED_TEMPLATE_NAMES . javascript ,
152145 description : CreateProjectCommand . HelloWorldTemplateDescription
153- } ) ;
154- templates . push ( {
146+ } ,
147+ {
155148 key : CreateProjectCommand . DrawerTemplateKey ,
156149 value : "tns-template-drawer-navigation" ,
157150 description : CreateProjectCommand . DrawerTemplateDescription
158- } ) ;
159- templates . push ( {
151+ } ,
152+ {
160153 key : CreateProjectCommand . TabsTemplateKey ,
161154 value : "tns-template-tab-navigation" ,
162155 description : CreateProjectCommand . TabsTemplateDescription
163- } ) ;
156+ } ] ;
157+
164158 return templates ;
165159 }
166160
167161 private getTsTemplates ( ) {
168- const templates : {
169- key ?: string ;
170- value : string ;
171- description ?: string ;
172- } [ ] = [ ] ;
173- templates . push ( {
162+ const templates = [ {
174163 key : CreateProjectCommand . HelloWorldTemplateKey ,
175- value : "tns-template-hello-world-ts" ,
164+ value : constants . RESERVED_TEMPLATE_NAMES . typescript ,
176165 description : CreateProjectCommand . HelloWorldTemplateDescription
177- } ) ;
178- templates . push ( {
166+ } ,
167+ {
179168 key : CreateProjectCommand . DrawerTemplateKey ,
180169 value : "tns-template-drawer-navigation-ts" ,
181170 description : CreateProjectCommand . DrawerTemplateDescription
182- } ) ;
183- templates . push ( {
171+ } ,
172+ {
184173 key : CreateProjectCommand . TabsTemplateKey ,
185174 value : "tns-template-tab-navigation-ts" ,
186175 description : CreateProjectCommand . TabsTemplateDescription
187- } ) ;
176+ } ] ;
177+
188178 return templates ;
189179 }
190180
191181 private getNgFlavors ( ) {
192- const templates : {
193- key ?: string ;
194- value : string ;
195- description ?: string ;
196- } [ ] = [ ] ;
197- templates . push ( {
182+ const templates = [ {
198183 key : CreateProjectCommand . HelloWorldTemplateKey ,
199- value : "tns-template-hello-world-ng" ,
184+ value : constants . RESERVED_TEMPLATE_NAMES . angular ,
200185 description : CreateProjectCommand . HelloWorldTemplateDescription
201- } ) ;
202- templates . push ( {
186+ } ,
187+ {
203188 key : CreateProjectCommand . DrawerTemplateKey ,
204189 value : "tns-template-drawer-navigation-ng" ,
205190 description : CreateProjectCommand . DrawerTemplateDescription
206- } ) ;
207- templates . push ( {
191+ } ,
192+ {
208193 key : CreateProjectCommand . TabsTemplateKey ,
209194 value : "tns-template-tab-navigation-ng" ,
210195 description : CreateProjectCommand . TabsTemplateDescription
211- } ) ;
196+ } ] ;
212197
213198 return templates ;
214199 }
0 commit comments