2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00
books/electron/client.js

89 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-04-16 09:32:56 +00:00
const frappe = require('frappejs');
const path = require('path');
2018-03-29 18:52:46 +00:00
const electron = require('frappejs/client/electron');
const appClient = require('../client');
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-04-18 06:47:00 +00:00
const { slug } = require('frappejs/utils');
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');
};
(async () => {
2018-04-16 13:03:54 +00:00
let electronSettings = getSettings();
let firstRun = false, setupWizardValues = null;
if (!electronSettings.dbPath) {
const values = await runSetupWizard();
2018-04-18 06:47:00 +00:00
const dbPath = path.join(values.file[0].path, slug(values.companyName) + '.db');
2018-04-16 13:03:54 +00:00
const config = {
directory: path.dirname(dbPath),
dbPath: dbPath
};
await saveSettings(config);
firstRun = true;
electronSettings = config;
setupWizardValues = values;
}
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-18 06:47:00 +00:00
await postStart();
2018-04-16 09:32:56 +00:00
2018-04-16 13:03:54 +00:00
if (firstRun) {
2018-04-18 06:47:00 +00:00
await saveSetupWizardValues(setupWizardValues);
2018-04-16 13:03:54 +00:00
await bootstrapChartOfAccounts();
}
2018-04-16 13:03:54 +00:00
frappe.getPDF = getPDFForElectron;
frappe.electronSettings = electronSettings;
2018-04-16 13:03:54 +00:00
appClient.start();
})();
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,
fiscalYearStart,
fiscalYearEnd
2018-04-16 13:03:54 +00:00
} = 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.set('fiscalYearStart', fiscalYearStart);
await doc.set('fiscalYearEnd', fiscalYearEnd);
2018-04-16 13:03:54 +00:00
await doc.update();
}
async function bootstrapChartOfAccounts() {
const importCOA = require('../models/doctype/account/importCOA');
const chart = require('../fixtures/standardCOA');
await importCOA(chart);
}