try to fix export in electron

This commit is contained in:
Jan Prochazka 2021-02-14 11:09:49 +01:00
parent 670e3d127e
commit 89dbf38962
3 changed files with 11 additions and 7 deletions

View File

@ -24,7 +24,7 @@ const requirePluginsTemplate = plugins =>
const scriptTemplate = script => `
const dbgateApi = require(process.env.DBGATE_API);
dbgateApi.registerProcessCommunication();
dbgateApi.initializeApiEnvironment();
${requirePluginsTemplate(extractPlugins(script))}
require=null;
async function run() {
@ -37,7 +37,7 @@ dbgateApi.runScript(run);
const loaderScriptTemplate = (functionName, props, runid) => `
const dbgateApi = require(process.env.DBGATE_API);
dbgateApi.registerProcessCommunication();
dbgateApi.initializeApiEnvironment();
${requirePluginsTemplate(extractShellApiPlugins(functionName, props))}
require=null;
async function run() {
@ -96,10 +96,10 @@ module.exports = {
console.log(`RUNNING SCRIPT ${scriptFile}`);
// const subprocess = fork(scriptFile, ['--checkParent', '--max-old-space-size=8192'], {
const subprocess = fork(scriptFile, ['--checkParent', ...process.argv.slice(3)], {
cwd: directory,
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
env: {
DBGATE_API: process.argv[1],
DBGATE_CWD: directory,
..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, path.join(pluginsdir(), name)])),
},
});

View File

@ -17,7 +17,7 @@ const requirePlugin = require('./requirePlugin');
const download = require('./download');
const executeQuery = require('./executeQuery');
const loadFile = require('./loadFile');
const registerProcessCommunication = require('./registerProcessCommunication');
const initializeApiEnvironment = require('./initializeApiEnvironment');
const dbgateApi = {
queryReader,
@ -38,7 +38,7 @@ const dbgateApi = {
registerPlugins,
executeQuery,
loadFile,
registerProcessCommunication,
initializeApiEnvironment,
};
requirePlugin.initializeDbgateApi(dbgateApi);

View File

@ -1,9 +1,13 @@
const { handleProcessCommunication } = require('../utility/processComm');
async function registerProcessCommunication() {
async function initializeApiEnvironment() {
process.on('message', async message => {
handleProcessCommunication(message);
});
if (process.env.DBGATE_CWD) {
process.chdir(process.env.DBGATE_CWD);
}
}
module.exports = registerProcessCommunication;
module.exports = initializeApiEnvironment;