backend exporters/importers from plugins

This commit is contained in:
Jan Prochazka
2020-11-21 21:16:22 +01:00
parent 6ed3eaa896
commit 286cac066c
3 changed files with 47 additions and 6 deletions

View File

@@ -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;
}
}

View File

@@ -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) {