Skip to content

Commit

Permalink
feat: enable deployment of plugins to local Levilamina server
Browse files Browse the repository at this point in the history
  • Loading branch information
leoweyr committed Jan 25, 2025
1 parent e51a169 commit 6aeec36
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/deployment/LevilaminaPluginNotFoundError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class LevilaminaPluginNotFoundError extends Error {
public constructor(pluginName: string) {
super(`Levilamina plugin ${pluginName} does not found.`);
}
}
46 changes: 46 additions & 0 deletions src/deployment/LevilaminaServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as File from "fs";
import * as Path from "path";

import { LevilaminaPluginNotFoundError } from "./LevilaminaPluginNotFoundError";
import { PluginPackage } from "../packager/PluginPackage";


export class LevilaminaServer {
private static deleteDirectory(basePath: string): void {
if (File.existsSync(basePath)) {
File.readdirSync(basePath).forEach((file: string): void => {
const currentPath: string = Path.join(basePath, file);

if (File.lstatSync(currentPath).isDirectory()) {
LevilaminaServer.deleteDirectory(currentPath);
} else {
File.unlinkSync(currentPath);
}
});

File.rmdirSync(basePath);
}
}

private readonly pluginDirectory: string;

public constructor(path: string) {
this.pluginDirectory = Path.join(path, "plugins");
}

public removePlugin(pluginName: string): void {
const pluginPath: string = Path.join(this.pluginDirectory, pluginName);

if (File.existsSync(pluginPath)) {
LevilaminaServer.deleteDirectory(pluginPath);
} else {
throw new LevilaminaPluginNotFoundError(pluginName);
}
}

public async importPlugin(pluginPackage: PluginPackage): Promise<string> {
await pluginPackage.expand(this.pluginDirectory);

return `Plugin ${pluginPackage.getName()} has been imported to ${this.pluginDirectory}.`;
}
}

0 comments on commit 6aeec36

Please # to comment.