@moku-labs/worker 0.4.0 → 0.5.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/dist/cli.cjs +926 -93
- package/dist/cli.d.cts +169 -69
- package/dist/cli.d.mts +169 -69
- package/dist/cli.mjs +927 -94
- package/dist/{config-50jmPyMv.d.cts → config-BYPJvEbl.d.cts} +16 -0
- package/dist/{config-50jmPyMv.d.mts → config-BYPJvEbl.d.mts} +16 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/package.json +9 -1
package/dist/cli.d.cts
CHANGED
|
@@ -1,76 +1,24 @@
|
|
|
1
1
|
import { PluginCtx, PluginInstance } from "@moku-labs/core";
|
|
2
2
|
|
|
3
|
-
//#region src/plugins/
|
|
4
|
-
/**
|
|
5
|
-
* @file cli plugin — type definitions (Config, Api).
|
|
6
|
-
*/
|
|
7
|
-
/** Resolved configuration for the cli plugin. Flat; complete defaults so omission never yields undefined. */
|
|
8
|
-
type Config$1 = {
|
|
9
|
-
/**
|
|
10
|
-
* Default local dev port forwarded to deploy.dev when dev() gets no port.
|
|
11
|
-
* Passed through to `wrangler dev --port <n>`.
|
|
12
|
-
*
|
|
13
|
-
* @default 8787
|
|
14
|
-
*/
|
|
15
|
-
readonly port: number;
|
|
16
|
-
};
|
|
17
|
-
/** Public api surface of the cli plugin, mounted at app.cli.*. */
|
|
18
|
-
type Api = {
|
|
19
|
-
/**
|
|
20
|
-
* Run the Worker locally via Wrangler (delegates to deploy.dev).
|
|
21
|
-
* Defaults port to the configured value (8787) when called with no opts.
|
|
22
|
-
*
|
|
23
|
-
* @param opts - Optional port override.
|
|
24
|
-
* @param opts.port - Local dev port to bind.
|
|
25
|
-
* @returns Resolves when the dev session ends.
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* await app.cli.dev(); // port 8787
|
|
29
|
-
* await app.cli.dev({ port: 3000 }); // port 3000
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
dev(opts?: {
|
|
33
|
-
port?: number;
|
|
34
|
-
}): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* One-command guided Cloudflare deploy (delegates to deploy.run).
|
|
37
|
-
* Forwards opts verbatim — passes undefined when called with no opts.
|
|
38
|
-
*
|
|
39
|
-
* @param opts - Optional guided/yes flags.
|
|
40
|
-
* @param opts.guided - Walk through each step interactively.
|
|
41
|
-
* @param opts.yes - Skip confirmation prompts (non-interactive).
|
|
42
|
-
* @returns Resolves once the deploy completes.
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* await app.cli.deploy({ guided: true });
|
|
46
|
-
* await app.cli.deploy({ yes: true }); // CI
|
|
47
|
-
* await app.cli.deploy(); // no opts → undefined forwarded
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
deploy(opts?: {
|
|
51
|
-
guided?: boolean;
|
|
52
|
-
yes?: boolean;
|
|
53
|
-
}): Promise<void>;
|
|
54
|
-
};
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/plugins/cli/index.d.ts
|
|
3
|
+
//#region src/plugins/deploy/types.d.ts
|
|
57
4
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* Inline lambdas on `api`/`hooks` preserve event-name inference so the hook map keys
|
|
65
|
-
* are constrained to `WorkerEvents` keys (spec/15 §5).
|
|
5
|
+
* A web-site build hook wired in from the consumer's deploy/dev script — e.g.
|
|
6
|
+
* `() => webApp.cli.build()`. This is the seam that lets one small app-side script compose a
|
|
7
|
+
* Moku Web app with this Worker framework: `dev` / `deploy` invoke it to (re)build the site
|
|
8
|
+
* before serving or deploying. May resolve a `{ files }` count (surfaced in `dev:rebuilt`) or
|
|
9
|
+
* nothing.
|
|
66
10
|
*
|
|
67
|
-
* @
|
|
11
|
+
* @returns Resolves when the web build completes; optionally a rebuilt-file count.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* await server.cli.dev({ webBuild: () => web.cli.build() });
|
|
15
|
+
* ```
|
|
68
16
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
17
|
+
type WebBuild = () => Promise<void> | Promise<{
|
|
18
|
+
files?: number;
|
|
19
|
+
}>;
|
|
72
20
|
/** deploy plugin configuration. Flat; complete defaults so omission never yields undefined. */
|
|
73
|
-
type Config = {
|
|
21
|
+
type Config$1 = {
|
|
74
22
|
/**
|
|
75
23
|
* Wrangler config file generated/updated and read by `wrangler deploy`. Default "wrangler.jsonc".
|
|
76
24
|
* Also the file parsed in the universal/non-moku path.
|
|
@@ -81,7 +29,18 @@ type Config = {
|
|
|
81
29
|
* CF credentials are read from the Node env (CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID).
|
|
82
30
|
* Default false.
|
|
83
31
|
*/
|
|
84
|
-
ci: boolean;
|
|
32
|
+
ci: boolean; /** Globs watched by `dev()` to trigger a Moku-site rebuild. */
|
|
33
|
+
watch: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Standing default web-site build hook (e.g. `() => webApp.cli.build()`). Usually passed
|
|
36
|
+
* call-time to `dev` / `deploy` via `opts.webBuild` (the script-driven path); set here only for
|
|
37
|
+
* a persistent default. When absent, dev() falls back to `buildCommand`, then auto-detects
|
|
38
|
+
* `scripts/build.ts`.
|
|
39
|
+
*/
|
|
40
|
+
webBuild?: WebBuild; /** Shell rebuild fallback (e.g. "bun run scripts/build.ts"); empty → auto-detect scripts/build.ts. */
|
|
41
|
+
buildCommand: string; /** Apply local D1 migrations before serving when a d1 manifest is present. */
|
|
42
|
+
migrateLocal: boolean; /** Debounce window (ms) coalescing rapid file changes into one rebuild. */
|
|
43
|
+
debounceMs: number;
|
|
85
44
|
};
|
|
86
45
|
/** Discriminated union of resource descriptors returned by each plugin's deployManifest(). */
|
|
87
46
|
type ResourceManifest = {
|
|
@@ -138,6 +97,141 @@ type ProvisionResult = {
|
|
|
138
97
|
skipped: ProvisionedRef[]; /** Merged binding → Cloudflare id map (existing + created) for writeWranglerConfig. */
|
|
139
98
|
ids: Record<string, string>;
|
|
140
99
|
};
|
|
100
|
+
/** Result of verifying the `.env` Cloudflare API token and resolving its account. */
|
|
101
|
+
type AuthStatus = {
|
|
102
|
+
/** Whether the token is present and active. */ok: boolean; /** Resolved account display name (or id when the name is unknown). */
|
|
103
|
+
account: string; /** Resolved Cloudflare account id. */
|
|
104
|
+
accountId: string; /** Token scopes, when discoverable (empty otherwise). */
|
|
105
|
+
scopes: string[];
|
|
106
|
+
};
|
|
107
|
+
/** One Cloudflare API-token permission group the app's manifest requires. */
|
|
108
|
+
type PermissionGroup = {
|
|
109
|
+
/** Human-readable group label, e.g. "Account · D1". */group: string; /** Permission scope. */
|
|
110
|
+
scope: "Edit" | "Read"; /** Why it is required, e.g. "d1", "queue", "deploy", "account". */
|
|
111
|
+
reason: string; /** Whether Cloudflare's stock "Edit Cloudflare Workers" template already includes it. */
|
|
112
|
+
inBaseTemplate: boolean;
|
|
113
|
+
};
|
|
114
|
+
/** The Cloudflare API token this app requires, derived from its manifest. */
|
|
115
|
+
type TokenRequirement = {
|
|
116
|
+
/** The recommended starting template. */base: "Edit Cloudflare Workers"; /** The full set of permission groups required. */
|
|
117
|
+
required: PermissionGroup[]; /** Groups NOT in the base template that the user must add (e.g. D1, Queues). */
|
|
118
|
+
toAdd: PermissionGroup[];
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/plugins/cli/types.d.ts
|
|
122
|
+
/** Resolved configuration for the cli plugin. Flat; complete defaults so omission never yields undefined. */
|
|
123
|
+
type Config = {
|
|
124
|
+
/**
|
|
125
|
+
* Default local dev port forwarded to deploy.dev when dev() gets no port.
|
|
126
|
+
* Passed through to `wrangler dev --port <n>`.
|
|
127
|
+
*
|
|
128
|
+
* @default 8787
|
|
129
|
+
*/
|
|
130
|
+
readonly port: number;
|
|
131
|
+
};
|
|
132
|
+
/** Public api surface of the cli plugin, mounted at app.cli.*. */
|
|
133
|
+
type Api = {
|
|
134
|
+
/**
|
|
135
|
+
* Run the Worker locally via Wrangler (delegates to deploy.dev).
|
|
136
|
+
* Defaults port to the configured value (8787) when called with no opts.
|
|
137
|
+
*
|
|
138
|
+
* @param opts - Optional port override and web build hook.
|
|
139
|
+
* @param opts.port - Local dev port to bind.
|
|
140
|
+
* @param opts.webBuild - Rebuild the web site on change (e.g. `() => webApp.cli.build()`).
|
|
141
|
+
* @returns Resolves when the dev session ends.
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* await app.cli.dev(); // port 8787, worker only
|
|
145
|
+
* await app.cli.dev({ webBuild: () => web.cli.build() }); // wire the web build in
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
dev(opts?: {
|
|
149
|
+
port?: number;
|
|
150
|
+
webBuild?: WebBuild;
|
|
151
|
+
}): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* One-command guided Cloudflare deploy (delegates to deploy.run).
|
|
154
|
+
* Forwards opts verbatim — passes undefined when called with no opts.
|
|
155
|
+
*
|
|
156
|
+
* @param opts - Optional guided/yes flags and a web build hook.
|
|
157
|
+
* @param opts.guided - Walk through each step interactively.
|
|
158
|
+
* @param opts.yes - Skip confirmation prompts (non-interactive).
|
|
159
|
+
* @param opts.webBuild - Build the web site first (e.g. `() => webApp.cli.build()`), before deploy.
|
|
160
|
+
* @returns Resolves once the deploy completes.
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* await app.cli.deploy({ guided: true, webBuild: () => web.cli.build() });
|
|
164
|
+
* await app.cli.deploy({ yes: true }); // CI
|
|
165
|
+
* await app.cli.deploy(); // no opts → undefined forwarded
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
deploy(opts?: {
|
|
169
|
+
guided?: boolean;
|
|
170
|
+
yes?: boolean;
|
|
171
|
+
webBuild?: WebBuild;
|
|
172
|
+
}): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Verify the `.env` Cloudflare token (no sub), or print the config-derived token-creation
|
|
175
|
+
* guidance (`"setup"`). Delegates to deploy.verifyAuth() / deploy.tokenInstructions().
|
|
176
|
+
*
|
|
177
|
+
* @param sub - Pass "setup" to print token guidance; omit to verify the current token.
|
|
178
|
+
* @returns Resolves once the auth check or guidance render completes.
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* await app.cli.auth(); // verify the current token
|
|
182
|
+
* await app.cli.auth("setup"); // print what token to create
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
auth(sub?: "setup"): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* One-shot preflight report: token + account (verifyAuth) and infra drift (checkInfra),
|
|
188
|
+
* each rendered as a branded check line.
|
|
189
|
+
*
|
|
190
|
+
* @returns Resolves once the report is printed.
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* await app.cli.doctor();
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
doctor(): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Print the resolved Cloudflare account for the current `.env` token (delegates to verifyAuth).
|
|
199
|
+
*
|
|
200
|
+
* @returns Resolves once the account summary is printed.
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* await app.cli.whoami();
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
whoami(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Run an arbitrary `wrangler` command through the branded CLI — the escape hatch for subcommands
|
|
209
|
+
* Moku does not wrap (kv / d1 / r2 / queues / secret / tail / …). Streams wrangler's output.
|
|
210
|
+
*
|
|
211
|
+
* @param args - The wrangler arguments (e.g. ["kv", "namespace", "list"]).
|
|
212
|
+
* @returns Resolves once wrangler exits.
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* await app.cli.wrangler(["kv", "namespace", "list"]);
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
wrangler(args: string[]): Promise<void>;
|
|
219
|
+
};
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/plugins/cli/index.d.ts
|
|
222
|
+
/**
|
|
223
|
+
* Standard tier (node-only) — developer-facing CLI surface.
|
|
224
|
+
*
|
|
225
|
+
* Mounts `app.cli.dev()` and `app.cli.deploy()` as thin passthroughs to deployPlugin.
|
|
226
|
+
* Hooks subscribe to the global deploy:phase / provision:resource / deploy:complete events
|
|
227
|
+
* and print a live progress TUI via the injected ctx.log core API.
|
|
228
|
+
*
|
|
229
|
+
* Inline lambdas on `api`/`hooks` preserve event-name inference so the hook map keys
|
|
230
|
+
* are constrained to `WorkerEvents` keys (spec/15 §5).
|
|
231
|
+
*
|
|
232
|
+
* @see README.md
|
|
233
|
+
*/
|
|
234
|
+
declare const cliPlugin: import("@moku-labs/core").PluginInstance<"cli", Config, Record<string, never>, Api, {}> & Record<never, never>;
|
|
141
235
|
//#endregion
|
|
142
236
|
//#region src/plugins/deploy/index.d.ts
|
|
143
237
|
/**
|
|
@@ -152,20 +246,26 @@ type ProvisionResult = {
|
|
|
152
246
|
*
|
|
153
247
|
* @see README.md
|
|
154
248
|
*/
|
|
155
|
-
declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", Config, Record<string, never>, {
|
|
249
|
+
declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", Config$1, Record<string, never>, {
|
|
156
250
|
run(opts?: {
|
|
157
251
|
guided?: boolean;
|
|
158
252
|
yes?: boolean;
|
|
253
|
+
webBuild?: WebBuild;
|
|
159
254
|
manifest?: ExternalManifest;
|
|
160
255
|
}): Promise<void>;
|
|
161
256
|
dev: (opts?: {
|
|
162
257
|
port?: number;
|
|
258
|
+
webBuild?: WebBuild;
|
|
163
259
|
}) => Promise<void>;
|
|
164
260
|
init: (opts?: {
|
|
165
261
|
ci?: boolean;
|
|
166
262
|
}) => Promise<void>;
|
|
167
263
|
checkInfra: () => Promise<InfraPlan>;
|
|
168
264
|
provisionInfra: (plan: InfraPlan) => Promise<ProvisionResult>;
|
|
265
|
+
verifyAuth: () => Promise<AuthStatus>;
|
|
266
|
+
requiredToken: () => TokenRequirement;
|
|
267
|
+
tokenInstructions: () => string;
|
|
268
|
+
wrangler: (args: string[]) => Promise<void>;
|
|
169
269
|
}, {}> & Record<never, never>;
|
|
170
270
|
//#endregion
|
|
171
271
|
export { type ExternalManifest, type ResourceManifest, cliPlugin, deployPlugin };
|
package/dist/cli.d.mts
CHANGED
|
@@ -1,76 +1,24 @@
|
|
|
1
1
|
import { PluginCtx, PluginInstance } from "@moku-labs/core";
|
|
2
2
|
|
|
3
|
-
//#region src/plugins/
|
|
4
|
-
/**
|
|
5
|
-
* @file cli plugin — type definitions (Config, Api).
|
|
6
|
-
*/
|
|
7
|
-
/** Resolved configuration for the cli plugin. Flat; complete defaults so omission never yields undefined. */
|
|
8
|
-
type Config$1 = {
|
|
9
|
-
/**
|
|
10
|
-
* Default local dev port forwarded to deploy.dev when dev() gets no port.
|
|
11
|
-
* Passed through to `wrangler dev --port <n>`.
|
|
12
|
-
*
|
|
13
|
-
* @default 8787
|
|
14
|
-
*/
|
|
15
|
-
readonly port: number;
|
|
16
|
-
};
|
|
17
|
-
/** Public api surface of the cli plugin, mounted at app.cli.*. */
|
|
18
|
-
type Api = {
|
|
19
|
-
/**
|
|
20
|
-
* Run the Worker locally via Wrangler (delegates to deploy.dev).
|
|
21
|
-
* Defaults port to the configured value (8787) when called with no opts.
|
|
22
|
-
*
|
|
23
|
-
* @param opts - Optional port override.
|
|
24
|
-
* @param opts.port - Local dev port to bind.
|
|
25
|
-
* @returns Resolves when the dev session ends.
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* await app.cli.dev(); // port 8787
|
|
29
|
-
* await app.cli.dev({ port: 3000 }); // port 3000
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
dev(opts?: {
|
|
33
|
-
port?: number;
|
|
34
|
-
}): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* One-command guided Cloudflare deploy (delegates to deploy.run).
|
|
37
|
-
* Forwards opts verbatim — passes undefined when called with no opts.
|
|
38
|
-
*
|
|
39
|
-
* @param opts - Optional guided/yes flags.
|
|
40
|
-
* @param opts.guided - Walk through each step interactively.
|
|
41
|
-
* @param opts.yes - Skip confirmation prompts (non-interactive).
|
|
42
|
-
* @returns Resolves once the deploy completes.
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* await app.cli.deploy({ guided: true });
|
|
46
|
-
* await app.cli.deploy({ yes: true }); // CI
|
|
47
|
-
* await app.cli.deploy(); // no opts → undefined forwarded
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
deploy(opts?: {
|
|
51
|
-
guided?: boolean;
|
|
52
|
-
yes?: boolean;
|
|
53
|
-
}): Promise<void>;
|
|
54
|
-
};
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/plugins/cli/index.d.ts
|
|
3
|
+
//#region src/plugins/deploy/types.d.ts
|
|
57
4
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* Inline lambdas on `api`/`hooks` preserve event-name inference so the hook map keys
|
|
65
|
-
* are constrained to `WorkerEvents` keys (spec/15 §5).
|
|
5
|
+
* A web-site build hook wired in from the consumer's deploy/dev script — e.g.
|
|
6
|
+
* `() => webApp.cli.build()`. This is the seam that lets one small app-side script compose a
|
|
7
|
+
* Moku Web app with this Worker framework: `dev` / `deploy` invoke it to (re)build the site
|
|
8
|
+
* before serving or deploying. May resolve a `{ files }` count (surfaced in `dev:rebuilt`) or
|
|
9
|
+
* nothing.
|
|
66
10
|
*
|
|
67
|
-
* @
|
|
11
|
+
* @returns Resolves when the web build completes; optionally a rebuilt-file count.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* await server.cli.dev({ webBuild: () => web.cli.build() });
|
|
15
|
+
* ```
|
|
68
16
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
17
|
+
type WebBuild = () => Promise<void> | Promise<{
|
|
18
|
+
files?: number;
|
|
19
|
+
}>;
|
|
72
20
|
/** deploy plugin configuration. Flat; complete defaults so omission never yields undefined. */
|
|
73
|
-
type Config = {
|
|
21
|
+
type Config$1 = {
|
|
74
22
|
/**
|
|
75
23
|
* Wrangler config file generated/updated and read by `wrangler deploy`. Default "wrangler.jsonc".
|
|
76
24
|
* Also the file parsed in the universal/non-moku path.
|
|
@@ -81,7 +29,18 @@ type Config = {
|
|
|
81
29
|
* CF credentials are read from the Node env (CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID).
|
|
82
30
|
* Default false.
|
|
83
31
|
*/
|
|
84
|
-
ci: boolean;
|
|
32
|
+
ci: boolean; /** Globs watched by `dev()` to trigger a Moku-site rebuild. */
|
|
33
|
+
watch: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Standing default web-site build hook (e.g. `() => webApp.cli.build()`). Usually passed
|
|
36
|
+
* call-time to `dev` / `deploy` via `opts.webBuild` (the script-driven path); set here only for
|
|
37
|
+
* a persistent default. When absent, dev() falls back to `buildCommand`, then auto-detects
|
|
38
|
+
* `scripts/build.ts`.
|
|
39
|
+
*/
|
|
40
|
+
webBuild?: WebBuild; /** Shell rebuild fallback (e.g. "bun run scripts/build.ts"); empty → auto-detect scripts/build.ts. */
|
|
41
|
+
buildCommand: string; /** Apply local D1 migrations before serving when a d1 manifest is present. */
|
|
42
|
+
migrateLocal: boolean; /** Debounce window (ms) coalescing rapid file changes into one rebuild. */
|
|
43
|
+
debounceMs: number;
|
|
85
44
|
};
|
|
86
45
|
/** Discriminated union of resource descriptors returned by each plugin's deployManifest(). */
|
|
87
46
|
type ResourceManifest = {
|
|
@@ -138,6 +97,141 @@ type ProvisionResult = {
|
|
|
138
97
|
skipped: ProvisionedRef[]; /** Merged binding → Cloudflare id map (existing + created) for writeWranglerConfig. */
|
|
139
98
|
ids: Record<string, string>;
|
|
140
99
|
};
|
|
100
|
+
/** Result of verifying the `.env` Cloudflare API token and resolving its account. */
|
|
101
|
+
type AuthStatus = {
|
|
102
|
+
/** Whether the token is present and active. */ok: boolean; /** Resolved account display name (or id when the name is unknown). */
|
|
103
|
+
account: string; /** Resolved Cloudflare account id. */
|
|
104
|
+
accountId: string; /** Token scopes, when discoverable (empty otherwise). */
|
|
105
|
+
scopes: string[];
|
|
106
|
+
};
|
|
107
|
+
/** One Cloudflare API-token permission group the app's manifest requires. */
|
|
108
|
+
type PermissionGroup = {
|
|
109
|
+
/** Human-readable group label, e.g. "Account · D1". */group: string; /** Permission scope. */
|
|
110
|
+
scope: "Edit" | "Read"; /** Why it is required, e.g. "d1", "queue", "deploy", "account". */
|
|
111
|
+
reason: string; /** Whether Cloudflare's stock "Edit Cloudflare Workers" template already includes it. */
|
|
112
|
+
inBaseTemplate: boolean;
|
|
113
|
+
};
|
|
114
|
+
/** The Cloudflare API token this app requires, derived from its manifest. */
|
|
115
|
+
type TokenRequirement = {
|
|
116
|
+
/** The recommended starting template. */base: "Edit Cloudflare Workers"; /** The full set of permission groups required. */
|
|
117
|
+
required: PermissionGroup[]; /** Groups NOT in the base template that the user must add (e.g. D1, Queues). */
|
|
118
|
+
toAdd: PermissionGroup[];
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/plugins/cli/types.d.ts
|
|
122
|
+
/** Resolved configuration for the cli plugin. Flat; complete defaults so omission never yields undefined. */
|
|
123
|
+
type Config = {
|
|
124
|
+
/**
|
|
125
|
+
* Default local dev port forwarded to deploy.dev when dev() gets no port.
|
|
126
|
+
* Passed through to `wrangler dev --port <n>`.
|
|
127
|
+
*
|
|
128
|
+
* @default 8787
|
|
129
|
+
*/
|
|
130
|
+
readonly port: number;
|
|
131
|
+
};
|
|
132
|
+
/** Public api surface of the cli plugin, mounted at app.cli.*. */
|
|
133
|
+
type Api = {
|
|
134
|
+
/**
|
|
135
|
+
* Run the Worker locally via Wrangler (delegates to deploy.dev).
|
|
136
|
+
* Defaults port to the configured value (8787) when called with no opts.
|
|
137
|
+
*
|
|
138
|
+
* @param opts - Optional port override and web build hook.
|
|
139
|
+
* @param opts.port - Local dev port to bind.
|
|
140
|
+
* @param opts.webBuild - Rebuild the web site on change (e.g. `() => webApp.cli.build()`).
|
|
141
|
+
* @returns Resolves when the dev session ends.
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* await app.cli.dev(); // port 8787, worker only
|
|
145
|
+
* await app.cli.dev({ webBuild: () => web.cli.build() }); // wire the web build in
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
dev(opts?: {
|
|
149
|
+
port?: number;
|
|
150
|
+
webBuild?: WebBuild;
|
|
151
|
+
}): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* One-command guided Cloudflare deploy (delegates to deploy.run).
|
|
154
|
+
* Forwards opts verbatim — passes undefined when called with no opts.
|
|
155
|
+
*
|
|
156
|
+
* @param opts - Optional guided/yes flags and a web build hook.
|
|
157
|
+
* @param opts.guided - Walk through each step interactively.
|
|
158
|
+
* @param opts.yes - Skip confirmation prompts (non-interactive).
|
|
159
|
+
* @param opts.webBuild - Build the web site first (e.g. `() => webApp.cli.build()`), before deploy.
|
|
160
|
+
* @returns Resolves once the deploy completes.
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* await app.cli.deploy({ guided: true, webBuild: () => web.cli.build() });
|
|
164
|
+
* await app.cli.deploy({ yes: true }); // CI
|
|
165
|
+
* await app.cli.deploy(); // no opts → undefined forwarded
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
deploy(opts?: {
|
|
169
|
+
guided?: boolean;
|
|
170
|
+
yes?: boolean;
|
|
171
|
+
webBuild?: WebBuild;
|
|
172
|
+
}): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Verify the `.env` Cloudflare token (no sub), or print the config-derived token-creation
|
|
175
|
+
* guidance (`"setup"`). Delegates to deploy.verifyAuth() / deploy.tokenInstructions().
|
|
176
|
+
*
|
|
177
|
+
* @param sub - Pass "setup" to print token guidance; omit to verify the current token.
|
|
178
|
+
* @returns Resolves once the auth check or guidance render completes.
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* await app.cli.auth(); // verify the current token
|
|
182
|
+
* await app.cli.auth("setup"); // print what token to create
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
auth(sub?: "setup"): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* One-shot preflight report: token + account (verifyAuth) and infra drift (checkInfra),
|
|
188
|
+
* each rendered as a branded check line.
|
|
189
|
+
*
|
|
190
|
+
* @returns Resolves once the report is printed.
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* await app.cli.doctor();
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
doctor(): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Print the resolved Cloudflare account for the current `.env` token (delegates to verifyAuth).
|
|
199
|
+
*
|
|
200
|
+
* @returns Resolves once the account summary is printed.
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* await app.cli.whoami();
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
whoami(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Run an arbitrary `wrangler` command through the branded CLI — the escape hatch for subcommands
|
|
209
|
+
* Moku does not wrap (kv / d1 / r2 / queues / secret / tail / …). Streams wrangler's output.
|
|
210
|
+
*
|
|
211
|
+
* @param args - The wrangler arguments (e.g. ["kv", "namespace", "list"]).
|
|
212
|
+
* @returns Resolves once wrangler exits.
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* await app.cli.wrangler(["kv", "namespace", "list"]);
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
wrangler(args: string[]): Promise<void>;
|
|
219
|
+
};
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/plugins/cli/index.d.ts
|
|
222
|
+
/**
|
|
223
|
+
* Standard tier (node-only) — developer-facing CLI surface.
|
|
224
|
+
*
|
|
225
|
+
* Mounts `app.cli.dev()` and `app.cli.deploy()` as thin passthroughs to deployPlugin.
|
|
226
|
+
* Hooks subscribe to the global deploy:phase / provision:resource / deploy:complete events
|
|
227
|
+
* and print a live progress TUI via the injected ctx.log core API.
|
|
228
|
+
*
|
|
229
|
+
* Inline lambdas on `api`/`hooks` preserve event-name inference so the hook map keys
|
|
230
|
+
* are constrained to `WorkerEvents` keys (spec/15 §5).
|
|
231
|
+
*
|
|
232
|
+
* @see README.md
|
|
233
|
+
*/
|
|
234
|
+
declare const cliPlugin: import("@moku-labs/core").PluginInstance<"cli", Config, Record<string, never>, Api, {}> & Record<never, never>;
|
|
141
235
|
//#endregion
|
|
142
236
|
//#region src/plugins/deploy/index.d.ts
|
|
143
237
|
/**
|
|
@@ -152,20 +246,26 @@ type ProvisionResult = {
|
|
|
152
246
|
*
|
|
153
247
|
* @see README.md
|
|
154
248
|
*/
|
|
155
|
-
declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", Config, Record<string, never>, {
|
|
249
|
+
declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", Config$1, Record<string, never>, {
|
|
156
250
|
run(opts?: {
|
|
157
251
|
guided?: boolean;
|
|
158
252
|
yes?: boolean;
|
|
253
|
+
webBuild?: WebBuild;
|
|
159
254
|
manifest?: ExternalManifest;
|
|
160
255
|
}): Promise<void>;
|
|
161
256
|
dev: (opts?: {
|
|
162
257
|
port?: number;
|
|
258
|
+
webBuild?: WebBuild;
|
|
163
259
|
}) => Promise<void>;
|
|
164
260
|
init: (opts?: {
|
|
165
261
|
ci?: boolean;
|
|
166
262
|
}) => Promise<void>;
|
|
167
263
|
checkInfra: () => Promise<InfraPlan>;
|
|
168
264
|
provisionInfra: (plan: InfraPlan) => Promise<ProvisionResult>;
|
|
265
|
+
verifyAuth: () => Promise<AuthStatus>;
|
|
266
|
+
requiredToken: () => TokenRequirement;
|
|
267
|
+
tokenInstructions: () => string;
|
|
268
|
+
wrangler: (args: string[]) => Promise<void>;
|
|
169
269
|
}, {}> & Record<never, never>;
|
|
170
270
|
//#endregion
|
|
171
271
|
export { type ExternalManifest, type ResourceManifest, cliPlugin, deployPlugin };
|