mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
plugin minimal versions
This commit is contained in:
parent
011ca0a5c4
commit
946ec7eb32
@ -23,6 +23,7 @@
|
|||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"bufferutil": "^4.0.1",
|
"bufferutil": "^4.0.1",
|
||||||
"byline": "^5.0.0",
|
"byline": "^5.0.0",
|
||||||
|
"compare-versions": "^3.6.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cross-env": "^6.0.3",
|
"cross-env": "^6.0.3",
|
||||||
"dbgate-sqltree": "^1.0.0",
|
"dbgate-sqltree": "^1.0.0",
|
||||||
|
@ -4,6 +4,7 @@ const path = require('path');
|
|||||||
const { extractPackageName } = require('dbgate-tools');
|
const { extractPackageName } = require('dbgate-tools');
|
||||||
const { pluginsdir, datadir } = require('../utility/directories');
|
const { pluginsdir, datadir } = require('../utility/directories');
|
||||||
const socket = require('../utility/socket');
|
const socket = require('../utility/socket');
|
||||||
|
const compareVersions = require('compare-versions');
|
||||||
const requirePlugin = require('../shell/requirePlugin');
|
const requirePlugin = require('../shell/requirePlugin');
|
||||||
const downloadPackage = require('../utility/downloadPackage');
|
const downloadPackage = require('../utility/downloadPackage');
|
||||||
const hasPermission = require('../utility/hasPermission');
|
const hasPermission = require('../utility/hasPermission');
|
||||||
@ -26,13 +27,13 @@ const hasPermission = require('../utility/hasPermission');
|
|||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const preinstallPlugins = [
|
const preinstallPluginMinimalVersions = {
|
||||||
'dbgate-plugin-mssql',
|
'dbgate-plugin-mssql': '1.0.8',
|
||||||
'dbgate-plugin-mysql',
|
'dbgate-plugin-mysql': '1.0.2',
|
||||||
'dbgate-plugin-postgres',
|
'dbgate-plugin-postgres': '1.0.2',
|
||||||
'dbgate-plugin-csv',
|
'dbgate-plugin-csv': '1.0.8',
|
||||||
'dbgate-plugin-excel',
|
'dbgate-plugin-excel': '1.0.6',
|
||||||
];
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
script_meta: 'get',
|
script_meta: 'get',
|
||||||
@ -136,8 +137,11 @@ module.exports = {
|
|||||||
async upgrade({ packageName }) {
|
async upgrade({ packageName }) {
|
||||||
if (!hasPermission(`plugins/install`)) return;
|
if (!hasPermission(`plugins/install`)) return;
|
||||||
const dir = path.join(pluginsdir(), packageName);
|
const dir = path.join(pluginsdir(), packageName);
|
||||||
|
if (await fs.exists(dir)) {
|
||||||
await fs.rmdir(dir, { recursive: true });
|
await fs.rmdir(dir, { recursive: true });
|
||||||
await downloadPackage(packageName, dir);
|
await downloadPackage(packageName, dir);
|
||||||
|
}
|
||||||
|
|
||||||
socket.emitChanged(`installed-plugins-changed`);
|
socket.emitChanged(`installed-plugins-changed`);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -164,9 +168,21 @@ module.exports = {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.removedPlugins = [];
|
this.removedPlugins = [];
|
||||||
}
|
}
|
||||||
for (const packageName of preinstallPlugins) {
|
for (const packageName of Object.keys(preinstallPluginMinimalVersions)) {
|
||||||
if (this.removedPlugins.includes(packageName)) continue;
|
if (this.removedPlugins.includes(packageName)) continue;
|
||||||
if (installed.find((x) => x.name == packageName)) continue;
|
const installedVersion = installed.find((x) => x.name == packageName);
|
||||||
|
if (installedVersion) {
|
||||||
|
const requiredVersion = preinstallPluginMinimalVersions[packageName];
|
||||||
|
if (compareVersions(installedVersion.version, requiredVersion) < 0) {
|
||||||
|
console.log(
|
||||||
|
`Upgrading preinstalled plugin, found ${installedVersion.version}, required version ${requiredVersion}`,
|
||||||
|
packageName
|
||||||
|
);
|
||||||
|
await this.upgrade({ packageName });
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
console.log('Preinstalling plugin', packageName);
|
console.log('Preinstalling plugin', packageName);
|
||||||
await this.install({ packageName });
|
await this.install({ packageName });
|
||||||
|
Loading…
Reference in New Issue
Block a user