2018-04-16 09:32:56 +00:00
|
|
|
const frappe = require('frappejs');
|
2018-03-30 17:03:12 +00:00
|
|
|
const path = require('path');
|
2018-03-29 18:52:46 +00:00
|
|
|
const electron = require('frappejs/client/electron');
|
|
|
|
const appClient = require('../client');
|
2018-03-30 17:03:12 +00:00
|
|
|
const SetupWizard = require('../setup');
|
2018-04-16 09:32:56 +00:00
|
|
|
const { getPDFForElectron } = require('frappejs/server/pdf');
|
2018-04-16 13:03:54 +00:00
|
|
|
const { getSettings, saveSettings } = require('./settings');
|
|
|
|
const { postStart } = require('../server');
|
2018-03-26 14:07:27 +00:00
|
|
|
|
2018-04-08 18:33:32 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
require.extensions['.html'] = function (module, filename) {
|
|
|
|
module.exports = fs.readFileSync(filename, 'utf8');
|
|
|
|
};
|
|
|
|
|
2018-03-30 17:03:12 +00:00
|
|
|
(async () => {
|
2018-04-16 13:03:54 +00:00
|
|
|
let electronSettings = getSettings();
|
|
|
|
let firstRun = false, setupWizardValues = null;
|
|
|
|
|
|
|
|
if (!electronSettings.dbPath) {
|
|
|
|
const values = await runSetupWizard();
|
|
|
|
const dbPath = path.join(values.file[0].path, frappe.slug(values.companyName) + '.db');
|
|
|
|
const config = {
|
|
|
|
directory: path.dirname(dbPath),
|
|
|
|
dbPath: dbPath
|
|
|
|
};
|
|
|
|
await saveSettings(config);
|
|
|
|
|
|
|
|
firstRun = true;
|
|
|
|
electronSettings = config;
|
|
|
|
setupWizardValues = values;
|
2018-03-30 17:03:12 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 13:03:54 +00:00
|
|
|
await electron.start({
|
|
|
|
dbPath: electronSettings.dbPath,
|
|
|
|
models: require('../models')
|
|
|
|
});
|
2018-04-16 09:32:56 +00:00
|
|
|
|
2018-04-16 13:03:54 +00:00
|
|
|
// await postStart();
|
2018-04-16 09:32:56 +00:00
|
|
|
|
2018-04-16 13:03:54 +00:00
|
|
|
if (firstRun) {
|
|
|
|
await saveSetupWizardValues(values);
|
|
|
|
await bootstrapChartOfAccounts();
|
2018-03-30 17:03:12 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 13:03:54 +00:00
|
|
|
frappe.getPDF = getPDFForElectron;
|
|
|
|
frappe.electronSettings = electronSettings;
|
2018-03-30 17:03:12 +00:00
|
|
|
|
2018-04-16 13:03:54 +00:00
|
|
|
appClient.start();
|
2018-03-30 17:03:12 +00:00
|
|
|
})();
|
2018-03-26 14:07:27 +00:00
|
|
|
|
2018-04-16 13:03:54 +00:00
|
|
|
async function runSetupWizard() {
|
|
|
|
const setup = new SetupWizard();
|
|
|
|
const values = await setup.start();
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveSetupWizardValues(values) {
|
|
|
|
const {
|
|
|
|
companyName,
|
|
|
|
country,
|
|
|
|
name,
|
|
|
|
email,
|
|
|
|
abbreviation,
|
|
|
|
bankName
|
|
|
|
} = values;
|
|
|
|
|
|
|
|
const doc = await frappe.getDoc('AccountingSettings');
|
|
|
|
|
|
|
|
await doc.set('companyName', companyName);
|
|
|
|
await doc.set('country', country);
|
|
|
|
await doc.set('fullname', name);
|
|
|
|
await doc.set('email', email);
|
|
|
|
await doc.set('bankName', bankName);
|
|
|
|
|
|
|
|
await doc.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function bootstrapChartOfAccounts() {
|
|
|
|
const importCOA = require('../models/doctype/account/importCOA');
|
|
|
|
const chart = require('../fixtures/standardCOA');
|
|
|
|
await importCOA(chart);
|
|
|
|
}
|