@axium/core 0.12.0 → 0.12.1
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/node/plugins.js +2 -2
- package/dist/plugins.d.ts +16 -11
- package/dist/plugins.js +28 -16
- package/package.json +1 -1
package/dist/node/plugins.js
CHANGED
|
@@ -53,8 +53,8 @@ export async function loadPlugin(mode, specifier, _loadedBy, safeMode = false) {
|
|
|
53
53
|
if (!plugin[mode])
|
|
54
54
|
throw `Plugin does not support running ${mode}-side`;
|
|
55
55
|
if (!safeMode) {
|
|
56
|
-
if (plugin.cli)
|
|
57
|
-
await import(resolve(plugin.dirname, plugin.cli));
|
|
56
|
+
if (plugin[mode].cli)
|
|
57
|
+
await import(resolve(plugin.dirname, plugin[mode].cli));
|
|
58
58
|
if (mode == 'client') {
|
|
59
59
|
if (plugin.client.hooks)
|
|
60
60
|
Object.assign(plugin, { _client: await import(resolve(plugin.dirname, plugin.client.hooks)) });
|
package/dist/plugins.d.ts
CHANGED
|
@@ -12,28 +12,32 @@ export declare const Plugin: z.ZodObject<{
|
|
|
12
12
|
client: z.ZodOptional<z.ZodObject<{
|
|
13
13
|
cli: z.ZodOptional<z.ZodString>;
|
|
14
14
|
hooks: z.ZodOptional<z.ZodString>;
|
|
15
|
+
integrations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
15
16
|
}, z.core.$strip>>;
|
|
16
17
|
server: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
cli: z.ZodOptional<z.ZodString>;
|
|
17
19
|
hooks: z.ZodOptional<z.ZodString>;
|
|
20
|
+
integrations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
18
21
|
http_handler: z.ZodOptional<z.ZodString>;
|
|
19
22
|
routes: z.ZodOptional<z.ZodString>;
|
|
20
|
-
cli: z.ZodOptional<z.ZodString>;
|
|
21
23
|
db: z.ZodOptional<z.ZodString>;
|
|
22
24
|
}, z.core.$strip>>;
|
|
23
25
|
}, z.core.$loose>;
|
|
24
26
|
export type Plugin = z.infer<typeof Plugin>;
|
|
25
|
-
export interface
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
export interface PluginInfo {
|
|
28
|
+
path: string;
|
|
29
|
+
dirname: string;
|
|
30
|
+
specifier: string;
|
|
31
|
+
_loadedBy: string;
|
|
32
|
+
cli?: string;
|
|
31
33
|
/** @internal */
|
|
32
|
-
|
|
34
|
+
_hooks?: ServerHooks;
|
|
33
35
|
/** @internal */
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
_client?: ClientHooks;
|
|
37
|
+
isServer: boolean;
|
|
38
|
+
_db?: any;
|
|
39
|
+
}
|
|
40
|
+
export interface PluginInternal extends Plugin, Readonly<PluginInfo> {
|
|
37
41
|
}
|
|
38
42
|
export declare const plugins: Map<string, PluginInternal>;
|
|
39
43
|
/**
|
|
@@ -60,4 +64,5 @@ export interface ServerHooks {
|
|
|
60
64
|
export interface ClientHooks {
|
|
61
65
|
run(): void | Promise<void>;
|
|
62
66
|
}
|
|
67
|
+
export declare function runIntegrations(): Promise<void>;
|
|
63
68
|
export {};
|
package/dist/plugins.js
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
import { zAsyncFunction } from './schemas.js';
|
|
3
3
|
import { App } from './apps.js';
|
|
4
|
+
import { debug, warn } from './io.js';
|
|
5
|
+
const PluginCommon = z.object({
|
|
6
|
+
/** CLI mixin path */
|
|
7
|
+
cli: z.string().optional(),
|
|
8
|
+
/** The path to the hooks script */
|
|
9
|
+
hooks: z.string().optional(),
|
|
10
|
+
/** A map of plugin names to paths */
|
|
11
|
+
integrations: z.record(z.string(), z.string()).optional(),
|
|
12
|
+
});
|
|
4
13
|
export const Plugin = z.looseObject({
|
|
5
14
|
name: z.string(),
|
|
6
15
|
version: z.string(),
|
|
7
16
|
description: z.string().optional(),
|
|
8
17
|
apps: z.array(App).optional(),
|
|
9
|
-
client:
|
|
10
|
-
|
|
11
|
-
/** CLI mixin path */
|
|
12
|
-
cli: z.string().optional(),
|
|
13
|
-
/** The path to the hooks script */
|
|
14
|
-
hooks: z.string().optional(),
|
|
15
|
-
})
|
|
16
|
-
.optional(),
|
|
17
|
-
server: z
|
|
18
|
-
.object({
|
|
19
|
-
/** The path to the hooks script */
|
|
20
|
-
hooks: z.string().optional(),
|
|
18
|
+
client: PluginCommon.extend({}).optional(),
|
|
19
|
+
server: PluginCommon.extend({
|
|
21
20
|
http_handler: z.string().optional(),
|
|
22
21
|
/** The path to the HTTP handler used by the server */
|
|
23
22
|
routes: z.string().optional(),
|
|
24
|
-
/** CLI mixin path */
|
|
25
|
-
cli: z.string().optional(),
|
|
26
23
|
db: z.string().optional(),
|
|
27
|
-
})
|
|
28
|
-
.optional(),
|
|
24
|
+
}).optional(),
|
|
29
25
|
});
|
|
30
26
|
export const plugins = new Map();
|
|
31
27
|
/**
|
|
@@ -43,3 +39,19 @@ export const PluginServerHooks = z.object({
|
|
|
43
39
|
remove: fn.optional(),
|
|
44
40
|
clean: fn.optional(),
|
|
45
41
|
});
|
|
42
|
+
export async function runIntegrations() {
|
|
43
|
+
for (const [pluginName, plugin] of plugins) {
|
|
44
|
+
const { integrations } = plugin[plugin.isServer ? 'server' : 'client'];
|
|
45
|
+
if (!integrations)
|
|
46
|
+
continue;
|
|
47
|
+
for (const [name, path] of Object.entries(integrations)) {
|
|
48
|
+
if (!plugins.has(name))
|
|
49
|
+
continue;
|
|
50
|
+
debug(`Running ${pluginName} integration with ${name}`);
|
|
51
|
+
await import(path).catch(e => {
|
|
52
|
+
const text = e instanceof Error ? e.stack : String(e);
|
|
53
|
+
warn(`Failed to load ${pluginName} integration with ${name}:\n\t${text}`);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|