2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +00:00

Initialize db in electron entry

This commit is contained in:
Faris Ansari 2018-10-21 18:19:33 +05:30
parent 5a7a8c8efe
commit dfbddd651a
4 changed files with 54 additions and 45 deletions

View File

@ -2,7 +2,7 @@ const path = require('path');
const server = require('frappejs/server'); const server = require('frappejs/server');
const frappe = require('frappejs'); const frappe = require('frappejs');
const naming = require('frappejs/model/naming'); const naming = require('frappejs/model/naming');
const registerReportMethods = require('../reports'); const registerServerMethods = require('./registerServerMethods');
async function start() { async function start() {
await server.start({ await server.start({
@ -36,16 +36,7 @@ async function postStart() {
await naming.createNumberSeries('PO-', 'PurchaseOrderSettings'); await naming.createNumberSeries('PO-', 'PurchaseOrderSettings');
await naming.createNumberSeries('PREC-', 'PurchaseReceiptSettings'); await naming.createNumberSeries('PREC-', 'PurchaseReceiptSettings');
registerReportMethods(); registerServerMethods();
frappe.registerMethod({
method: 'import-coa',
async handler() {
const standardCOA = require('../fixtures/standardCOA');
const importCOA = require('../models/doctype/Account/importCOA');
await importCOA(standardCOA);
}
})
} }
start(); start();

View File

@ -0,0 +1,15 @@
const frappe = require('frappejs');
const registerReportMethods = require('../reports');
module.exports = function registerServerMethods() {
registerReportMethods();
frappe.registerMethod({
method: 'import-coa',
async handler() {
const standardCOA = require('../fixtures/standardCOA');
const importCOA = require('../models/doctype/Account/importCOA');
await importCOA(standardCOA);
}
});
}

View File

@ -1,3 +1,4 @@
const path = require('path');
const { app, BrowserWindow } = require('electron'); const { app, BrowserWindow } = require('electron');
const { getAppConfig } = require('frappejs/webpack/utils'); const { getAppConfig } = require('frappejs/webpack/utils');
const setupMenu = require('./menu'); const setupMenu = require('./menu');
@ -5,7 +6,7 @@ const setupMenu = require('./menu');
const appConfig = getAppConfig(); const appConfig = getAppConfig();
if (process.env.NODE_ENV !== 'development') { if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') global.__static = path.join(__dirname, '/static').replace(/\\/g, '\\\\')
} }
let mainWindow let mainWindow

View File

@ -6,27 +6,28 @@ import frappeVue from 'frappejs/ui/plugins/frappeVue';
// frappejs imports // frappejs imports
import frappe from 'frappejs'; import frappe from 'frappejs';
import frappeConf from '../frappe.conf';
import HTTPClient from 'frappejs/backends/http';
import SQLite from 'frappejs/backends/sqlite'; import SQLite from 'frappejs/backends/sqlite';
import common from 'frappejs/common'; import common from 'frappejs/common';
import coreModels from 'frappejs/models'; import coreModels from 'frappejs/models';
import models from '../models'; import models from '../models';
import registerReportMethods from '../reports'; import registerServerMethods from '../server/registerServerMethods';
console.log('electron is here') (async () => {
frappe.isServer = true;
frappe.init();
frappe.registerLibs(common);
frappe.registerModels(coreModels);
frappe.registerModels(models);
frappe.fetch = window.fetch.bind();
frappe.login('Administrator');
frappe.db = new SQLite({ dbPath: 'test.db' });
await frappe.db.connect();
await frappe.db.migrate();
frappe.init(); frappe.getSingle('SystemSettings');
frappe.registerLibs(common); registerServerMethods();
frappe.registerModels(coreModels);
frappe.registerModels(models);
frappe.fetch = window.fetch.bind();
frappe.db = new SQLite({ dbPath: 'test.db' });
frappe.getSingle('SystemSettings'); frappe.getSingle('AccountingSettings')
registerReportMethods();
frappe.getSingle('AccountingSettings')
.then(accountingSettings => { .then(accountingSettings => {
if (router.currentRoute.fullPath !== '/') return; if (router.currentRoute.fullPath !== '/') return;
@ -37,15 +38,16 @@ frappe.getSingle('AccountingSettings')
} }
}); });
window.frappe = frappe; window.frappe = frappe;
Vue.config.productionTip = false; Vue.config.productionTip = false;
Vue.use(frappeVue); Vue.use(frappeVue);
/* eslint-disable no-new */ /* eslint-disable no-new */
new Vue({ new Vue({
el: '#app', el: '#app',
router, router,
components: { App }, components: { App },
template: '<App/>' template: '<App/>'
}); });
})()