Skip to content

Commit 6aeec36

Browse files
committed
feat: enable deployment of plugins to local Levilamina server
1 parent e51a169 commit 6aeec36

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export class LevilaminaPluginNotFoundError extends Error {
2+
public constructor(pluginName: string) {
3+
super(`Levilamina plugin ${pluginName} does not found.`);
4+
}
5+
}

src/deployment/LevilaminaServer.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as File from "fs";
2+
import * as Path from "path";
3+
4+
import { LevilaminaPluginNotFoundError } from "./LevilaminaPluginNotFoundError";
5+
import { PluginPackage } from "../packager/PluginPackage";
6+
7+
8+
export class LevilaminaServer {
9+
private static deleteDirectory(basePath: string): void {
10+
if (File.existsSync(basePath)) {
11+
File.readdirSync(basePath).forEach((file: string): void => {
12+
const currentPath: string = Path.join(basePath, file);
13+
14+
if (File.lstatSync(currentPath).isDirectory()) {
15+
LevilaminaServer.deleteDirectory(currentPath);
16+
} else {
17+
File.unlinkSync(currentPath);
18+
}
19+
});
20+
21+
File.rmdirSync(basePath);
22+
}
23+
}
24+
25+
private readonly pluginDirectory: string;
26+
27+
public constructor(path: string) {
28+
this.pluginDirectory = Path.join(path, "plugins");
29+
}
30+
31+
public removePlugin(pluginName: string): void {
32+
const pluginPath: string = Path.join(this.pluginDirectory, pluginName);
33+
34+
if (File.existsSync(pluginPath)) {
35+
LevilaminaServer.deleteDirectory(pluginPath);
36+
} else {
37+
throw new LevilaminaPluginNotFoundError(pluginName);
38+
}
39+
}
40+
41+
public async importPlugin(pluginPackage: PluginPackage): Promise<string> {
42+
await pluginPackage.expand(this.pluginDirectory);
43+
44+
return `Plugin ${pluginPackage.getName()} has been imported to ${this.pluginDirectory}.`;
45+
}
46+
}

0 commit comments

Comments
 (0)