architex-js 1.2.0 → 1.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "architex-js",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "main": "src/index.js",
5
5
  "exports": {
6
6
  ".": "./src/index.js",
@@ -0,0 +1,60 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+
4
+ /**
5
+ * Microkernel class to manage plugins and core functionality.
6
+ */
7
+ class Microkernel {
8
+ constructor() {
9
+ this.plugins = new Map();
10
+ this.registry = {};
11
+ }
12
+
13
+ /**
14
+ * Boot the kernel and load plugins from the specified directory.
15
+ * @param {string} pluginsPath - The path to the plugins directory.
16
+ */
17
+ async boot(pluginsPath) {
18
+ const dir = path.resolve(pluginsPath);
19
+ const files = fs.readdirSync(dir);
20
+
21
+ for (const file of files) {
22
+ if (file.endsWith('.js')) {
23
+ const PluginClass = require(path.join(dir, file));
24
+ const instance = new PluginClass();
25
+
26
+ // VALIDATION: Is it a valid plugin from our suite?
27
+ if (!(instance instanceof BasePlugin)) {
28
+ console.error(`[Kernel] Ignored: ${file} does not extend BasePlugin.`);
29
+ continue;
30
+ }
31
+
32
+ const name = instance.name || file.replace('.js', '');
33
+ this.plugins.set(name, instance);
34
+
35
+ // Execute the mandatory contract
36
+ await instance.setup(this);
37
+ }
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Allows a plugin to offer a functionality to the rest of the system
43
+ * @param {string} key
44
+ * @param {any} service
45
+ */
46
+ provideService(key, service) {
47
+ this.registry[key] = service;
48
+ }
49
+
50
+ /**
51
+ * Allows a plugin to consume a functionality of another
52
+ * @param {string} key
53
+ * @returns
54
+ */
55
+ getService(key) {
56
+ return this.registry[key];
57
+ }
58
+ }
59
+
60
+ export { Microkernel };
@@ -0,0 +1 @@
1
+ export * from "./Microkernel.js";