@@ -5,60 +5,83 @@ const changeCase = require('change-case');
55//
66module . exports = {
77 prompt : ( { inquirer } ) => {
8- const questions = [
9- {
10- type : 'input' ,
11- name : 'name' ,
12- message : 'Which component is this playground for?' ,
13- initial : 'ion-button' ,
14- validate ( value ) {
15- return value . match ( / ^ i o n - [ a - z / - ] * [ a - z ] + $ / ) ? true : "Component name must be kebab-case and begin with 'ion-'" ;
8+ return inquirer
9+ . prompt ( [
10+ {
11+ type : 'toggle' ,
12+ name : 'is_component' ,
13+ message : 'Is this playground for a component?' ,
14+ initial : true ,
1615 } ,
17- } ,
18- {
19- type : 'input' ,
20- name : 'path' ,
21- message : 'What should the playground path be?' ,
22- hint : 'e.g. `basic` or `theming/colors`' ,
23- validate ( value ) {
24- return value . match ( / ^ [ a - z ] + [ a - z / - ] * [ a - z ] + $ / )
25- ? true
26- : "Path should begin and end with a letter and only contain lowercase letters, '-', or '/'" ;
27- } ,
28- } ,
29- {
30- type : 'select' ,
31- name : 'version' ,
32- message : 'Select the Ionic Framework version for the playground' ,
33- initial : '7' ,
34- choices : [ '6' , '7' ] ,
35- } ,
36- {
37- type : 'toggle' ,
38- name : 'css' ,
39- message : 'Generate custom CSS files?' ,
40- enabled : 'Yes' ,
41- disabled : 'No' ,
42- } ,
43- {
44- type : 'toggle' ,
45- name : 'angular_ts' ,
46- message : 'Generate an Angular TypeScript file?' ,
47- enabled : 'Yes' ,
48- disabled : 'No' ,
49- } ,
50- ] ;
16+ ] )
17+ . then ( ( answers ) => {
18+ return inquirer
19+ . prompt ( [
20+ // ask a different question for components vs. other playgrounds
21+ answers . is_component
22+ ? {
23+ type : 'input' ,
24+ name : 'component' ,
25+ message : 'Which component is this playground for?' ,
26+ initial : 'ion-button' ,
27+ validate ( value ) {
28+ return value . match ( / ^ i o n - [ a - z / - ] * [ a - z ] + $ / )
29+ ? true
30+ : "Component name must be kebab-case and begin with 'ion-'" ;
31+ } ,
32+ }
33+ : {
34+ type : 'input' ,
35+ name : 'name' ,
36+ message : 'Which guide section is this playground for?' ,
37+ initial : 'animations' ,
38+ validate ( value ) {
39+ return value . match ( / ^ [ a - z / - ] + $ / ) ? true : 'Section must be kebab-case' ;
40+ } ,
41+ } ,
42+ {
43+ type : 'input' ,
44+ name : 'path' ,
45+ message : 'What should the playground path be?' ,
46+ hint : 'e.g. `basic` or `theming/colors`' ,
47+ validate ( value ) {
48+ return value . match ( / ^ [ a - z ] + [ a - z / - ] * [ a - z ] + $ / )
49+ ? true
50+ : "Path should begin and end with a letter and only contain lowercase letters, '-', or '/'" ;
51+ } ,
52+ } ,
53+ {
54+ type : 'select' ,
55+ name : 'version' ,
56+ message : 'Select the Ionic Framework version for the playground' ,
57+ initial : '7' ,
58+ choices : [ '6' , '7' ] ,
59+ } ,
60+ {
61+ type : 'toggle' ,
62+ name : 'css' ,
63+ message : 'Generate custom CSS files?' ,
64+ } ,
65+ {
66+ type : 'toggle' ,
67+ name : 'angular_ts' ,
68+ message : 'Generate an Angular TypeScript file?' ,
69+ } ,
70+ ] )
71+ . then ( ( answers ) => {
72+ answers . name = answers . name || answers . component . replace ( 'ion-' , '' ) ;
73+
74+ // if the playground is not for a component,
75+ // include an ion-card in the playground
76+ answers . component = answers . component || 'ion-card' ;
5177
52- return inquirer . prompt ( questions ) . then ( ( answers ) => {
53- const componentName = changeCase . pascal ( answers . path . split ( '/' ) . pop ( ) ) ;
54- console . log (
55- `\nTo use this component in a docs markdown file, include\nthe following:\n\n## ${ componentName } \n\nimport ${ componentName } from '@site/static/usage/v7/${ answers . name . replace (
56- 'ion-' ,
57- ''
58- ) } /${ answers . path } /index.md';\n\n<${ componentName } />\n`
59- ) ;
78+ const playgroundName = changeCase . pascal ( answers . path . split ( '/' ) . pop ( ) ) ;
79+ console . log (
80+ `\nTo use this playground in a docs markdown file, include\nthe following:\n\n## ${ playgroundName } \n\nimport ${ playgroundName } from '@site/static/usage/v7/${ answers . name } /${ answers . path } /index.md';\n\n<${ playgroundName } />\n`
81+ ) ;
6082
61- return answers ;
62- } ) ;
83+ return answers ;
84+ } ) ;
85+ } ) ;
6386 } ,
6487} ;
0 commit comments