@@ -21,7 +21,21 @@ async function main() {
21
21
console . log ( gray ( `\ncreate-svelte version ${ version } ` ) ) ;
22
22
console . log ( disclaimer ) ;
23
23
24
- const cwd = process . argv [ 2 ] || '.' ;
24
+ let cwd = process . argv [ 2 ] || '.' ;
25
+
26
+ if ( cwd === '.' ) {
27
+ const opts = await prompts ( [
28
+ {
29
+ type : 'text' ,
30
+ name : 'dir' ,
31
+ message : 'Where should we create your project?\n (leave blank to use current directory)'
32
+ }
33
+ ] ) ;
34
+
35
+ if ( opts . dir ) {
36
+ cwd = opts . dir ;
37
+ }
38
+ }
25
39
26
40
if ( fs . existsSync ( cwd ) ) {
27
41
if ( fs . readdirSync ( cwd ) . length > 0 ) {
@@ -39,48 +53,57 @@ async function main() {
39
53
}
40
54
41
55
const options = /** @type {import('./types/internal').Options } */ (
42
- await prompts ( [
43
- {
44
- type : 'select' ,
45
- name : 'template' ,
46
- message : 'Which Svelte app template?' ,
47
- choices : fs . readdirSync ( dist ( 'templates' ) ) . map ( ( dir ) => {
48
- const meta_file = dist ( `templates/${ dir } /meta.json` ) ;
49
- const meta = JSON . parse ( fs . readFileSync ( meta_file , 'utf8' ) ) ;
50
-
51
- return {
52
- title : meta . description ,
53
- value : dir
54
- } ;
55
- } )
56
- } ,
57
- {
58
- type : 'toggle' ,
59
- name : 'typescript' ,
60
- message : 'Use TypeScript?' ,
61
- initial : false ,
62
- active : 'Yes' ,
63
- inactive : 'No'
64
- } ,
56
+ await prompts (
57
+ [
58
+ {
59
+ type : 'select' ,
60
+ name : 'template' ,
61
+ message : 'Which Svelte app template?' ,
62
+ choices : fs . readdirSync ( dist ( 'templates' ) ) . map ( ( dir ) => {
63
+ const meta_file = dist ( `templates/${ dir } /meta.json` ) ;
64
+ const meta = JSON . parse ( fs . readFileSync ( meta_file , 'utf8' ) ) ;
65
+
66
+ return {
67
+ title : meta . description ,
68
+ value : dir
69
+ } ;
70
+ } )
71
+ } ,
72
+ {
73
+ type : 'toggle' ,
74
+ name : 'typescript' ,
75
+ message : 'Use TypeScript?' ,
76
+ initial : false ,
77
+ active : 'Yes' ,
78
+ inactive : 'No'
79
+ } ,
80
+ {
81
+ type : 'toggle' ,
82
+ name : 'eslint' ,
83
+ message : 'Add ESLint for code linting?' ,
84
+ initial : false ,
85
+ active : 'Yes' ,
86
+ inactive : 'No'
87
+ } ,
88
+ {
89
+ type : 'toggle' ,
90
+ name : 'prettier' ,
91
+ message : 'Add Prettier for code formatting?' ,
92
+ initial : false ,
93
+ active : 'Yes' ,
94
+ inactive : 'No'
95
+ }
96
+ ] ,
65
97
{
66
- type : 'toggle' ,
67
- name : 'eslint' ,
68
- message : 'Add ESLint for code linting?' ,
69
- initial : false ,
70
- active : 'Yes' ,
71
- inactive : 'No'
72
- } ,
73
- {
74
- type : 'toggle' ,
75
- name : 'prettier' ,
76
- message : 'Add Prettier for code formatting?' ,
77
- initial : false ,
78
- active : 'Yes' ,
79
- inactive : 'No'
98
+ onCancel : ( ) => {
99
+ process . exit ( 1 ) ;
100
+ }
80
101
}
81
- ] )
102
+ )
82
103
) ;
83
104
105
+ options . name = path . basename ( path . resolve ( cwd ) ) ;
106
+
84
107
await create ( cwd , options ) ;
85
108
86
109
console . log ( bold ( green ( '\nYour project is ready!' ) ) ) ;
0 commit comments