Skip to content

Commit b7b7f69

Browse files
committed
Adds interactive options and directory
- This way running `npx @parse/init` will generate appId/masterKey
1 parent eea3042 commit b7b7f69

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

parse-init/init.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const CWD = process.cwd();
99
const crypto = require('crypto');
1010
const DEFAULT_MONGODB_URI = 'mongodb://127.0.0.1:27017/parse';
1111
const CHECK = '✓';
12+
const program = require('commander');
1213

1314
let useYarn = false;
1415
if (shell.which("yarn")) {
@@ -23,11 +24,11 @@ function ok(message) {
2324
console.log(chalk.green(`${CHECK} ${message}`));
2425
}
2526

26-
async function getInstallationsDir() {
27+
async function getInstallationsDir({ directory, interactive }) {
2728
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) {
3132
const answer = await inquirer.prompt([
3233
{
3334
type: 'input',
@@ -37,14 +38,24 @@ async function getInstallationsDir() {
3738
},
3839
]);
3940
target_directory = answer.target_directory;
41+
} else {
42+
target_directory = './parse-server'
4043
}
4144
console.log(`This will setup parse-server in ${chalk.bold(target_directory)}`);
4245
await confirm(`Do you want to continue?`);
4346
console.log(`Setting up parse-server in ${chalk.bold(target_directory)}`);
4447
return target_directory;
4548
}
4649

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+
}
4859
const questions = [
4960
{
5061
type: 'input',
@@ -92,8 +103,11 @@ function confirm(message, defaults = true) {
92103
});
93104
}
94105

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 });
97111
target_directory = path.resolve(target_directory);
98112
if (fs.existsSync(target_directory)) {
99113
console.log(chalk.red(`${chalk.bold(target_directory)} already exists.\naborting...`));
@@ -102,7 +116,7 @@ function confirm(message, defaults = true) {
102116

103117
shell.mkdir(target_directory);
104118

105-
const config = await getAppConfiguration();
119+
const config = await getAppConfiguration({ interactive });
106120
const {
107121
masterKey,
108122
databaseURI
@@ -152,10 +166,17 @@ function confirm(message, defaults = true) {
152166
}
153167

154168
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}`);
156170
if (useYarn) {
157171
shell.exec("yarn start");
158172
} else {
159173
shell.exec("npm start");
160174
}
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);

parse-init/package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parse-init/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"license": "MIT",
1111
"dependencies": {
1212
"chalk": "^2.4.1",
13+
"commander": "^2.17.1",
1314
"inquirer": "^6.1.0",
1415
"shelljs": "^0.8.2"
1516
}

0 commit comments

Comments
 (0)