budibase/packages/server/initialise/initialiseBudibase.js

76 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-06-07 13:02:48 +02:00
const create = require("./createMasterDb");
const argv = require("yargs").argv
const readline = require('readline');
const { promisify } = require('util');
2019-06-28 23:59:27 +02:00
const { mkdir, rimraf } = require("../utilities/fsawait");
const budibaseConfig = require("../config");
2019-07-09 08:29:50 +02:00
const buildAppContext = require("../initialise/buildAppContext");
2019-06-07 13:02:48 +02:00
readline.Interface.prototype.question[promisify.custom] = function(prompt) {
return new Promise(resolve =>
readline.Interface.prototype.question.call(this, prompt, resolve),
);
};
readline.Interface.prototype.questionAsync = promisify(
readline.Interface.prototype.question,
);
const question = async (q) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
var answer = await rl.questionAsync(q);
rl.close();
return answer;
}
(async () => {
const datastore = argv.datastore
? argv.datastore
: await question("Datastore: ");
if(!datastore) throw new Error("Datastore not supplied!");
const username = argv.username
? argv.username
: await question("Owner Username: ");
const password = argv.password
? argv.password
: await question("Owner Password: ");
if(!username) throw new Error("Username not supplied!");
if(!password) throw new Error("Password not supplied!");
2019-06-07 15:18:10 +02:00
var datastoreModule = require("../../datastores/datastores/" + datastore);
2019-06-07 13:02:48 +02:00
const rootconfig = {};
for(let parameter in datastoreModule.configParameters) {
rootconfig[parameter] = argv[parameter]
? argv[parameter]
: await question(`${datastoreModule.configParameters[parameter]}: `);
}
const cleanDev = argv.cleanDev ? true : false;
if(cleanDev) {
try {
await rimraf(rootconfig.rootPath);
}
catch(_){}
await mkdir(rootconfig.rootPath);
}
2019-07-09 08:29:50 +02:00
const appContext = await buildAppContext(budibaseConfig, false);
2019-06-07 13:02:48 +02:00
await create(
2019-07-09 08:29:50 +02:00
appContext,
datastoreModule,
username,
password);
2019-06-07 13:02:48 +02:00
})()