Skip to content

Commit

Permalink
Added wireframe for plugin configuration builder
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Oct 3, 2023
1 parent f0b8eee commit 686323f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/services/pluginsService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ import project from 'main/project';
import { LogLevel } from 'shared/types';
import { sanitizePath, tryGetAsync } from 'shared/utils';

import PluginBuilder from './pluginBuilder';

import IService from '../IService';

class PluginsService implements IService {
#messageBroker: ProjectMessageBroker;

#pluginsFolder: string;

#plugins: any;

constructor(pluginsFolder: string, messageBroker: ProjectMessageBroker) {
this.#messageBroker = messageBroker;
this.#pluginsFolder = sanitizePath(pluginsFolder);
}

async init(): Promise<boolean> {
this.#plugins = {};
try {
await this.loadPlugins();
console.log(this.#plugins);

Check warning on line 29 in src/main/services/pluginsService/index.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest)

Unexpected console statement

Check warning on line 29 in src/main/services/pluginsService/index.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest)

Unexpected console statement

Check warning on line 29 in src/main/services/pluginsService/index.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Unexpected console statement
return true;
} catch (error) {
return false;
Expand Down Expand Up @@ -87,13 +93,16 @@ class PluginsService implements IService {
return `Required ${path}`;
},
logger: project.logger,
builder: new PluginBuilder(),
};
const script = await readFile(scriptPath, 'utf8');

// execute script in private context
try {
// eslint-disable-next-line no-new-func
new Function(`with(this) { ${script} }`).call(context);
const plugin = context.builder.build();
this.#plugins[pluginName] = plugin;
} catch (error) {
project.logger.log(LogLevel.error, ['plugin', pluginName], error);
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/services/pluginsService/pluginBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
type ConnectionInfo = {
in: number;
out: number;
};

type NodeInfo = {
type: string;
connection: ConnectionInfo;
};

export default class PluginBuilder {
#flowView: boolean = false;

#nodes: NodeInfo | undefined = undefined;

setFlowView(value: boolean) {
this.#flowView = value;
return this;
}

setNodes(nodes: NodeInfo) {
this.#nodes = nodes;
return this;
}

build() {
const flowView = this.#flowView;
const nodes = this.#nodes;
return { flowView, nodes };
}
}

0 comments on commit 686323f

Please sign in to comment.