@@ -38,13 +38,13 @@ async function getInstallationsDir() {
38
38
] ) ;
39
39
target_directory = answer . target_directory ;
40
40
}
41
- console . log ( `This will setup parse-server in ${ target_directory } ` ) ;
41
+ console . log ( `This will setup parse-server in ${ chalk . bold ( target_directory ) } ` ) ;
42
42
await confirm ( `Do you want to continue?` ) ;
43
- console . log ( `Setting up parse-server in ${ target_directory } ` ) ;
43
+ console . log ( `Setting up parse-server in ${ chalk . bold ( target_directory ) } ` ) ;
44
44
return target_directory ;
45
45
}
46
46
47
- async function getAppConfiguration ( ) {
47
+ function getAppConfiguration ( ) {
48
48
const questions = [
49
49
{
50
50
type : 'input' ,
@@ -74,10 +74,10 @@ async function getAppConfiguration() {
74
74
}
75
75
] ;
76
76
77
- return await inquirer . prompt ( questions ) ;
77
+ return inquirer . prompt ( questions ) ;
78
78
}
79
79
80
- async function confirm ( message , defaults = true ) {
80
+ function confirm ( message , defaults = true ) {
81
81
return inquirer . prompt ( [
82
82
{
83
83
type : 'confirm' ,
@@ -95,59 +95,60 @@ async function confirm(message, defaults = true) {
95
95
( async function main ( ) {
96
96
let target_directory = await getInstallationsDir ( ) ;
97
97
target_directory = path . resolve ( target_directory ) ;
98
- if ( ! fs . existsSync ( target_directory ) ) {
99
- shell . mkdir ( target_directory ) ;
100
- }
101
- if ( fs . existsSync ( `${ target_directory } /package.json` ) ) {
102
- await confirm ( `package.json exists\nDo you want to continue? ${ chalk . red ( `this will erase your configuration` ) } ` , false ) ;
98
+ if ( fs . existsSync ( target_directory ) ) {
99
+ console . log ( chalk . red ( `${ chalk . bold ( target_directory ) } already exists.\naborting...` ) ) ;
100
+ process . exit ( 1 ) ;
103
101
}
104
102
105
- if ( fs . existsSync ( `${ target_directory } /config.js` ) ) {
106
- await confirm ( `config.js exists\nDo you want to continue? \n${ chalk . red ( `this will erase your configuration` ) } ` , false ) ;
107
- }
103
+ shell . mkdir ( target_directory ) ;
104
+
108
105
const config = await getAppConfiguration ( ) ;
106
+ const {
107
+ masterKey,
108
+ databaseURI
109
+ } = config ;
110
+
111
+ // Cleanup sensitive info
112
+ delete config . masterKey ;
113
+ delete config . databaseURI ;
114
+
109
115
shell . cd ( target_directory ) ;
110
116
111
117
const packageContent = {
112
118
scripts : {
113
- start : "parse-server config.js"
119
+ start : "node -r dotenv/config node_modules/.bin/ parse-server config.js"
114
120
}
115
121
} ;
116
122
fs . writeFileSync (
117
123
target_directory + "/package.json" ,
118
- JSON . stringify ( packageContent , null , 2 ) + "\n"
124
+ JSON . stringify ( packageContent , null , 2 ) + '\n'
119
125
) ;
126
+ ok ( 'Added package.json' ) ;
120
127
121
128
fs . writeFileSync (
122
- target_directory + " /config.js" ,
123
- ` module.exports = ` + JSON . stringify ( config , null , 2 ) + " ;\n"
129
+ target_directory + ' /config.js' ,
130
+ ' module.exports = ' + JSON . stringify ( config , null , 2 ) + ' ;\n'
124
131
) ;
132
+ ok ( 'Added config.js' ) ;
125
133
126
- if ( fs . existsSync ( target_directory + '/cloud' ) ) {
127
- ok ( 'cloud/ exists' ) ;
128
- } else {
129
- shell . mkdir ( target_directory + '/cloud' ) ;
130
- ok ( 'Created cloud/' ) ;
131
- }
134
+ fs . writeFileSync (
135
+ target_directory + '/.env' ,
136
+ `PARSE_SERVER_MASTER_KEY=${ masterKey } \nPARSE_SERVER_DATABASE_URI=${ databaseURI } \n`
137
+ )
138
+ ok ( 'Added .env' ) ;
132
139
133
- if ( fs . existsSync ( target_directory + '/cloud/main.js' ) ) {
134
- ok ( 'cloud/main.js exists' ) ;
135
- } else {
136
- fs . writeFileSync ( target_directory + '/cloud/main.js' , `// Cloud Code entry point\n` ) ;
137
- ok ( 'Created cloud/main.js' ) ;
138
- }
140
+ shell . mkdir ( target_directory + '/cloud' ) ;
141
+ ok ( 'Created cloud/' ) ;
139
142
140
- if ( fs . existsSync ( target_directory + '/public' ) ) {
141
- ok ( 'public/ exists' ) ;
142
- } else {
143
- shell . mkdir ( target_directory + '/public' ) ;
144
- ok ( 'Created public/' ) ;
145
- }
143
+ fs . writeFileSync ( target_directory + '/cloud/main.js' , `// Cloud Code entry point\n` ) ;
144
+ ok ( 'Created cloud/main.js' ) ;
145
+ shell . mkdir ( target_directory + '/public' ) ;
146
+ ok ( 'Created public/' ) ;
146
147
147
148
if ( useYarn ) {
148
- shell . exec ( "yarn add parse-server" ) ;
149
+ shell . exec ( "yarn add parse-server dotenv " ) ;
149
150
} else {
150
- shell . exec ( "npm install parse-server --save" ) ;
151
+ shell . exec ( "npm install parse-server dotenv --save" ) ;
151
152
}
152
153
153
154
console . log ( chalk . green ( `parse-server is installed in \n\t${ target_directory } !\n` ) ) ;
0 commit comments