@@ -9,6 +9,7 @@ const CWD = process.cwd();
9
9
const crypto = require ( 'crypto' ) ;
10
10
const DEFAULT_MONGODB_URI = 'mongodb://127.0.0.1:27017/parse' ;
11
11
const CHECK = '✓' ;
12
+ const program = require ( 'commander' ) ;
12
13
13
14
let useYarn = false ;
14
15
if ( shell . which ( "yarn" ) ) {
@@ -23,11 +24,11 @@ function ok(message) {
23
24
console . log ( chalk . green ( `${ CHECK } ${ message } ` ) ) ;
24
25
}
25
26
26
- async function getInstallationsDir ( ) {
27
+ async function getInstallationsDir ( { directory , interactive } ) {
27
28
let target_directory ;
28
- if ( process . argv . length == 3 ) {
29
- target_directory = process . argv [ 2 ] ;
30
- } else {
29
+ if ( directory ) {
30
+ target_directory = directory ;
31
+ } else if ( interactive ) {
31
32
const answer = await inquirer . prompt ( [
32
33
{
33
34
type : 'input' ,
@@ -37,14 +38,24 @@ async function getInstallationsDir() {
37
38
} ,
38
39
] ) ;
39
40
target_directory = answer . target_directory ;
41
+ } else {
42
+ target_directory = './parse-server'
40
43
}
41
44
console . log ( `This will setup parse-server in ${ chalk . bold ( target_directory ) } ` ) ;
42
45
await confirm ( `Do you want to continue?` ) ;
43
46
console . log ( `Setting up parse-server in ${ chalk . bold ( target_directory ) } ` ) ;
44
47
return target_directory ;
45
48
}
46
49
47
- function getAppConfiguration ( ) {
50
+ function getAppConfiguration ( { interactive } ) {
51
+ if ( ! interactive ) {
52
+ return {
53
+ appName : 'My Parse Server' ,
54
+ appId : generateKey ( ) ,
55
+ masterKey : generateKey ( ) ,
56
+ databaseURI : DEFAULT_MONGODB_URI
57
+ } ;
58
+ }
48
59
const questions = [
49
60
{
50
61
type : 'input' ,
@@ -92,8 +103,11 @@ function confirm(message, defaults = true) {
92
103
} ) ;
93
104
}
94
105
95
- ( async function main ( ) {
96
- let target_directory = await getInstallationsDir ( ) ;
106
+ async function main ( {
107
+ directory,
108
+ interactive,
109
+ } ) {
110
+ let target_directory = await getInstallationsDir ( { interactive, directory } ) ;
97
111
target_directory = path . resolve ( target_directory ) ;
98
112
if ( fs . existsSync ( target_directory ) ) {
99
113
console . log ( chalk . red ( `${ chalk . bold ( target_directory ) } already exists.\naborting...` ) ) ;
@@ -102,7 +116,7 @@ function confirm(message, defaults = true) {
102
116
103
117
shell . mkdir ( target_directory ) ;
104
118
105
- const config = await getAppConfiguration ( ) ;
119
+ const config = await getAppConfiguration ( { interactive } ) ;
106
120
const {
107
121
masterKey,
108
122
databaseURI
@@ -152,10 +166,17 @@ function confirm(message, defaults = true) {
152
166
}
153
167
154
168
console . log ( chalk . green ( `parse-server is installed in \n\t${ target_directory } !\n` ) ) ;
155
- await confirm ( ' Do you want to start the server now?' ) ;
169
+ await confirm ( ` Do you want to start the server now?\nEnsure a database running on ${ databaseURI } ` ) ;
156
170
if ( useYarn ) {
157
171
shell . exec ( "yarn start" ) ;
158
172
} else {
159
173
shell . exec ( "npm start" ) ;
160
174
}
161
- } ) ( ) ;
175
+ }
176
+
177
+ program
178
+ . option ( '-i, --interactive' , 'Configure manually' )
179
+ . option ( '-d, --directory [directory]' , 'The target directory where to create a new parse-server' )
180
+ . parse ( process . argv ) ;
181
+
182
+ main ( program ) ;
0 commit comments