mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 11:16:01 +00:00
backend exporters/importers from plugins
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export default class ScriptWriter {
|
||||
constructor() {
|
||||
this.s = '';
|
||||
this.packageNames = [];
|
||||
this.engines = [];
|
||||
this.varCount = 0;
|
||||
}
|
||||
|
||||
@@ -15,7 +19,21 @@ export default class ScriptWriter {
|
||||
}
|
||||
|
||||
assign(variableName, functionName, props) {
|
||||
this.put(`const ${variableName} = await dbgateApi.${functionName}(${JSON.stringify(props)});`);
|
||||
const nsMatch = functionName.match(/^([^@]+)@([^@]+)/);
|
||||
if (nsMatch) {
|
||||
const packageName = nsMatch[2];
|
||||
if (!this.packageNames.includes(packageName)) {
|
||||
this.packageNames.push(packageName);
|
||||
}
|
||||
this.put(
|
||||
`const ${variableName} = await ${_.camelCase(packageName)}.shellApi.${nsMatch[1]}(${JSON.stringify(props)});`
|
||||
);
|
||||
} else {
|
||||
this.put(`const ${variableName} = await dbgateApi.${functionName}(${JSON.stringify(props)});`);
|
||||
}
|
||||
if (props && props.connection && props.connection.engine && !this.engines.includes(props.connection.engine)) {
|
||||
this.engines.push(props.connection.engine);
|
||||
}
|
||||
}
|
||||
|
||||
copyStream(sourceVar, targetVar) {
|
||||
@@ -25,4 +43,17 @@ export default class ScriptWriter {
|
||||
comment(s) {
|
||||
this.put(`// ${s}`);
|
||||
}
|
||||
|
||||
getScript(extensions) {
|
||||
// if (this.packageNames.length > 0) {
|
||||
// this.comment('@packages');
|
||||
// this.comment(JSON.stringify(this.packageNames));
|
||||
// }
|
||||
// if (this.engines.length > 0) {
|
||||
// this.comment('@engines');
|
||||
// this.comment(JSON.stringify(this.engines));
|
||||
// }
|
||||
const packageNames = this.packageNames;
|
||||
return packageNames.map((packageName) => `// @require ${packageName}\n`).join('') + '\n' + this.s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ export default async function createImpExpScript(extensions, values, addEditorIn
|
||||
script.comment('@ImportExportConfigurator');
|
||||
script.comment(JSON.stringify(values));
|
||||
}
|
||||
return script.s;
|
||||
return script.getScript(extensions);
|
||||
}
|
||||
|
||||
export function getActionOptions(extensions, source, values, targetDbinfo) {
|
||||
|
||||
Reference in New Issue
Block a user