@serenityjs/plugins 0.5.0 → 0.5.1-beta-20240915195437
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +67 -80
- package/package.json +34 -34
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
9
|
var __export = (target, all) => {
|
|
9
10
|
for (var name in all)
|
|
10
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -57,6 +58,7 @@ function exists(path) {
|
|
|
57
58
|
return false;
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
__name(exists, "exists");
|
|
60
62
|
|
|
61
63
|
// src/utils/unzip.ts
|
|
62
64
|
var import_node_path = require("path");
|
|
@@ -65,6 +67,7 @@ function unzip(source, destination) {
|
|
|
65
67
|
const zip2 = new import_adm_zip.default((0, import_node_path.resolve)(source));
|
|
66
68
|
zip2.extractAllTo((0, import_node_path.resolve)(destination), true);
|
|
67
69
|
}
|
|
70
|
+
__name(unzip, "unzip");
|
|
68
71
|
|
|
69
72
|
// src/utils/zip.ts
|
|
70
73
|
var import_node_path2 = require("path");
|
|
@@ -74,38 +77,42 @@ function zip(source, destination) {
|
|
|
74
77
|
zip2.addLocalFolder((0, import_node_path2.resolve)(source));
|
|
75
78
|
zip2.writeZip((0, import_node_path2.resolve)(destination));
|
|
76
79
|
}
|
|
80
|
+
__name(zip, "zip");
|
|
77
81
|
|
|
78
82
|
// src/plugins.ts
|
|
79
|
-
var Plugins = class extends import_emitter.default {
|
|
83
|
+
var Plugins = class Plugins2 extends import_emitter.default {
|
|
84
|
+
static {
|
|
85
|
+
__name(this, "Plugins");
|
|
86
|
+
}
|
|
80
87
|
/**
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
* The logger instance.
|
|
89
|
+
*/
|
|
83
90
|
logger = new import_logger.Logger("Plugins", import_logger.LoggerColors.Blue);
|
|
84
91
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
* The path to the plugins folder.
|
|
93
|
+
*/
|
|
87
94
|
path;
|
|
88
95
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
* Whether the plugins are enabled.
|
|
97
|
+
*/
|
|
91
98
|
enabled;
|
|
92
99
|
/**
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
* A collection registry of all plugins.
|
|
101
|
+
*/
|
|
95
102
|
entries = /* @__PURE__ */ new Map();
|
|
96
103
|
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
* Constructs a new plugins instance.
|
|
105
|
+
*
|
|
106
|
+
* @param serenity - The serenity instance.
|
|
107
|
+
*/
|
|
101
108
|
constructor(path, enabled = true) {
|
|
102
109
|
super();
|
|
103
110
|
this.path = (0, import_node_path3.resolve)(import_node_process.default.cwd(), path);
|
|
104
111
|
this.enabled = enabled;
|
|
105
112
|
}
|
|
106
113
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
* Initializes all plugins.
|
|
115
|
+
*/
|
|
109
116
|
async initialize(...arguments_) {
|
|
110
117
|
if (!this.enabled) {
|
|
111
118
|
this.logger.warn("Plugins are set to be disabled.");
|
|
@@ -118,9 +125,7 @@ var Plugins = class extends import_emitter.default {
|
|
|
118
125
|
this.logger.error(`Failed to create plugins directory!`, reason);
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
|
-
const bundled = (0, import_node_fs2.readdirSync)(this.path).filter(
|
|
122
|
-
(file) => file.endsWith(".sjs")
|
|
123
|
-
);
|
|
128
|
+
const bundled = (0, import_node_fs2.readdirSync)(this.path).filter((file) => file.endsWith(".sjs"));
|
|
124
129
|
for (const file of bundled) {
|
|
125
130
|
unzip((0, import_node_path3.resolve)(this.path, file), this.path);
|
|
126
131
|
(0, import_node_fs2.rmSync)((0, import_node_path3.resolve)(this.path, file));
|
|
@@ -131,52 +136,37 @@ var Plugins = class extends import_emitter.default {
|
|
|
131
136
|
for (const directory of directories) {
|
|
132
137
|
const path = (0, import_node_path3.resolve)(this.path, directory.name);
|
|
133
138
|
if (!exists((0, import_node_path3.resolve)(path, "package.json"))) {
|
|
134
|
-
this.logger.debug(
|
|
135
|
-
`Skipping directory "${(0, import_node_path3.relative)(import_node_process.default.cwd(), path)}", as a package.json was not found.`
|
|
136
|
-
);
|
|
139
|
+
this.logger.debug(`Skipping directory "${(0, import_node_path3.relative)(import_node_process.default.cwd(), path)}", as a package.json was not found.`);
|
|
137
140
|
continue;
|
|
138
141
|
}
|
|
139
|
-
this.logger.debug(
|
|
140
|
-
|
|
141
|
-
);
|
|
142
|
-
const pak = JSON.parse(
|
|
143
|
-
(0, import_node_fs2.readFileSync)((0, import_node_path3.resolve)(path, "package.json"), "utf8")
|
|
144
|
-
);
|
|
142
|
+
this.logger.debug(`Attempting to load plugin "${(0, import_node_path3.relative)(import_node_process.default.cwd(), path)}".`);
|
|
143
|
+
const pak = JSON.parse((0, import_node_fs2.readFileSync)((0, import_node_path3.resolve)(path, "package.json"), "utf8"));
|
|
145
144
|
try {
|
|
146
|
-
this.logger.info(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
this.logger.info(`Installing package dependencies for plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r.`);
|
|
146
|
+
await (0, import_node_child_process.execSync)("npm install", {
|
|
147
|
+
stdio: "ignore",
|
|
148
|
+
cwd: path
|
|
149
|
+
});
|
|
150
150
|
} catch (reason) {
|
|
151
|
-
this.logger.error(
|
|
152
|
-
`Failed to install package dependencies for plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r!`,
|
|
153
|
-
reason
|
|
154
|
-
);
|
|
151
|
+
this.logger.error(`Failed to install package dependencies for plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r!`, reason);
|
|
155
152
|
}
|
|
156
153
|
if (exists((0, import_node_path3.resolve)(path, "tsconfig.json")) && !exists((0, import_node_path3.resolve)(path, "dist"))) {
|
|
157
|
-
this.logger.info(
|
|
158
|
-
`Compiling plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r.`
|
|
159
|
-
);
|
|
154
|
+
this.logger.info(`Compiling plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r.`);
|
|
160
155
|
try {
|
|
161
|
-
await (0, import_node_child_process.execSync)("npm run build", {
|
|
156
|
+
await (0, import_node_child_process.execSync)("npm run build", {
|
|
157
|
+
stdio: "ignore",
|
|
158
|
+
cwd: path
|
|
159
|
+
});
|
|
162
160
|
} catch (reason) {
|
|
163
|
-
this.logger.error(
|
|
164
|
-
`Failed to compile plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r!`,
|
|
165
|
-
reason
|
|
166
|
-
);
|
|
161
|
+
this.logger.error(`Failed to compile plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r!`, reason);
|
|
167
162
|
}
|
|
168
163
|
}
|
|
169
164
|
if (!exists((0, import_node_path3.resolve)(path, pak.main))) {
|
|
170
|
-
this.logger.warn(
|
|
171
|
-
`Unable to load plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r, the main entry path "\xA78${(0, import_node_path3.relative)(import_node_process.default.cwd(), (0, import_node_path3.resolve)(path, pak.main))}\xA7r" was not found in the directory.`
|
|
172
|
-
);
|
|
165
|
+
this.logger.warn(`Unable to load plugin \xA71${pak.name}\xA78@\xA71${pak.version}\xA7r, the main entry path "\xA78${(0, import_node_path3.relative)(import_node_process.default.cwd(), (0, import_node_path3.resolve)(path, pak.main))}\xA7r" was not found in the directory.`);
|
|
173
166
|
continue;
|
|
174
167
|
}
|
|
175
168
|
const module2 = require(`${(0, import_node_path3.resolve)(path, pak.main)}`);
|
|
176
|
-
const logger = new import_logger.Logger(
|
|
177
|
-
`${pak.name}@${pak.version}`,
|
|
178
|
-
import_logger.LoggerColors.Blue
|
|
179
|
-
);
|
|
169
|
+
const logger = new import_logger.Logger(`${pak.name}@${pak.version}`, import_logger.LoggerColors.Blue);
|
|
180
170
|
const plugin = {
|
|
181
171
|
package: pak,
|
|
182
172
|
module: module2,
|
|
@@ -189,17 +179,15 @@ var Plugins = class extends import_emitter.default {
|
|
|
189
179
|
await module2.onInitialize(...arguments_, plugin);
|
|
190
180
|
}
|
|
191
181
|
}
|
|
192
|
-
const plugins = [
|
|
193
|
-
(
|
|
194
|
-
);
|
|
182
|
+
const plugins = [
|
|
183
|
+
...this.entries.values()
|
|
184
|
+
].map((plugin) => `\xA71${plugin.package.name}\xA78@\xA71${plugin.package.version}\xA7r`);
|
|
195
185
|
const s = plugins.length > 1 ? "s" : "";
|
|
196
|
-
this.logger.success(
|
|
197
|
-
`Initializing \xA7c${plugins.length}\xA7r plugin${s}: ${plugins.join(", ")}\xA7r`
|
|
198
|
-
);
|
|
186
|
+
this.logger.success(`Initializing \xA7c${plugins.length}\xA7r plugin${s}: ${plugins.join(", ")}\xA7r`);
|
|
199
187
|
}
|
|
200
188
|
/**
|
|
201
|
-
|
|
202
|
-
|
|
189
|
+
* Starts all plugins.
|
|
190
|
+
*/
|
|
203
191
|
async start(...arguments_) {
|
|
204
192
|
for await (const plugin of this.entries.values()) {
|
|
205
193
|
if (plugin.module.onStartup) {
|
|
@@ -208,8 +196,8 @@ var Plugins = class extends import_emitter.default {
|
|
|
208
196
|
}
|
|
209
197
|
}
|
|
210
198
|
/**
|
|
211
|
-
|
|
212
|
-
|
|
199
|
+
* Stops all plugins.
|
|
200
|
+
*/
|
|
213
201
|
async stop(...arguments_) {
|
|
214
202
|
for await (const plugin of this.entries.values()) {
|
|
215
203
|
if (plugin.module.onShutdown) {
|
|
@@ -218,10 +206,10 @@ var Plugins = class extends import_emitter.default {
|
|
|
218
206
|
}
|
|
219
207
|
}
|
|
220
208
|
/**
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
209
|
+
* Reloads a plugin by its name.
|
|
210
|
+
* @param name - The name of the plugin.
|
|
211
|
+
* @param arguments_ - The arguments to pass to the plugin.
|
|
212
|
+
*/
|
|
225
213
|
async reload(name, ...arguments_) {
|
|
226
214
|
const plugin = this.entries.get(name);
|
|
227
215
|
if (!plugin) throw new Error(`Plugin ${name} not found!`);
|
|
@@ -232,10 +220,7 @@ var Plugins = class extends import_emitter.default {
|
|
|
232
220
|
this.entries.delete(name);
|
|
233
221
|
delete require.cache[require.resolve(path)];
|
|
234
222
|
const module2 = require(`${(0, import_node_path3.resolve)(path, pak.main)}`);
|
|
235
|
-
const logger = new import_logger.Logger(
|
|
236
|
-
`${pak.name}@${pak.version}.r`,
|
|
237
|
-
import_logger.LoggerColors.Blue
|
|
238
|
-
);
|
|
223
|
+
const logger = new import_logger.Logger(`${pak.name}@${pak.version}.r`, import_logger.LoggerColors.Blue);
|
|
239
224
|
const reloaded = {
|
|
240
225
|
package: pak,
|
|
241
226
|
module: module2,
|
|
@@ -253,25 +238,27 @@ var Plugins = class extends import_emitter.default {
|
|
|
253
238
|
}
|
|
254
239
|
}
|
|
255
240
|
/**
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
241
|
+
* Gets all the currently loaded plugins.
|
|
242
|
+
* @returns All the currently loaded plugins.
|
|
243
|
+
*/
|
|
259
244
|
getAll() {
|
|
260
|
-
return [
|
|
245
|
+
return [
|
|
246
|
+
...this.entries.values()
|
|
247
|
+
];
|
|
261
248
|
}
|
|
262
249
|
/**
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
250
|
+
* Gets a plugin by its name.
|
|
251
|
+
* @param name - The name of the plugin.
|
|
252
|
+
* @returns The plugin or undefined if not found.
|
|
253
|
+
*/
|
|
267
254
|
get(name) {
|
|
268
255
|
return this.entries.get(name);
|
|
269
256
|
}
|
|
270
257
|
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
258
|
+
* Imports a plugin module.
|
|
259
|
+
* @param name - The name of the plugin.
|
|
260
|
+
* @returns The plugin module.
|
|
261
|
+
*/
|
|
275
262
|
import(name) {
|
|
276
263
|
const plugin = this.entries.get(name);
|
|
277
264
|
if (!plugin) {
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
"name": "@serenityjs/plugins",
|
|
3
|
+
"version": "0.5.1-beta-20240915195437",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"repository": "https://github.com/SerenityJS/serenity",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/**"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup",
|
|
12
|
+
"watch": "tsup --watch",
|
|
13
|
+
"lint": "eslint src/",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"test": "jest"
|
|
16
|
+
},
|
|
17
|
+
"jest": {
|
|
18
|
+
"preset": "@serenityjs/jest-presets/jest/node"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@serenityjs/eslint-config": "workspace:*",
|
|
22
|
+
"@serenityjs/jest-presets": "workspace:*",
|
|
23
|
+
"@serenityjs/typescript-config": "workspace:*",
|
|
24
|
+
"@types/adm-zip": "^0",
|
|
25
|
+
"@types/jest": "^29.5.12",
|
|
26
|
+
"@types/node": "^20.11.24",
|
|
27
|
+
"jest": "^29.7.0",
|
|
28
|
+
"tsup": "^8.0.2",
|
|
29
|
+
"typescript": "^5.4.2"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@serenityjs/emitter": "workspace:*",
|
|
33
|
+
"@serenityjs/logger": "workspace:*",
|
|
34
|
+
"adm-zip": "^0.5.16"
|
|
35
|
+
}
|
|
36
36
|
}
|