Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify reading dashboard config from a json file #1828

Merged
merged 4 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions Parse-Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Command line tool for npm start
'use strict'
const path = require('path');
const jsonFile = require('json-file-plus');
const fs = require('fs');
const express = require('express');
const parseDashboard = require('./app');
const CLIHelper = require('./CLIHelper.js');
Expand Down Expand Up @@ -126,19 +126,39 @@ if (!program.config && !process.env.PARSE_DASHBOARD_CONFIG) {
}
}

let p = null;
let config = null;
let configFilePath = null;
if (configFile) {
p = jsonFile(configFile);
try {
config = {
data: JSON.parse(fs.readFileSync(configFile, 'utf8'))
};
configFilePath = path.dirname(configFile);
} catch (error) {
if (error instanceof SyntaxError) {
console.log('Your config file contains invalid JSON. Exiting.');
process.exit(1);
} else if (error.code === 'ENOENT') {
if (explicitConfigFileProvided) {
console.log('Your config file is missing. Exiting.');
process.exit(2);
} else {
console.log('You must provide either a config file or required CLI options (app ID, Master Key, and server URL); not both.');
process.exit(3);
}
} else {
console.log('There was a problem with your config. Exiting.');
process.exit(-1);
}
}
} else if (configFromCLI) {
p = Promise.resolve(configFromCLI);
config = configFromCLI;
} else {
//Failed to load default config file.
console.log('You must provide either a config file or an app ID, Master Key, and server URL. See parse-dashboard --help for details.');
process.exit(4);
}
p.then(config => {

config.data.apps.forEach(app => {
if (!app.appName) {
app.appName = app.appId;
Expand All @@ -164,7 +184,6 @@ p.then(config => {
});
} else {
// Start the server using SSL.
var fs = require('fs');
var privateKey = fs.readFileSync(configSSLKey);
var certificate = fs.readFileSync(configSSLCert);

Expand All @@ -176,24 +195,3 @@ p.then(config => {
});
}
handleSIGs(server);
}, error => {
if (error instanceof SyntaxError) {
console.log('Your config file contains invalid JSON. Exiting.');
process.exit(1);
} else if (error.code === 'ENOENT') {
if (explicitConfigFileProvided) {
console.log('Your config file is missing. Exiting.');
process.exit(2);
} else {
console.log('You must provide either a config file or required CLI options (app ID, Master Key, and server URL); not both.');
process.exit(3);
}
} else {
console.log('There was a problem with your config. Exiting.');
process.exit(-1);
}
})
.catch(error => {
console.log('There was a problem loading the dashboard. Exiting.', error);
process.exit(-1);
});
48 changes: 5 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"immutable-devtools": "0.1.5",
"inquirer": "8.1.3",
"js-beautify": "1.14.0",
"json-file-plus": "3.2.0",
"otpauth": "7.0.6",
"package-json": "6.5.0",
"parse": "3.3.1",
Expand Down