@@ -45,35 +45,63 @@ export class JsonformsGenerator extends Generator {
45
45
}
46
46
47
47
async prompting ( ) {
48
+
48
49
if ( ! this . skipPrompting ) {
49
50
clear ( ) ;
50
51
this . log (
51
- chalk . blue (
52
- textSync ( 'JSONForms Tooling' , { horizontalLayout : 'full' } ) ,
53
- ) ,
52
+ textSync ( 'JSONForms Tooling' , { horizontalLayout : 'full' } ) ,
54
53
) ;
55
54
this . answers = await this . prompt ( [
56
55
{
57
- name : 'path ' ,
56
+ name : 'name ' ,
58
57
type : 'input' ,
59
- message : 'Enter the path where the project will be installed (default: current folder):' ,
60
- validate : async value => {
58
+ message : 'Enter a name for your seed project:' ,
59
+ default : 'jsonforms-react-seed' ,
60
+ validate : ( value : any ) => {
61
61
if ( value !== '' ) {
62
- try {
63
- await statWithPromise ( value ) ;
64
- } catch ( err ) {
65
- return 'Folder does not exists' ;
66
- }
62
+ const valid = validate ( value ) ;
63
+ return valid . validForNewPackages || 'Sorry, the name can only contain URL-friendly ' +
64
+ 'characters and cannot contain capital letters.' ;
67
65
}
68
66
return true ;
69
67
} ,
68
+ when : ( ) => {
69
+ if ( this . name === undefined ) {
70
+ return true ;
71
+ }
72
+ if ( ! validate ( this . name ) . validForNewPackages ) {
73
+ this . log ( chalk . red ( 'Sorry, the name can only contain URL-friendly ' +
74
+ 'characters and cannot contain capital letters.' ) ) ;
75
+ return true ;
76
+ }
77
+ return false ;
78
+ }
79
+ } ,
80
+ {
81
+ name : 'path' ,
82
+ type : 'input' ,
83
+ message : `Enter the path where the project will be installed:` ,
84
+ default : ( answers : any ) => {
85
+ if ( this . name !== undefined ) {
86
+ return join ( process . cwd ( ) , this . name ) ;
87
+ }
88
+ return join ( process . cwd ( ) , answers . name ) ;
89
+ } ,
90
+ validate : async ( value : any ) => {
91
+ try {
92
+ await statWithPromise ( value ) ;
93
+ } catch ( err ) {
94
+ return true ;
95
+ }
96
+ return 'Folder does already exists. Please enter a different path.' ;
97
+ } ,
70
98
when : ( this . path == null )
71
99
} ,
72
100
{
73
101
name : 'schemaPath' ,
74
102
type : 'input' ,
75
103
message : 'Enter the path of schema from which the ui schema will be generated (leave empty for default schema):' ,
76
- validate : async value => {
104
+ validate : async ( value : any ) => {
77
105
if ( value !== '' ) {
78
106
try {
79
107
await statWithPromise ( value ) ;
@@ -85,30 +113,6 @@ export class JsonformsGenerator extends Generator {
85
113
} ,
86
114
when : ( this . schemaPath == null )
87
115
} ,
88
- {
89
- name : 'name' ,
90
- type : 'input' ,
91
- message : `Enter a name for your seed project (default: jsonforms-react-seed):` ,
92
- validate : value => {
93
- if ( value !== '' ) {
94
- const valid = validate ( value ) ;
95
- return valid . validForNewPackages || 'Sorry, name can only contain URL-friendly ' +
96
- 'characters and name can no longer contain capital letters.' ;
97
- }
98
- return true ;
99
- } ,
100
- when : ( ) => {
101
- if ( this . name === undefined ) {
102
- return true ;
103
- }
104
- if ( ! validate ( this . name ) . validForNewPackages ) {
105
- this . log ( chalk . red ( 'Sorry, name can only contain URL-friendly ' +
106
- 'characters and name can no longer contain capital letters.' ) ) ;
107
- return true ;
108
- }
109
- return false ;
110
- }
111
- }
112
116
] ) ;
113
117
if ( this . answers && this . answers . path === '' || this . path === '' ) {
114
118
this . path = process . cwd ( ) ;
0 commit comments