mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 01:26:01 +00:00
#63 - workaround export from SNAP
This commit is contained in:
@@ -8,6 +8,7 @@ const { fork } = require('child_process');
|
||||
const { rundir, uploadsdir, pluginsdir } = require('../utility/directories');
|
||||
const { extractShellApiPlugins, extractShellApiFunctionName } = require('dbgate-tools');
|
||||
const { handleProcessCommunication } = require('../utility/processComm');
|
||||
const platformInfo = require('../utility/platformInfo');
|
||||
|
||||
function extractPlugins(script) {
|
||||
const requireRegex = /\s*\/\/\s*@require\s+([^\s]+)\s*\n/g;
|
||||
@@ -22,7 +23,20 @@ const requirePluginsTemplate = plugins =>
|
||||
)
|
||||
.join('') + `dbgateApi.registerPlugins(${plugins.map(x => _.camelCase(x)).join(',')});\n`;
|
||||
|
||||
// workaround - not working env in SNAP
|
||||
const expandEnvParamsScript = platformInfo.isSnap
|
||||
? `
|
||||
for(let i=0;i<process.argv.length;i+=1) {
|
||||
const arg=process.argv[i];
|
||||
if (arg.startsWith('--env.')) {
|
||||
process.env[arg.substring(6)] = process.argv[i+1]
|
||||
}
|
||||
}
|
||||
`
|
||||
: '';
|
||||
|
||||
const scriptTemplate = script => `
|
||||
${expandEnvParamsScript};
|
||||
const dbgateApi = require(process.env.DBGATE_API);
|
||||
dbgateApi.initializeApiEnvironment();
|
||||
${requirePluginsTemplate(extractPlugins(script))}
|
||||
@@ -36,6 +50,7 @@ dbgateApi.runScript(run);
|
||||
`;
|
||||
|
||||
const loaderScriptTemplate = (functionName, props, runid) => `
|
||||
${expandEnvParamsScript};
|
||||
const dbgateApi = require(process.env.DBGATE_API);
|
||||
dbgateApi.initializeApiEnvironment();
|
||||
${requirePluginsTemplate(extractShellApiPlugins(functionName, props))}
|
||||
@@ -48,6 +63,10 @@ await dbgateApi.copyStream(reader, writer);
|
||||
dbgateApi.runScript(run);
|
||||
`;
|
||||
|
||||
function envToParams(env) {
|
||||
return _.flatten(_.keys(env).map(key => [`--env.${key}`, env[key]]));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
/** @type {import('dbgate-types').OpenedRunner[]} */
|
||||
opened: [],
|
||||
@@ -95,14 +114,19 @@ module.exports = {
|
||||
const pluginNames = fs.readdirSync(pluginsdir());
|
||||
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: global['dbgateApiModulePath'] || process.argv[1],
|
||||
..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, path.join(pluginsdir(), name)])),
|
||||
},
|
||||
});
|
||||
const env = {
|
||||
DBGATE_API: global['dbgateApiModulePath'] || process.argv[1],
|
||||
..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, path.join(pluginsdir(), name)])),
|
||||
};
|
||||
const subprocess = fork(
|
||||
scriptFile,
|
||||
['--checkParent', ...process.argv.slice(3), ...(platformInfo.isSnap ? envToParams(env) : [])],
|
||||
{
|
||||
cwd: directory,
|
||||
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
||||
env: platformInfo.isSnap ? undefined : env,
|
||||
}
|
||||
);
|
||||
const pipeDispatcher = severity => data =>
|
||||
this.dispatchMessage(runid, { severity, message: data.toString().trim() });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user