@geekity/cms 0.24.0 → 0.26.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/README.md +96 -160
- package/admin/pages/documents/editor.njk +48 -0
- package/admin/pages/federation/settings.njk +1 -59
- package/admin/pages/plugins/installed.njk +113 -0
- package/admin/pages/plugins/screen.njk +129 -0
- package/admin/static/admin.css +144 -4
- package/admin/static/editor-actions.js +202 -0
- package/dist/admin/accounts.d.ts +18 -39
- package/dist/admin/accounts.d.ts.map +1 -1
- package/dist/admin/accounts.js +19 -48
- package/dist/admin/accounts.js.map +1 -1
- package/dist/admin/documents.d.ts +5 -0
- package/dist/admin/documents.d.ts.map +1 -1
- package/dist/admin/documents.js +17 -8
- package/dist/admin/documents.js.map +1 -1
- package/dist/admin/editor-actions.d.ts +35 -0
- package/dist/admin/editor-actions.d.ts.map +1 -0
- package/dist/admin/editor-actions.js +187 -0
- package/dist/admin/editor-actions.js.map +1 -0
- package/dist/admin/federation.d.ts +4 -5
- package/dist/admin/federation.d.ts.map +1 -1
- package/dist/admin/federation.js +4 -5
- package/dist/admin/federation.js.map +1 -1
- package/dist/admin/index.d.ts +1 -1
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/menu.d.ts +1 -1
- package/dist/admin/menu.d.ts.map +1 -1
- package/dist/admin/menu.js +10 -3
- package/dist/admin/menu.js.map +1 -1
- package/dist/admin/plugins.d.ts +24 -0
- package/dist/admin/plugins.d.ts.map +1 -0
- package/dist/admin/plugins.js +312 -0
- package/dist/admin/plugins.js.map +1 -0
- package/dist/admin/routes.d.ts.map +1 -1
- package/dist/admin/routes.js +5 -1
- package/dist/admin/routes.js.map +1 -1
- package/dist/admin/settings-federation.d.ts +0 -25
- package/dist/admin/settings-federation.d.ts.map +1 -1
- package/dist/admin/settings-federation.js +1 -54
- package/dist/admin/settings-federation.js.map +1 -1
- package/dist/admin/settings.d.ts +2 -14
- package/dist/admin/settings.d.ts.map +1 -1
- package/dist/admin/settings.js +1 -21
- package/dist/admin/settings.js.map +1 -1
- package/dist/admin/store.d.ts +8 -1
- package/dist/admin/store.d.ts.map +1 -1
- package/dist/admin/store.js +7 -3
- package/dist/admin/store.js.map +1 -1
- package/dist/admin/templates.d.ts +2 -0
- package/dist/admin/templates.d.ts.map +1 -1
- package/dist/admin/templates.js +2 -0
- package/dist/admin/templates.js.map +1 -1
- package/dist/cli.d.ts +2 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +278 -212
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +20 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -0
- package/dist/config.js.map +1 -1
- package/dist/content/store.d.ts +6 -0
- package/dist/content/store.d.ts.map +1 -1
- package/dist/content/store.js +3 -0
- package/dist/content/store.js.map +1 -1
- package/dist/drain.d.ts +28 -0
- package/dist/drain.d.ts.map +1 -0
- package/dist/drain.js +106 -0
- package/dist/drain.js.map +1 -0
- package/dist/env.d.ts +11 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/federation/federation.d.ts +4 -2
- package/dist/federation/federation.d.ts.map +1 -1
- package/dist/federation/federation.js +16 -21
- package/dist/federation/federation.js.map +1 -1
- package/dist/federation/inbox.d.ts +23 -3
- package/dist/federation/inbox.d.ts.map +1 -1
- package/dist/federation/inbox.js +63 -1
- package/dist/federation/inbox.js.map +1 -1
- package/dist/federation/index.d.ts +0 -4
- package/dist/federation/index.d.ts.map +1 -1
- package/dist/federation/index.js +0 -2
- package/dist/federation/index.js.map +1 -1
- package/dist/federation/mount.d.ts +6 -12
- package/dist/federation/mount.d.ts.map +1 -1
- package/dist/federation/mount.js +3 -50
- package/dist/federation/mount.js.map +1 -1
- package/dist/federation/queue.d.ts +22 -0
- package/dist/federation/queue.d.ts.map +1 -0
- package/dist/federation/queue.js +58 -0
- package/dist/federation/queue.js.map +1 -0
- package/dist/files/atomic.d.ts +13 -0
- package/dist/files/atomic.d.ts.map +1 -1
- package/dist/files/atomic.js +45 -0
- package/dist/files/atomic.js.map +1 -1
- package/dist/index.d.ts +30 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +156 -79
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +524 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +23 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/enabled.d.ts +23 -0
- package/dist/plugins/enabled.d.ts.map +1 -0
- package/dist/plugins/enabled.js +49 -0
- package/dist/plugins/enabled.js.map +1 -0
- package/dist/plugins/federation.d.ts +26 -0
- package/dist/plugins/federation.d.ts.map +1 -0
- package/dist/plugins/federation.js +114 -0
- package/dist/plugins/federation.js.map +1 -0
- package/dist/plugins/fetch.d.ts +15 -0
- package/dist/plugins/fetch.d.ts.map +1 -0
- package/dist/plugins/fetch.js +33 -0
- package/dist/plugins/fetch.js.map +1 -0
- package/dist/plugins/folder.d.ts +50 -0
- package/dist/plugins/folder.d.ts.map +1 -0
- package/dist/plugins/folder.js +171 -0
- package/dist/plugins/folder.js.map +1 -0
- package/dist/plugins/install.d.ts +45 -0
- package/dist/plugins/install.d.ts.map +1 -0
- package/dist/plugins/install.js +275 -0
- package/dist/plugins/install.js.map +1 -0
- package/dist/plugins/mount.d.ts +17 -0
- package/dist/plugins/mount.d.ts.map +1 -0
- package/dist/plugins/mount.js +44 -0
- package/dist/plugins/mount.js.map +1 -0
- package/dist/plugins/registry.d.ts +110 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +447 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/settings.d.ts +64 -0
- package/dist/plugins/settings.d.ts.map +1 -0
- package/dist/plugins/settings.js +219 -0
- package/dist/plugins/settings.js.map +1 -0
- package/dist/plugins/site.d.ts +17 -0
- package/dist/plugins/site.d.ts.map +1 -0
- package/dist/plugins/site.js +67 -0
- package/dist/plugins/site.js.map +1 -0
- package/dist/supervisor/primary.d.ts +47 -0
- package/dist/supervisor/primary.d.ts.map +1 -0
- package/dist/supervisor/primary.js +208 -0
- package/dist/supervisor/primary.js.map +1 -0
- package/dist/supervisor/protocol.d.ts +37 -0
- package/dist/supervisor/protocol.d.ts.map +1 -0
- package/dist/supervisor/protocol.js +29 -0
- package/dist/supervisor/protocol.js.map +1 -0
- package/dist/supervisor/supervision.d.ts +25 -0
- package/dist/supervisor/supervision.d.ts.map +1 -0
- package/dist/supervisor/supervision.js +7 -0
- package/dist/supervisor/supervision.js.map +1 -0
- package/dist/supervisor/worker.d.ts +29 -0
- package/dist/supervisor/worker.d.ts.map +1 -0
- package/dist/supervisor/worker.js +97 -0
- package/dist/supervisor/worker.js.map +1 -0
- package/dist/web/maintenance.d.ts +2 -2
- package/dist/web/maintenance.js +2 -2
- package/dist/web/negotiate.d.ts +4 -3
- package/dist/web/negotiate.d.ts.map +1 -1
- package/dist/web/negotiate.js +4 -3
- package/dist/web/negotiate.js.map +1 -1
- package/dist/web/routes.d.ts.map +1 -1
- package/dist/web/routes.js +33 -14
- package/dist/web/routes.js.map +1 -1
- package/package.json +10 -1
- package/dist/comments/conversation.d.ts +0 -29
- package/dist/comments/conversation.d.ts.map +0 -1
- package/dist/comments/conversation.js +0 -60
- package/dist/comments/conversation.js.map +0 -1
- package/dist/federation/import-wordpress.d.ts +0 -128
- package/dist/federation/import-wordpress.d.ts.map +0 -1
- package/dist/federation/import-wordpress.js +0 -426
- package/dist/federation/import-wordpress.js.map +0 -1
- package/dist/federation/wordpress.d.ts +0 -131
- package/dist/federation/wordpress.d.ts.map +0 -1
- package/dist/federation/wordpress.js +0 -342
- package/dist/federation/wordpress.js.map +0 -1
- package/dist/web/comments.d.ts +0 -60
- package/dist/web/comments.d.ts.map +0 -1
- package/dist/web/comments.js +0 -207
- package/dist/web/comments.js.map +0 -1
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@geekity/cms/plugin`: the whole of what a plugin may import from core
|
|
3
|
+
* (decision-33). Types, the host API version and {@link definePlugin}, which is
|
|
4
|
+
* an identity function so a bundled plugin needs no runtime import of core.
|
|
5
|
+
*
|
|
6
|
+
* Removing or reshaping anything here is a breaking change to `@geekity/cms`
|
|
7
|
+
* (decision-6), and bumps {@link HOST_API_VERSION}.
|
|
8
|
+
*/
|
|
9
|
+
import type { webcrypto } from 'node:crypto';
|
|
10
|
+
import type { KvStore } from '@fedify/fedify';
|
|
11
|
+
/**
|
|
12
|
+
* The version of the host API this core provides. A plugin names the version
|
|
13
|
+
* it targets in {@link Plugin.hostApi}, and one that targets a newer version
|
|
14
|
+
* than this is unavailable.
|
|
15
|
+
*/
|
|
16
|
+
export declare const HOST_API_VERSION = 1;
|
|
17
|
+
/**
|
|
18
|
+
* The site federation's key-value store, as Fedify defines it. A plugin that
|
|
19
|
+
* runs a federation of its own hands it this store, so the two agree about
|
|
20
|
+
* which activities they have already handled.
|
|
21
|
+
*/
|
|
22
|
+
export type { KvStore };
|
|
23
|
+
/** What a plugin's route handler is handed. */
|
|
24
|
+
export interface PluginRequestContext {
|
|
25
|
+
/** The request as it arrived. */
|
|
26
|
+
readonly request: Request;
|
|
27
|
+
/** The named parameters of the route's path, such as `:slug`. */
|
|
28
|
+
readonly params: Readonly<Record<string, string>>;
|
|
29
|
+
}
|
|
30
|
+
/** Answers one request to a plugin's route. */
|
|
31
|
+
export type PluginRouteHandler = (context: PluginRequestContext) => Response | Promise<Response>;
|
|
32
|
+
/**
|
|
33
|
+
* A JSON-LD document as plain data. Documents cross the host boundary this way
|
|
34
|
+
* rather than as objects built by a library, because a bundled plugin carries
|
|
35
|
+
* its own copy of every library and an `instanceof` across two copies fails.
|
|
36
|
+
*/
|
|
37
|
+
export type JsonLdDocument = Readonly<Record<string, unknown>>;
|
|
38
|
+
/** One account on the site. */
|
|
39
|
+
export interface PluginUser {
|
|
40
|
+
readonly username: string;
|
|
41
|
+
/** The ActivityStreams id this person was published under elsewhere, if any. */
|
|
42
|
+
readonly actorId?: string | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** A follower, as a user's `followers.json` holds one. */
|
|
45
|
+
export interface PluginFollower {
|
|
46
|
+
readonly actorId: string;
|
|
47
|
+
readonly inboxId: string;
|
|
48
|
+
readonly sharedInboxId: string | null;
|
|
49
|
+
/** `@name@host`, or `null`. */
|
|
50
|
+
readonly handle: string | null;
|
|
51
|
+
readonly name: string | null;
|
|
52
|
+
readonly iconUrl: string | null;
|
|
53
|
+
readonly url: string | null;
|
|
54
|
+
}
|
|
55
|
+
/** The algorithms an actor holds a key pair for. */
|
|
56
|
+
export type PluginKeyAlgorithm = 'RSASSA-PKCS1-v1_5' | 'Ed25519';
|
|
57
|
+
/** One of a user's key files. */
|
|
58
|
+
export interface PluginActorKey {
|
|
59
|
+
/** The file, absolute. */
|
|
60
|
+
readonly file: string;
|
|
61
|
+
/** The private JWK it holds, or `undefined` when there is no file yet. */
|
|
62
|
+
readonly jwk: string | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** The site's accounts, keys and followers, as a plugin may read and change them. */
|
|
65
|
+
export interface PluginSite {
|
|
66
|
+
readonly baseUrl: string;
|
|
67
|
+
/** Every account, in the users file's order. */
|
|
68
|
+
users(): readonly PluginUser[];
|
|
69
|
+
/**
|
|
70
|
+
* Set the id a user was published under elsewhere. Returns whether anything
|
|
71
|
+
* changed. Throws for a user the site does not have, or an id another user
|
|
72
|
+
* already carries.
|
|
73
|
+
*/
|
|
74
|
+
setActorId(username: string, actorId: string): Promise<boolean>;
|
|
75
|
+
actorKey(username: string, algorithm: PluginKeyAlgorithm): PluginActorKey;
|
|
76
|
+
/** Write a private JWK as the user's key for one algorithm. */
|
|
77
|
+
writeActorKey(username: string, algorithm: PluginKeyAlgorithm, jwk: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Load every key pair the user signs with, minting any that is missing.
|
|
80
|
+
* Throws when a key file does not import.
|
|
81
|
+
*/
|
|
82
|
+
loadActorKeys(username: string): Promise<void>;
|
|
83
|
+
followers(username: string): readonly PluginFollower[];
|
|
84
|
+
/** Add a follower, or refresh the one already held. */
|
|
85
|
+
addFollower(username: string, follower: PluginFollower): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
/** The plugin's private folder, `data/plugins/<package name>/`. */
|
|
88
|
+
export interface PluginDataFolder {
|
|
89
|
+
/** The folder, absolute. */
|
|
90
|
+
readonly path: string;
|
|
91
|
+
/** A file's text, or `undefined` when it is not there. */
|
|
92
|
+
read(file: string): string | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Read a file, decide what it says next and write it, as one step nothing
|
|
95
|
+
* else writing that file can get between. The write is atomic.
|
|
96
|
+
*/
|
|
97
|
+
update(file: string, change: (current: string | undefined) => string): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
/** One page of a collection the site's federation publishes. */
|
|
100
|
+
export interface PluginCollectionPage<Item> {
|
|
101
|
+
readonly items: readonly Item[];
|
|
102
|
+
readonly nextCursor: string | null;
|
|
103
|
+
readonly prevCursor: string | null;
|
|
104
|
+
}
|
|
105
|
+
/** A collection the site's federation publishes, paged by offset cursors. */
|
|
106
|
+
export interface PluginCollection<Item> {
|
|
107
|
+
readonly totalItems: number;
|
|
108
|
+
readonly firstCursor: string;
|
|
109
|
+
readonly lastCursor: string;
|
|
110
|
+
/** One page; a `null` cursor is every item at once. */
|
|
111
|
+
page(cursor: string | null): Promise<PluginCollectionPage<Item>>;
|
|
112
|
+
}
|
|
113
|
+
/** A follower as a delivery reaches them. */
|
|
114
|
+
export interface PluginRecipient {
|
|
115
|
+
readonly id: string;
|
|
116
|
+
readonly inboxId: string;
|
|
117
|
+
readonly sharedInboxId: string | null;
|
|
118
|
+
}
|
|
119
|
+
/** What a federation middleware is handed for one request. */
|
|
120
|
+
export interface PluginFederationContext {
|
|
121
|
+
readonly request: Request;
|
|
122
|
+
readonly site: PluginSite;
|
|
123
|
+
/** The site federation's store, for idempotence shared with its inboxes. */
|
|
124
|
+
readonly kv: KvStore;
|
|
125
|
+
/** Whether the site's federation may fetch from private addresses. */
|
|
126
|
+
readonly allowPrivateAddress: boolean;
|
|
127
|
+
/** The site's clock. */
|
|
128
|
+
now(): Date;
|
|
129
|
+
/** A user's actor document, exactly as the site's federation serves it. */
|
|
130
|
+
actor(username: string): Promise<JsonLdDocument | undefined>;
|
|
131
|
+
/**
|
|
132
|
+
* The key pairs a user signs with, as WebCrypto keys, which belong to no
|
|
133
|
+
* library. Empty for a user the site does not have.
|
|
134
|
+
*/
|
|
135
|
+
keyPairs(username: string): Promise<webcrypto.CryptoKeyPair[]>;
|
|
136
|
+
/**
|
|
137
|
+
* A user's outbox, the activities announcing their posts, or `undefined`
|
|
138
|
+
* for a user the site does not have.
|
|
139
|
+
*/
|
|
140
|
+
outbox(username: string): PluginCollection<JsonLdDocument> | undefined;
|
|
141
|
+
/** A user's followers, or `undefined` for a user the site does not have. */
|
|
142
|
+
followers(username: string): PluginCollection<PluginRecipient> | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Handle an activity a plugin's inbox verified, as the site's own inbox
|
|
145
|
+
* handles it. `recipient` is the username of the personal inbox it arrived
|
|
146
|
+
* at, or `null` for a shared inbox.
|
|
147
|
+
*/
|
|
148
|
+
receive(activity: JsonLdDocument, recipient: string | null): Promise<void>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Answers a request in the federation mount, or hands it on with `next`, which
|
|
152
|
+
* resolves to what the rest of the site answers.
|
|
153
|
+
*/
|
|
154
|
+
export type PluginFederationMiddleware = (context: PluginFederationContext, next: () => Promise<Response>) => Promise<Response>;
|
|
155
|
+
/** Text on a plugin screen: plain, or set as code. */
|
|
156
|
+
export type PluginScreenText = string | {
|
|
157
|
+
readonly code: string;
|
|
158
|
+
};
|
|
159
|
+
/** A table cell: text, or an instant drawn as a date, `null` for never. */
|
|
160
|
+
export type PluginScreenCell = PluginScreenText | {
|
|
161
|
+
readonly time: string | null;
|
|
162
|
+
};
|
|
163
|
+
/** One block of a plugin screen's card. */
|
|
164
|
+
export type PluginScreenBlock = {
|
|
165
|
+
readonly paragraph: readonly PluginScreenText[];
|
|
166
|
+
} | {
|
|
167
|
+
readonly table: {
|
|
168
|
+
readonly caption: string;
|
|
169
|
+
readonly columns: readonly string[];
|
|
170
|
+
readonly rows: readonly (readonly PluginScreenCell[])[];
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
/** One card on a plugin screen. */
|
|
174
|
+
export interface PluginScreenCard {
|
|
175
|
+
readonly title: string;
|
|
176
|
+
readonly blocks: readonly PluginScreenBlock[];
|
|
177
|
+
}
|
|
178
|
+
/** What a plugin screen's render and its actions are handed. */
|
|
179
|
+
export interface PluginScreenContext {
|
|
180
|
+
readonly site: PluginSite;
|
|
181
|
+
}
|
|
182
|
+
/** What an action reports, which the screen shows as a notice or an error. */
|
|
183
|
+
export interface PluginScreenOutcome {
|
|
184
|
+
readonly ok: boolean;
|
|
185
|
+
/** Plain words. Core shows them escaped. */
|
|
186
|
+
readonly message: string;
|
|
187
|
+
}
|
|
188
|
+
/** A button on a plugin's screen, such as Test connection. */
|
|
189
|
+
export interface PluginScreenAction {
|
|
190
|
+
/** Lower case words joined by `-`, unique on the screen. */
|
|
191
|
+
readonly id: string;
|
|
192
|
+
readonly label: string;
|
|
193
|
+
run(context: PluginScreenContext): PluginScreenOutcome | Promise<PluginScreenOutcome>;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* A screen under Plugins in the admin, listed in the menu while the plugin is
|
|
197
|
+
* active. Core draws it, so a plugin writes no markup.
|
|
198
|
+
*/
|
|
199
|
+
export interface PluginScreen {
|
|
200
|
+
/** Its heading and its label in the menu. */
|
|
201
|
+
readonly title: string;
|
|
202
|
+
render(context: PluginScreenContext): readonly PluginScreenCard[];
|
|
203
|
+
/** Buttons core draws under the settings, each run when pressed. */
|
|
204
|
+
readonly actions?: readonly PluginScreenAction[] | undefined;
|
|
205
|
+
}
|
|
206
|
+
/** What every settings field has. */
|
|
207
|
+
interface PluginSettingBase {
|
|
208
|
+
/**
|
|
209
|
+
* Lower case words joined by `_`, such as `api_key`. It is the key in
|
|
210
|
+
* `site.json` or `secrets.json`, and upper-cased it ends the field's
|
|
211
|
+
* environment variable.
|
|
212
|
+
*/
|
|
213
|
+
readonly key: string;
|
|
214
|
+
readonly label: string;
|
|
215
|
+
/** A sentence under the box. */
|
|
216
|
+
readonly hint?: string | undefined;
|
|
217
|
+
}
|
|
218
|
+
/** A line of text. An empty box stores nothing, so the default applies. */
|
|
219
|
+
export interface PluginTextSetting extends PluginSettingBase {
|
|
220
|
+
readonly type: 'text';
|
|
221
|
+
readonly default?: string | undefined;
|
|
222
|
+
}
|
|
223
|
+
/** An absolute `http:` or `https:` URL. */
|
|
224
|
+
export interface PluginUrlSetting extends PluginSettingBase {
|
|
225
|
+
readonly type: 'url';
|
|
226
|
+
readonly default?: string | undefined;
|
|
227
|
+
}
|
|
228
|
+
/** One of a fixed list. */
|
|
229
|
+
export interface PluginSelectSetting extends PluginSettingBase {
|
|
230
|
+
readonly type: 'select';
|
|
231
|
+
readonly options: readonly {
|
|
232
|
+
readonly value: string;
|
|
233
|
+
readonly label: string;
|
|
234
|
+
}[];
|
|
235
|
+
readonly default: string;
|
|
236
|
+
}
|
|
237
|
+
/** On or off, off unless a default says otherwise. */
|
|
238
|
+
export interface PluginCheckboxSetting extends PluginSettingBase {
|
|
239
|
+
readonly type: 'checkbox';
|
|
240
|
+
readonly default?: boolean | undefined;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* A credential. It is kept in `secrets.json` in the plugin's data folder at
|
|
244
|
+
* mode 0600, or set by an environment variable, and is never drawn on a page.
|
|
245
|
+
*/
|
|
246
|
+
export interface PluginSecretSetting extends PluginSettingBase {
|
|
247
|
+
readonly type: 'secret';
|
|
248
|
+
}
|
|
249
|
+
/** One field of a plugin's settings form. */
|
|
250
|
+
export type PluginSettingField = PluginTextSetting | PluginUrlSetting | PluginSelectSetting | PluginCheckboxSetting | PluginSecretSetting;
|
|
251
|
+
/** What one field hands the plugin: a secret may be unset, the rest always have a value. */
|
|
252
|
+
export type PluginSettingValue<Field extends PluginSettingField> = Field extends PluginCheckboxSetting ? boolean : Field extends PluginSecretSetting ? string | undefined : Field extends PluginSelectSetting ? Field['options'][number]['value'] : string;
|
|
253
|
+
/** Every field's value, keyed by its key. */
|
|
254
|
+
export type PluginSettingValues<Fields extends readonly PluginSettingField[]> = {
|
|
255
|
+
readonly [Field in Fields[number] as Field['key']]: PluginSettingValue<Field>;
|
|
256
|
+
};
|
|
257
|
+
/** A plugin's settings, as {@link PluginHost.settings} hands them back. */
|
|
258
|
+
export interface PluginSettings<Fields extends readonly PluginSettingField[]> {
|
|
259
|
+
/**
|
|
260
|
+
* The values now, read from the files and the environment on every call. A
|
|
261
|
+
* stored value the field does not accept is replaced by the field's default.
|
|
262
|
+
*/
|
|
263
|
+
current(): PluginSettingValues<Fields>;
|
|
264
|
+
}
|
|
265
|
+
/** One option a command takes. */
|
|
266
|
+
export interface PluginCommandOption {
|
|
267
|
+
/** Its name without the dashes. */
|
|
268
|
+
readonly name: string;
|
|
269
|
+
/** What its value is called in the help, or absent for an on-off switch. */
|
|
270
|
+
readonly value?: string | undefined;
|
|
271
|
+
readonly description: string;
|
|
272
|
+
}
|
|
273
|
+
/** What a command's run is handed. */
|
|
274
|
+
export interface PluginCommandContext {
|
|
275
|
+
/** The arguments after the command's words. */
|
|
276
|
+
readonly args: readonly string[];
|
|
277
|
+
/** Each option given: the text after it, or `true` for a switch. */
|
|
278
|
+
readonly options: Readonly<Record<string, string | true>>;
|
|
279
|
+
/** The directory the command was run from. */
|
|
280
|
+
readonly cwd: string;
|
|
281
|
+
readonly site: PluginSite;
|
|
282
|
+
/** Write to standard output. */
|
|
283
|
+
write(text: string): void;
|
|
284
|
+
}
|
|
285
|
+
/** A command on the `geekity` command line. */
|
|
286
|
+
export interface PluginCommand {
|
|
287
|
+
/** The words that name it, such as `['import', 'old-blog']`. */
|
|
288
|
+
readonly words: readonly string[];
|
|
289
|
+
/** What follows the words in the usage line, such as `<username> --id <n>`. */
|
|
290
|
+
readonly usage: string;
|
|
291
|
+
/** What `geekity --help` says it does. */
|
|
292
|
+
readonly summary: string;
|
|
293
|
+
/** Every option it takes; any other is refused. */
|
|
294
|
+
readonly options?: readonly PluginCommandOption[] | undefined;
|
|
295
|
+
/** Run it and answer the exit code. A thrown error is printed and exits 1. */
|
|
296
|
+
run(context: PluginCommandContext): number | Promise<number>;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The service each plugin provides, keyed by its package name. Empty here: a
|
|
300
|
+
* plugin package that provides one adds its entry by declaration merging, and
|
|
301
|
+
* a consumer that imports the package's types sees it.
|
|
302
|
+
*
|
|
303
|
+
* ```ts
|
|
304
|
+
* declare module '@geekity/cms/plugin' {
|
|
305
|
+
* interface PluginServices {
|
|
306
|
+
* '@acme/plugin-clock': Clock;
|
|
307
|
+
* }
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
export interface PluginServices {
|
|
312
|
+
}
|
|
313
|
+
/** The service a package provides, as {@link PluginServices} says, or `unknown` when it says nothing. */
|
|
314
|
+
export type PluginService<Name extends string> = Name extends keyof PluginServices ? PluginServices[Name] : unknown;
|
|
315
|
+
/** A field of the post and page editor that a plugin's button can sit beside. */
|
|
316
|
+
export type PluginEditorField = 'title' | 'description' | 'tags';
|
|
317
|
+
/**
|
|
318
|
+
* What kind of post a draft is, by Post Type Discovery over what the editor
|
|
319
|
+
* holds: a post with a `like-of` is a `like`, one with photos a `photo`, an
|
|
320
|
+
* untitled one a `note` and a titled one an `article`.
|
|
321
|
+
*/
|
|
322
|
+
export type PluginPostType = 'event' | 'rsvp' | 'repost' | 'like' | 'reply' | 'photo' | 'read' | 'bookmark' | 'note' | 'article';
|
|
323
|
+
/** The document in the editor as it stands when a button is pressed, saved or not. */
|
|
324
|
+
export interface PluginEditorDraft {
|
|
325
|
+
readonly type: 'post' | 'page';
|
|
326
|
+
/** A post's kind, or `undefined` for a page. */
|
|
327
|
+
readonly postType: PluginPostType | undefined;
|
|
328
|
+
/** Whether the document is on disk, rather than new in the editor. */
|
|
329
|
+
readonly saved: boolean;
|
|
330
|
+
readonly title: string;
|
|
331
|
+
/** The Markdown body. */
|
|
332
|
+
readonly body: string;
|
|
333
|
+
readonly description: string;
|
|
334
|
+
readonly tags: readonly string[];
|
|
335
|
+
/** The language it is written in: its own `lang`, else the site's. */
|
|
336
|
+
readonly lang: string;
|
|
337
|
+
}
|
|
338
|
+
/** What a press of an editor button hands its plugin. */
|
|
339
|
+
export interface PluginEditorContext {
|
|
340
|
+
readonly draft: PluginEditorDraft;
|
|
341
|
+
/** Every tag on the site's published documents, as written, most used first. */
|
|
342
|
+
readonly siteTags: readonly string[];
|
|
343
|
+
/**
|
|
344
|
+
* The titles of the site's latest published posts that have one, newest
|
|
345
|
+
* first, at most ten, leaving out any the draft's own title repeats.
|
|
346
|
+
*/
|
|
347
|
+
readonly recentTitles: readonly string[];
|
|
348
|
+
/** Aborts when the author leaves the page before the answer comes. */
|
|
349
|
+
readonly signal: AbortSignal;
|
|
350
|
+
}
|
|
351
|
+
/** One of several values an editor button offers, each drawn with a box to tick. */
|
|
352
|
+
export interface PluginEditorChoice {
|
|
353
|
+
readonly value: string;
|
|
354
|
+
/** A few words after it, such as `120 followers`. */
|
|
355
|
+
readonly note?: string | undefined;
|
|
356
|
+
/** A word or two drawn as a badge, such as `Used here`. */
|
|
357
|
+
readonly badge?: string | undefined;
|
|
358
|
+
/**
|
|
359
|
+
* The heading the choice is listed under, such as `For reach`. The editor
|
|
360
|
+
* draws the heading before a choice whose group differs from the one before
|
|
361
|
+
* it, so a plugin lists each group's choices together.
|
|
362
|
+
*/
|
|
363
|
+
readonly group?: string | undefined;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* What an editor button answers: a value the author may accept into the
|
|
367
|
+
* field, choices the author ticks before accepting, or why there is none, in
|
|
368
|
+
* plain words. Core shows each escaped. Choices are for the tags field, and
|
|
369
|
+
* accepting adds every ticked one; beside another field they are a failure.
|
|
370
|
+
*/
|
|
371
|
+
export type PluginEditorSuggestion = {
|
|
372
|
+
readonly ok: true;
|
|
373
|
+
readonly value: string;
|
|
374
|
+
} | {
|
|
375
|
+
readonly ok: true;
|
|
376
|
+
readonly choices: readonly PluginEditorChoice[];
|
|
377
|
+
} | {
|
|
378
|
+
readonly ok: false;
|
|
379
|
+
readonly message: string;
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* A button beside an editor field. Core draws it, posts the draft to the
|
|
383
|
+
* plugin when it is pressed, and shows the suggestion with Accept and
|
|
384
|
+
* Dismiss. Accepting fills the field and saves nothing; nothing is sent
|
|
385
|
+
* unless the author presses the button. Without JavaScript there is no
|
|
386
|
+
* button.
|
|
387
|
+
*/
|
|
388
|
+
export interface PluginEditorAction {
|
|
389
|
+
/** Lower case words joined by `-`, unique among the plugin's editor actions. */
|
|
390
|
+
readonly id: string;
|
|
391
|
+
readonly field: PluginEditorField;
|
|
392
|
+
/** The button's words, such as `Suggest title`. */
|
|
393
|
+
readonly label: string;
|
|
394
|
+
/**
|
|
395
|
+
* Whether the button is offered for this draft. Asked when the editor opens
|
|
396
|
+
* and again when the button is pressed. Absent offers it always.
|
|
397
|
+
*/
|
|
398
|
+
offers?(draft: PluginEditorDraft): boolean;
|
|
399
|
+
suggest(context: PluginEditorContext): PluginEditorSuggestion | Promise<PluginEditorSuggestion>;
|
|
400
|
+
}
|
|
401
|
+
/** What a plugin's {@link PluginHost.fetch} sends besides the URL. */
|
|
402
|
+
export interface PluginFetchInit {
|
|
403
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
404
|
+
/** Ends the request, and any redirect it leads to, when it aborts. */
|
|
405
|
+
readonly signal?: AbortSignal | undefined;
|
|
406
|
+
}
|
|
407
|
+
/** What a plugin knows of the site it runs on. */
|
|
408
|
+
export interface PluginSiteInfo {
|
|
409
|
+
/** The site's public URL. */
|
|
410
|
+
readonly baseUrl: string;
|
|
411
|
+
/** The site title, as the site's settings have it now. */
|
|
412
|
+
readonly title: string;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* A plugin's only door into the CMS, handed to {@link Plugin.register}. It
|
|
416
|
+
* reaches no other plugin during `register`: registration order never
|
|
417
|
+
* matters. Everything is declared during `register`; a declaration after it
|
|
418
|
+
* returns throws.
|
|
419
|
+
*/
|
|
420
|
+
export interface PluginHost<Name extends string = string, Requires extends PluginRequirements = PluginRequirements> {
|
|
421
|
+
/** {@link HOST_API_VERSION} of the core running the plugin. */
|
|
422
|
+
readonly apiVersion: number;
|
|
423
|
+
/** The name of the plugin this host belongs to. */
|
|
424
|
+
readonly name: Name;
|
|
425
|
+
/** The plugin's private folder under `data/`. */
|
|
426
|
+
readonly data: PluginDataFolder;
|
|
427
|
+
/**
|
|
428
|
+
* Answer `GET` (and `HEAD`) on a public path, in Hono's path syntax. The
|
|
429
|
+
* route answers only while the plugin is enabled; otherwise the request
|
|
430
|
+
* falls through as if the route were absent.
|
|
431
|
+
*/
|
|
432
|
+
get(path: string, handler: PluginRouteHandler): void;
|
|
433
|
+
/**
|
|
434
|
+
* Run a middleware in the federation mount, after the site's own federation
|
|
435
|
+
* has answered its paths and before stored ids are. It runs only while the
|
|
436
|
+
* plugin is enabled.
|
|
437
|
+
*/
|
|
438
|
+
federation(middleware: PluginFederationMiddleware): void;
|
|
439
|
+
/** Add the plugin's screen under Plugins. At most one per plugin. */
|
|
440
|
+
screen(screen: PluginScreen): void;
|
|
441
|
+
/**
|
|
442
|
+
* Declare the plugin's settings, which core draws as a form on its screen.
|
|
443
|
+
* At most once per plugin. Public values are kept under the plugin's key in
|
|
444
|
+
* `content/_data/site.json`; secrets in `secrets.json` in its data folder,
|
|
445
|
+
* or in the environment variable named by the package name, `__` and the
|
|
446
|
+
* key, upper-cased with every run of other characters as one `_`.
|
|
447
|
+
*/
|
|
448
|
+
settings<const Fields extends readonly PluginSettingField[]>(fields: Fields): PluginSettings<Fields>;
|
|
449
|
+
/**
|
|
450
|
+
* Add a command to the command line. It runs whenever the plugin is
|
|
451
|
+
* installed and available, enabled or not.
|
|
452
|
+
*/
|
|
453
|
+
command(command: PluginCommand): void;
|
|
454
|
+
/**
|
|
455
|
+
* Add a button beside a field of the post and page editor, drawn while the
|
|
456
|
+
* plugin is enabled. Pressing it posts the draft to
|
|
457
|
+
* `/admin/plugins/<package name>/editor/<id>`, which only a signed-in user
|
|
458
|
+
* with the page's CSRF token reaches.
|
|
459
|
+
*/
|
|
460
|
+
editorAction(action: PluginEditorAction): void;
|
|
461
|
+
/** The site's base URL and title, read when asked. */
|
|
462
|
+
siteInfo(): PluginSiteInfo;
|
|
463
|
+
/**
|
|
464
|
+
* `GET` another site's URL. Redirects are followed, at most five, and every
|
|
465
|
+
* address on the way must be public: a loopback, private or link-local
|
|
466
|
+
* address, or a name that resolves to one, rejects with an error, unless
|
|
467
|
+
* the site lets its federation reach private addresses. Rejects as `fetch`
|
|
468
|
+
* does when the host cannot be reached; any status is answered as it came.
|
|
469
|
+
*/
|
|
470
|
+
fetch(url: string, init?: PluginFetchInit): Promise<Response>;
|
|
471
|
+
/**
|
|
472
|
+
* Offer this plugin's service to the plugins that require it, under the
|
|
473
|
+
* plugin's own package name. At most once per plugin, during `register`.
|
|
474
|
+
* Every consumer receives this one instance, so it carries plain data and
|
|
475
|
+
* the host's types across, never an object built by a library.
|
|
476
|
+
*/
|
|
477
|
+
provide(service: PluginService<Name>): void;
|
|
478
|
+
/**
|
|
479
|
+
* The service a required plugin provides. Only a name in `requires` is
|
|
480
|
+
* accepted, and only once every plugin has registered: call it when
|
|
481
|
+
* handling a request, a command or a job, never in `register`.
|
|
482
|
+
*/
|
|
483
|
+
use<Dependency extends keyof Requires & string>(name: Dependency): PluginService<Dependency>;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* The plugins this one depends on: package name to the semver range it
|
|
487
|
+
* needs, the same pairs as its peer dependencies.
|
|
488
|
+
*/
|
|
489
|
+
export type PluginRequirements = Readonly<Record<string, string>>;
|
|
490
|
+
/** A plugin, as a site config or a bundle's default export hands it over. */
|
|
491
|
+
export interface Plugin<Name extends string = string, Requires extends PluginRequirements = PluginRequirements> {
|
|
492
|
+
/**
|
|
493
|
+
* The npm package name, such as `@geekity/plugin-llm`. A plugin installed by
|
|
494
|
+
* hand still declares a package-style name. It is the key of the plugin
|
|
495
|
+
* everywhere: `requires`, the `plugins` key in `site.json` and its data.
|
|
496
|
+
*/
|
|
497
|
+
readonly name: Name;
|
|
498
|
+
/** The package version, shown on the Plugins screen. */
|
|
499
|
+
readonly version: string;
|
|
500
|
+
/** What the Plugins screen calls it. */
|
|
501
|
+
readonly label: string;
|
|
502
|
+
/** One or two sentences on what it does. */
|
|
503
|
+
readonly description: string;
|
|
504
|
+
/** The {@link HOST_API_VERSION} it was written against. */
|
|
505
|
+
readonly hostApi: number;
|
|
506
|
+
/** The plugins it needs installed and enabled before it can be enabled. */
|
|
507
|
+
readonly requires?: Requires;
|
|
508
|
+
/**
|
|
509
|
+
* Called once at boot for every installed plugin, enabled or not, to
|
|
510
|
+
* declare what the plugin contributes.
|
|
511
|
+
*/
|
|
512
|
+
register(host: PluginHost<Name, Requires>): void;
|
|
513
|
+
/** Called when the plugin starts running: at boot when enabled, and on enable. */
|
|
514
|
+
start?(): void | Promise<void>;
|
|
515
|
+
/** Called when it stops: on disable and when the CMS closes. */
|
|
516
|
+
stop?(): void | Promise<void>;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Declare a plugin, typed. Returns it unchanged. Its name and `requires` are
|
|
520
|
+
* kept as written, so `host.use` accepts only a required name and
|
|
521
|
+
* `host.provide` only the service {@link PluginServices} names for the plugin.
|
|
522
|
+
*/
|
|
523
|
+
export declare function definePlugin<const Name extends string, const Requires extends PluginRequirements = {}>(plugin: Plugin<Name, Requires>): Plugin<NoInfer<Name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CAAC;IAC/B,gEAAgE;IAChE,IAAI,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,KAAK,CAAC,IAAI,SAAS,MAAM,EAEzB,KAAK,CAAC,QAAQ,SAAS,kBAAkB,GAAG,EAAE,EAE9C,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,GAG7B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAE1C"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@geekity/cms/plugin`: the whole of what a plugin may import from core
|
|
3
|
+
* (decision-33). Types, the host API version and {@link definePlugin}, which is
|
|
4
|
+
* an identity function so a bundled plugin needs no runtime import of core.
|
|
5
|
+
*
|
|
6
|
+
* Removing or reshaping anything here is a breaking change to `@geekity/cms`
|
|
7
|
+
* (decision-6), and bumps {@link HOST_API_VERSION}.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The version of the host API this core provides. A plugin names the version
|
|
11
|
+
* it targets in {@link Plugin.hostApi}, and one that targets a newer version
|
|
12
|
+
* than this is unavailable.
|
|
13
|
+
*/
|
|
14
|
+
export const HOST_API_VERSION = 1;
|
|
15
|
+
/**
|
|
16
|
+
* Declare a plugin, typed. Returns it unchanged. Its name and `requires` are
|
|
17
|
+
* kept as written, so `host.use` accepts only a required name and
|
|
18
|
+
* `host.provide` only the service {@link PluginServices} names for the plugin.
|
|
19
|
+
*/
|
|
20
|
+
export function definePlugin(plugin) {
|
|
21
|
+
return plugin;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AA+jBlC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAK1B,MAA8B;IAI9B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The enabled set: the `plugins` key of `content/_data/site.json`, an object
|
|
3
|
+
* keyed by package name (decision-33). Each value is an object of its own, so
|
|
4
|
+
* a plugin's public settings can sit beside `enabled` and survive a disable.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PLUGINS_KEY = "plugins";
|
|
7
|
+
/** The names the site has enabled, read from the file now. */
|
|
8
|
+
export declare function readEnabledPlugins(contentDir: string): ReadonlySet<string>;
|
|
9
|
+
/** Write one plugin's `enabled`, keeping every other key in the file. */
|
|
10
|
+
export declare function setPluginEnabled(options: {
|
|
11
|
+
contentDir: string;
|
|
12
|
+
name: string;
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
/** One plugin's object under `plugins`, empty when it has none. */
|
|
16
|
+
export declare function readPluginEntry(contentDir: string, name: string): Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Rewrite one plugin's object under `plugins`, keeping every other key in the
|
|
19
|
+
* file. The only writer of the `plugins` key: enabling and settings both go
|
|
20
|
+
* through it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function updatePluginEntry(contentDir: string, name: string, change: (entry: Record<string, unknown>) => Record<string, unknown>): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=enabled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enabled.d.ts","sourceRoot":"","sources":["../../src/plugins/enabled.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAM1E;AAED,yEAAyE;AACzE,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhB;AAED,mEAAmE;AACnE,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGzF;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClE,OAAO,CAAC,IAAI,CAAC,CAQf"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The enabled set: the `plugins` key of `content/_data/site.json`, an object
|
|
3
|
+
* keyed by package name (decision-33). Each value is an object of its own, so
|
|
4
|
+
* a plugin's public settings can sit beside `enabled` and survive a disable.
|
|
5
|
+
*/
|
|
6
|
+
import { parseSiteJson, readSiteJson, siteDataPath } from '../admin/settings.js';
|
|
7
|
+
import { updateFileAtomically } from '../files/atomic.js';
|
|
8
|
+
export const PLUGINS_KEY = 'plugins';
|
|
9
|
+
/** The names the site has enabled, read from the file now. */
|
|
10
|
+
export function readEnabledPlugins(contentDir) {
|
|
11
|
+
const enabled = new Set();
|
|
12
|
+
for (const [name, entry] of Object.entries(pluginsOf(readSiteJson(contentDir)))) {
|
|
13
|
+
if (isRecord(entry) && entry['enabled'] === true)
|
|
14
|
+
enabled.add(name);
|
|
15
|
+
}
|
|
16
|
+
return enabled;
|
|
17
|
+
}
|
|
18
|
+
/** Write one plugin's `enabled`, keeping every other key in the file. */
|
|
19
|
+
export async function setPluginEnabled(options) {
|
|
20
|
+
const { contentDir, name, enabled } = options;
|
|
21
|
+
await updatePluginEntry(contentDir, name, (entry) => ({ ...entry, enabled }));
|
|
22
|
+
}
|
|
23
|
+
/** One plugin's object under `plugins`, empty when it has none. */
|
|
24
|
+
export function readPluginEntry(contentDir, name) {
|
|
25
|
+
const entry = pluginsOf(readSiteJson(contentDir))[name];
|
|
26
|
+
return isRecord(entry) ? entry : {};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Rewrite one plugin's object under `plugins`, keeping every other key in the
|
|
30
|
+
* file. The only writer of the `plugins` key: enabling and settings both go
|
|
31
|
+
* through it.
|
|
32
|
+
*/
|
|
33
|
+
export async function updatePluginEntry(contentDir, name, change) {
|
|
34
|
+
await updateFileAtomically(siteDataPath(contentDir), (current) => {
|
|
35
|
+
const file = parseSiteJson(current ?? '');
|
|
36
|
+
const plugins = pluginsOf(file);
|
|
37
|
+
const entry = plugins[name];
|
|
38
|
+
file[PLUGINS_KEY] = { ...plugins, [name]: change(isRecord(entry) ? entry : {}) };
|
|
39
|
+
return `${JSON.stringify(file, null, 2)}\n`;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function pluginsOf(file) {
|
|
43
|
+
const plugins = file[PLUGINS_KEY];
|
|
44
|
+
return isRecord(plugins) ? plugins : {};
|
|
45
|
+
}
|
|
46
|
+
function isRecord(value) {
|
|
47
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=enabled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enabled.js","sourceRoot":"","sources":["../../src/plugins/enabled.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAG,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