|
|
|
@ -5,6 +5,7 @@ const path = require('path');
|
|
|
|
|
const cluster = require('cluster');
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
const { argv } = require('yargs');
|
|
|
|
|
const child = require('child_process');
|
|
|
|
|
|
|
|
|
|
if (!cluster.isMaster) {
|
|
|
|
|
const hydro = require('../dist/loader');
|
|
|
|
@ -14,11 +15,25 @@ if (!cluster.isMaster) {
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
fs.ensureDirSync(path.resolve(os.homedir(), '.hydro'));
|
|
|
|
|
const addonPath = path.resolve(os.homedir(), '.hydro', 'addon.json');
|
|
|
|
|
const hydroPath = path.resolve(os.homedir(), '.hydro');
|
|
|
|
|
fs.ensureDirSync(hydroPath);
|
|
|
|
|
const addonPath = path.resolve(hydroPath, 'addon.json');
|
|
|
|
|
if (!fs.existsSync(addonPath)) fs.writeFileSync(addonPath, '[]');
|
|
|
|
|
let addons = JSON.parse(fs.readFileSync(addonPath).toString());
|
|
|
|
|
|
|
|
|
|
if (argv._[0] === 'db') {
|
|
|
|
|
function buildUrl(opts) {
|
|
|
|
|
let mongourl = `${opts.protocol}://`;
|
|
|
|
|
if (opts.username) mongourl += `${opts.username}:${opts.password}@`;
|
|
|
|
|
mongourl += `${opts.host}:${opts.port}/${opts.name}`;
|
|
|
|
|
if (opts.url) mongourl = opts.url;
|
|
|
|
|
return mongourl;
|
|
|
|
|
}
|
|
|
|
|
const dbConfig = fs.readFileSync(path.resolve(hydroPath, 'config.json'), 'utf-8');
|
|
|
|
|
const url = buildUrl(JSON.parse(dbConfig));
|
|
|
|
|
return child.spawn('mongo', [url], { stdio: 'inherit' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const ui = argv.ui || '@hydrooj/ui-default';
|
|
|
|
|
require.resolve(ui);
|
|
|
|
|