This commit is contained in:
Jan Prochazka 2021-04-17 17:31:32 +02:00
parent ab4febf938
commit 516d007c22
9 changed files with 20 additions and 21 deletions

View File

@ -5,7 +5,7 @@ const uuidv1 = require('uuid/v1');
const byline = require('byline'); const byline = require('byline');
const socket = require('../utility/socket'); const socket = require('../utility/socket');
const { fork } = require('child_process'); const { fork } = require('child_process');
const { rundir, uploadsdir, pluginsdir, getPluginPath, packagedPluginList } = require('../utility/directories'); const { rundir, uploadsdir, pluginsdir, getPluginBackendPath, packagedPluginList } = require('../utility/directories');
const { extractShellApiPlugins, extractShellApiFunctionName } = require('dbgate-tools'); const { extractShellApiPlugins, extractShellApiFunctionName } = require('dbgate-tools');
const { handleProcessCommunication } = require('../utility/processComm'); const { handleProcessCommunication } = require('../utility/processComm');
@ -101,7 +101,7 @@ module.exports = {
env: { env: {
...process.env, ...process.env,
DBGATE_API: global['dbgateApiModulePath'] || process.argv[1], DBGATE_API: global['dbgateApiModulePath'] || process.argv[1],
..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginPath(name)])), ..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginBackendPath(name)])),
}, },
}); });
const pipeDispatcher = severity => data => const pipeDispatcher = severity => data =>

View File

@ -1,6 +1,6 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const { pluginsdir, packagedPluginsDir } = require('../utility/directories'); const { pluginsdir, packagedPluginsDir, getPluginBackendPath } = require('../utility/directories');
const nativeModules = require('../nativeModules'); const nativeModules = require('../nativeModules');
const platformInfo = require('../utility/platformInfo'); const platformInfo = require('../utility/platformInfo');
@ -10,26 +10,13 @@ const dbgateEnv = {
dbgateApi: null, dbgateApi: null,
nativeModules, nativeModules,
}; };
function getModulePath(packageName) {
const packagedModulePath = platformInfo.isDevMode
? path.join(packagedPluginsDir(), packageName, 'src', 'backend', 'index.js')
: path.join(packagedPluginsDir(), packageName, 'dist', 'backend.js');
if (fs.existsSync(packagedModulePath)) {
return packagedModulePath;
}
return path.join(pluginsdir(), packageName, 'dist', 'backend.js');
}
function requirePlugin(packageName, requiredPlugin = null) { function requirePlugin(packageName, requiredPlugin = null) {
if (!packageName) throw new Error('Missing packageName in plugin'); if (!packageName) throw new Error('Missing packageName in plugin');
if (loadedPlugins[packageName]) return loadedPlugins[packageName]; if (loadedPlugins[packageName]) return loadedPlugins[packageName];
if (requiredPlugin == null) { if (requiredPlugin == null) {
let module; let module;
const modulePath = getModulePath(packageName); const modulePath = getPluginBackendPath(packageName);
console.log(`Loading module ${packageName} from ${modulePath}`); console.log(`Loading module ${packageName} from ${modulePath}`);
try { try {
// @ts-ignore // @ts-ignore

View File

@ -60,9 +60,15 @@ function packagedPluginsDir() {
const packagedPluginList = const packagedPluginList =
packagedPluginsDir() != null ? fs.readdirSync(packagedPluginsDir()).filter(x => x.startsWith('dbgate-plugin-')) : []; packagedPluginsDir() != null ? fs.readdirSync(packagedPluginsDir()).filter(x => x.startsWith('dbgate-plugin-')) : [];
function getPluginPath(packageName) { function getPluginBackendPath(packageName) {
if (packagedPluginList.includes(packageName)) return path.join(packagedPluginsDir(), packageName); if (packagedPluginList.includes(packageName)) {
return path.join(pluginsdir(), packageName); if (platformInfo.isDevMode) {
return path.join(packagedPluginsDir(), packageName, 'src', 'backend', 'index.js');
}
return path.join(packagedPluginsDir(), packageName, 'dist', 'backend.js');
}
return path.join(pluginsdir(), packageName, 'dist', 'backend.js');
} }
module.exports = { module.exports = {
@ -76,5 +82,5 @@ module.exports = {
filesdir, filesdir,
packagedPluginsDir, packagedPluginsDir,
packagedPluginList, packagedPluginList,
getPluginPath, getPluginBackendPath,
}; };

View File

@ -18,6 +18,7 @@
"dbgateplugin" "dbgateplugin"
], ],
"files": [ "files": [
"src",
"dist", "dist",
"icon.svg" "icon.svg"
], ],

View File

@ -19,6 +19,7 @@
], ],
"files": [ "files": [
"dist", "dist",
"src",
"icon.svg" "icon.svg"
], ],
"scripts": { "scripts": {

View File

@ -18,6 +18,7 @@
], ],
"files": [ "files": [
"dist", "dist",
"src",
"icon.svg" "icon.svg"
], ],
"scripts": { "scripts": {

View File

@ -18,6 +18,7 @@
], ],
"files": [ "files": [
"dist", "dist",
"src",
"icon.svg" "icon.svg"
], ],
"scripts": { "scripts": {

View File

@ -18,6 +18,7 @@
], ],
"files": [ "files": [
"dist", "dist",
"src",
"icon.svg" "icon.svg"
], ],
"scripts": { "scripts": {

View File

@ -17,6 +17,7 @@
], ],
"files": [ "files": [
"dist", "dist",
"src",
"icon.svg" "icon.svg"
], ],
"scripts": { "scripts": {