@vibesdotdev/infra-deploy 0.0.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/README.md +125 -0
- package/SPEC.md +181 -0
- package/dist/cli/alerts/infra-alerts-create.cli-command.descriptor.d.ts +39 -0
- package/dist/cli/alerts/infra-alerts-create.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/alerts/infra-alerts-create.cli-command.descriptor.js +61 -0
- package/dist/cli/alerts/infra-alerts-create.cli-command.descriptor.js.map +1 -0
- package/dist/cli/alerts/infra-alerts-create.cli-command.impl.d.ts +13 -0
- package/dist/cli/alerts/infra-alerts-create.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/alerts/infra-alerts-create.cli-command.impl.js +109 -0
- package/dist/cli/alerts/infra-alerts-create.cli-command.impl.js.map +1 -0
- package/dist/cli/alerts/infra-alerts-delete.cli-command.descriptor.d.ts +31 -0
- package/dist/cli/alerts/infra-alerts-delete.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/alerts/infra-alerts-delete.cli-command.descriptor.js +36 -0
- package/dist/cli/alerts/infra-alerts-delete.cli-command.descriptor.js.map +1 -0
- package/dist/cli/alerts/infra-alerts-delete.cli-command.impl.d.ts +11 -0
- package/dist/cli/alerts/infra-alerts-delete.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/alerts/infra-alerts-delete.cli-command.impl.js +67 -0
- package/dist/cli/alerts/infra-alerts-delete.cli-command.impl.js.map +1 -0
- package/dist/cli/alerts/infra-alerts-list.cli-command.descriptor.d.ts +21 -0
- package/dist/cli/alerts/infra-alerts-list.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/alerts/infra-alerts-list.cli-command.descriptor.js +27 -0
- package/dist/cli/alerts/infra-alerts-list.cli-command.descriptor.js.map +1 -0
- package/dist/cli/alerts/infra-alerts-list.cli-command.impl.d.ts +12 -0
- package/dist/cli/alerts/infra-alerts-list.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/alerts/infra-alerts-list.cli-command.impl.js +74 -0
- package/dist/cli/alerts/infra-alerts-list.cli-command.impl.js.map +1 -0
- package/dist/cli/alerts/infra-alerts.cli-group.descriptor.d.ts +12 -0
- package/dist/cli/alerts/infra-alerts.cli-group.descriptor.d.ts.map +1 -0
- package/dist/cli/alerts/infra-alerts.cli-group.descriptor.js +12 -0
- package/dist/cli/alerts/infra-alerts.cli-group.descriptor.js.map +1 -0
- package/dist/cli/audit/infra-audit.cli-command.descriptor.d.ts +21 -0
- package/dist/cli/audit/infra-audit.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/audit/infra-audit.cli-command.descriptor.js +28 -0
- package/dist/cli/audit/infra-audit.cli-command.descriptor.js.map +1 -0
- package/dist/cli/audit/infra-audit.cli-command.impl.d.ts +18 -0
- package/dist/cli/audit/infra-audit.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/audit/infra-audit.cli-command.impl.js +219 -0
- package/dist/cli/audit/infra-audit.cli-command.impl.js.map +1 -0
- package/dist/cli/infra-deploy.cli-group.descriptor.d.ts +12 -0
- package/dist/cli/infra-deploy.cli-group.descriptor.d.ts.map +1 -0
- package/dist/cli/infra-deploy.cli-group.descriptor.js +12 -0
- package/dist/cli/infra-deploy.cli-group.descriptor.js.map +1 -0
- package/dist/cli/infra.cli-group.descriptor.d.ts +11 -0
- package/dist/cli/infra.cli-group.descriptor.d.ts.map +1 -0
- package/dist/cli/infra.cli-group.descriptor.js +11 -0
- package/dist/cli/infra.cli-group.descriptor.js.map +1 -0
- package/dist/cli/list/infra-deploy.list.cli-command.descriptor.d.ts +34 -0
- package/dist/cli/list/infra-deploy.list.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/list/infra-deploy.list.cli-command.descriptor.js +29 -0
- package/dist/cli/list/infra-deploy.list.cli-command.descriptor.js.map +1 -0
- package/dist/cli/list/infra-deploy.list.cli-command.impl.d.ts +5 -0
- package/dist/cli/list/infra-deploy.list.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/list/infra-deploy.list.cli-command.impl.js +110 -0
- package/dist/cli/list/infra-deploy.list.cli-command.impl.js.map +1 -0
- package/dist/cli/logs/infra-logs.cli-command.descriptor.d.ts +39 -0
- package/dist/cli/logs/infra-logs.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/logs/infra-logs.cli-command.descriptor.js +64 -0
- package/dist/cli/logs/infra-logs.cli-command.descriptor.js.map +1 -0
- package/dist/cli/logs/infra-logs.cli-command.impl.d.ts +5 -0
- package/dist/cli/logs/infra-logs.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/logs/infra-logs.cli-command.impl.js +323 -0
- package/dist/cli/logs/infra-logs.cli-command.impl.js.map +1 -0
- package/dist/cli/logs/stream-worker-tail.d.ts +62 -0
- package/dist/cli/logs/stream-worker-tail.d.ts.map +1 -0
- package/dist/cli/logs/stream-worker-tail.js +165 -0
- package/dist/cli/logs/stream-worker-tail.js.map +1 -0
- package/dist/cli/npm/infra-npm-publish.cli-command.descriptor.d.ts +27 -0
- package/dist/cli/npm/infra-npm-publish.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/npm/infra-npm-publish.cli-command.descriptor.js +75 -0
- package/dist/cli/npm/infra-npm-publish.cli-command.descriptor.js.map +1 -0
- package/dist/cli/npm/infra-npm-publish.cli-command.impl.d.ts +5 -0
- package/dist/cli/npm/infra-npm-publish.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/npm/infra-npm-publish.cli-command.impl.js +383 -0
- package/dist/cli/npm/infra-npm-publish.cli-command.impl.js.map +1 -0
- package/dist/cli/npm/infra-npm.cli-group.descriptor.d.ts +12 -0
- package/dist/cli/npm/infra-npm.cli-group.descriptor.d.ts.map +1 -0
- package/dist/cli/npm/infra-npm.cli-group.descriptor.js +12 -0
- package/dist/cli/npm/infra-npm.cli-group.descriptor.js.map +1 -0
- package/dist/cli/observability/infra-observability-set.cli-command.descriptor.d.ts +25 -0
- package/dist/cli/observability/infra-observability-set.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/observability/infra-observability-set.cli-command.descriptor.js +57 -0
- package/dist/cli/observability/infra-observability-set.cli-command.descriptor.js.map +1 -0
- package/dist/cli/observability/infra-observability-set.cli-command.impl.d.ts +17 -0
- package/dist/cli/observability/infra-observability-set.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/observability/infra-observability-set.cli-command.impl.js +152 -0
- package/dist/cli/observability/infra-observability-set.cli-command.impl.js.map +1 -0
- package/dist/cli/observability/infra-observability-status.cli-command.descriptor.d.ts +21 -0
- package/dist/cli/observability/infra-observability-status.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/observability/infra-observability-status.cli-command.descriptor.js +35 -0
- package/dist/cli/observability/infra-observability-status.cli-command.descriptor.js.map +1 -0
- package/dist/cli/observability/infra-observability-status.cli-command.impl.d.ts +17 -0
- package/dist/cli/observability/infra-observability-status.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/observability/infra-observability-status.cli-command.impl.js +99 -0
- package/dist/cli/observability/infra-observability-status.cli-command.impl.js.map +1 -0
- package/dist/cli/observability/infra-observability.cli-group.descriptor.d.ts +12 -0
- package/dist/cli/observability/infra-observability.cli-group.descriptor.d.ts.map +1 -0
- package/dist/cli/observability/infra-observability.cli-group.descriptor.js +12 -0
- package/dist/cli/observability/infra-observability.cli-group.descriptor.js.map +1 -0
- package/dist/cli/regenerate/infra-deploy.regenerate.cli-command.descriptor.d.ts +27 -0
- package/dist/cli/regenerate/infra-deploy.regenerate.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/regenerate/infra-deploy.regenerate.cli-command.descriptor.js +35 -0
- package/dist/cli/regenerate/infra-deploy.regenerate.cli-command.descriptor.js.map +1 -0
- package/dist/cli/regenerate/infra-deploy.regenerate.cli-command.impl.d.ts +5 -0
- package/dist/cli/regenerate/infra-deploy.regenerate.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/regenerate/infra-deploy.regenerate.cli-command.impl.js +99 -0
- package/dist/cli/regenerate/infra-deploy.regenerate.cli-command.impl.js.map +1 -0
- package/dist/cli/rum/infra-rum-status.cli-command.descriptor.d.ts +21 -0
- package/dist/cli/rum/infra-rum-status.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/rum/infra-rum-status.cli-command.descriptor.js +27 -0
- package/dist/cli/rum/infra-rum-status.cli-command.descriptor.js.map +1 -0
- package/dist/cli/rum/infra-rum-status.cli-command.impl.d.ts +12 -0
- package/dist/cli/rum/infra-rum-status.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/rum/infra-rum-status.cli-command.impl.js +88 -0
- package/dist/cli/rum/infra-rum-status.cli-command.impl.js.map +1 -0
- package/dist/cli/rum/infra-rum.cli-group.descriptor.d.ts +12 -0
- package/dist/cli/rum/infra-rum.cli-group.descriptor.d.ts.map +1 -0
- package/dist/cli/rum/infra-rum.cli-group.descriptor.js +12 -0
- package/dist/cli/rum/infra-rum.cli-group.descriptor.js.map +1 -0
- package/dist/cli/run/infra-deploy.run.cli-command.descriptor.d.ts +27 -0
- package/dist/cli/run/infra-deploy.run.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/run/infra-deploy.run.cli-command.descriptor.js +49 -0
- package/dist/cli/run/infra-deploy.run.cli-command.descriptor.js.map +1 -0
- package/dist/cli/run/infra-deploy.run.cli-command.impl.d.ts +5 -0
- package/dist/cli/run/infra-deploy.run.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/run/infra-deploy.run.cli-command.impl.js +272 -0
- package/dist/cli/run/infra-deploy.run.cli-command.impl.js.map +1 -0
- package/dist/cli/shared/discover-deployments.d.ts +41 -0
- package/dist/cli/shared/discover-deployments.d.ts.map +1 -0
- package/dist/cli/shared/discover-deployments.js +95 -0
- package/dist/cli/shared/discover-deployments.js.map +1 -0
- package/dist/config-loader.d.ts +24 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +135 -0
- package/dist/config-loader.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/infra-deploy.plugin.d.ts +3 -0
- package/dist/infra-deploy.plugin.d.ts.map +1 -0
- package/dist/infra-deploy.plugin.js +59 -0
- package/dist/infra-deploy.plugin.js.map +1 -0
- package/dist/regenerate.d.ts +55 -0
- package/dist/regenerate.d.ts.map +1 -0
- package/dist/regenerate.js +206 -0
- package/dist/regenerate.js.map +1 -0
- package/package.json +85 -0
- package/src/cli/alerts/infra-alerts-create.cli-command.descriptor.ts +61 -0
- package/src/cli/alerts/infra-alerts-create.cli-command.impl.ts +131 -0
- package/src/cli/alerts/infra-alerts-delete.cli-command.descriptor.ts +36 -0
- package/src/cli/alerts/infra-alerts-delete.cli-command.impl.ts +75 -0
- package/src/cli/alerts/infra-alerts-list.cli-command.descriptor.ts +27 -0
- package/src/cli/alerts/infra-alerts-list.cli-command.impl.ts +88 -0
- package/src/cli/alerts/infra-alerts.cli-group.descriptor.ts +12 -0
- package/src/cli/audit/infra-audit.cli-command.descriptor.ts +28 -0
- package/src/cli/audit/infra-audit.cli-command.impl.ts +293 -0
- package/src/cli/infra-deploy.cli-group.descriptor.ts +12 -0
- package/src/cli/infra.cli-group.descriptor.ts +11 -0
- package/src/cli/list/infra-deploy.list.cli-command.descriptor.ts +29 -0
- package/src/cli/list/infra-deploy.list.cli-command.impl.ts +125 -0
- package/src/cli/logs/infra-logs.cli-command.descriptor.ts +65 -0
- package/src/cli/logs/infra-logs.cli-command.impl.ts +354 -0
- package/src/cli/logs/stream-worker-tail.ts +202 -0
- package/src/cli/npm/infra-npm-publish.cli-command.descriptor.ts +75 -0
- package/src/cli/npm/infra-npm-publish.cli-command.impl.ts +474 -0
- package/src/cli/npm/infra-npm.cli-group.descriptor.ts +12 -0
- package/src/cli/observability/infra-observability-set.cli-command.descriptor.ts +57 -0
- package/src/cli/observability/infra-observability-set.cli-command.impl.ts +173 -0
- package/src/cli/observability/infra-observability-status.cli-command.descriptor.ts +35 -0
- package/src/cli/observability/infra-observability-status.cli-command.impl.ts +124 -0
- package/src/cli/observability/infra-observability.cli-group.descriptor.ts +12 -0
- package/src/cli/regenerate/infra-deploy.regenerate.cli-command.descriptor.ts +36 -0
- package/src/cli/regenerate/infra-deploy.regenerate.cli-command.impl.ts +103 -0
- package/src/cli/rum/infra-rum-status.cli-command.descriptor.ts +27 -0
- package/src/cli/rum/infra-rum-status.cli-command.impl.ts +112 -0
- package/src/cli/rum/infra-rum.cli-group.descriptor.ts +12 -0
- package/src/cli/run/infra-deploy.run.cli-command.descriptor.ts +49 -0
- package/src/cli/run/infra-deploy.run.cli-command.impl.ts +330 -0
- package/src/cli/shared/discover-deployments.ts +127 -0
- package/src/config-loader.ts +179 -0
- package/src/index.ts +11 -0
- package/src/infra-deploy.plugin.ts +83 -0
- package/src/regenerate.ts +230 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createRuntimePlugin, loader } from '@vibesdotdev/runtime';
|
|
2
|
+
|
|
3
|
+
import infraGroup from './cli/infra.cli-group.descriptor.ts';
|
|
4
|
+
import infraDeployGroup from './cli/infra-deploy.cli-group.descriptor.ts';
|
|
5
|
+
import infraDeployRun from './cli/run/infra-deploy.run.cli-command.descriptor.ts';
|
|
6
|
+
import infraDeployList from './cli/list/infra-deploy.list.cli-command.descriptor.ts';
|
|
7
|
+
import infraDeployRegenerate from './cli/regenerate/infra-deploy.regenerate.cli-command.descriptor.ts';
|
|
8
|
+
import infraLogs from './cli/logs/infra-logs.cli-command.descriptor.ts';
|
|
9
|
+
import infraNpmGroup from './cli/npm/infra-npm.cli-group.descriptor.ts';
|
|
10
|
+
import infraNpmPublish from './cli/npm/infra-npm-publish.cli-command.descriptor.ts';
|
|
11
|
+
import infraAlertsGroup from './cli/alerts/infra-alerts.cli-group.descriptor.ts';
|
|
12
|
+
import infraAlertsList from './cli/alerts/infra-alerts-list.cli-command.descriptor.ts';
|
|
13
|
+
import infraAlertsCreate from './cli/alerts/infra-alerts-create.cli-command.descriptor.ts';
|
|
14
|
+
import infraAlertsDelete from './cli/alerts/infra-alerts-delete.cli-command.descriptor.ts';
|
|
15
|
+
import infraAudit from './cli/audit/infra-audit.cli-command.descriptor.ts';
|
|
16
|
+
import infraObservabilityGroup from './cli/observability/infra-observability.cli-group.descriptor.ts';
|
|
17
|
+
import infraObservabilityStatus from './cli/observability/infra-observability-status.cli-command.descriptor.ts';
|
|
18
|
+
import infraObservabilitySet from './cli/observability/infra-observability-set.cli-command.descriptor.ts';
|
|
19
|
+
import infraRumGroup from './cli/rum/infra-rum.cli-group.descriptor.ts';
|
|
20
|
+
import infraRumStatus from './cli/rum/infra-rum-status.cli-command.descriptor.ts';
|
|
21
|
+
|
|
22
|
+
export default createRuntimePlugin({
|
|
23
|
+
id: 'infra-deploy',
|
|
24
|
+
name: 'Infra Deploy',
|
|
25
|
+
description: 'Build and deploy apps declared in deployment.config.ts',
|
|
26
|
+
|
|
27
|
+
descriptors: [
|
|
28
|
+
infraGroup,
|
|
29
|
+
infraDeployGroup,
|
|
30
|
+
infraDeployRun,
|
|
31
|
+
infraDeployList,
|
|
32
|
+
infraDeployRegenerate,
|
|
33
|
+
infraLogs,
|
|
34
|
+
infraNpmGroup,
|
|
35
|
+
infraNpmPublish,
|
|
36
|
+
infraAlertsGroup,
|
|
37
|
+
infraAlertsList,
|
|
38
|
+
infraAlertsCreate,
|
|
39
|
+
infraAlertsDelete,
|
|
40
|
+
infraAudit,
|
|
41
|
+
infraObservabilityGroup,
|
|
42
|
+
infraObservabilityStatus,
|
|
43
|
+
infraObservabilitySet,
|
|
44
|
+
infraRumGroup,
|
|
45
|
+
infraRumStatus
|
|
46
|
+
],
|
|
47
|
+
|
|
48
|
+
loaders: [
|
|
49
|
+
loader('infra-deploy.run', () => import('./cli/run/infra-deploy.run.cli-command.impl.ts')),
|
|
50
|
+
loader('infra-deploy.list', () => import('./cli/list/infra-deploy.list.cli-command.impl.ts')),
|
|
51
|
+
loader(
|
|
52
|
+
'infra-deploy.regenerate',
|
|
53
|
+
() => import('./cli/regenerate/infra-deploy.regenerate.cli-command.impl.ts')
|
|
54
|
+
),
|
|
55
|
+
loader('infra-logs', () => import('./cli/logs/infra-logs.cli-command.impl.ts')),
|
|
56
|
+
loader(
|
|
57
|
+
'infra-npm.publish',
|
|
58
|
+
() => import('./cli/npm/infra-npm-publish.cli-command.impl.ts')
|
|
59
|
+
),
|
|
60
|
+
loader(
|
|
61
|
+
'infra-alerts.list',
|
|
62
|
+
() => import('./cli/alerts/infra-alerts-list.cli-command.impl.ts')
|
|
63
|
+
),
|
|
64
|
+
loader(
|
|
65
|
+
'infra-alerts.create',
|
|
66
|
+
() => import('./cli/alerts/infra-alerts-create.cli-command.impl.ts')
|
|
67
|
+
),
|
|
68
|
+
loader(
|
|
69
|
+
'infra-alerts.delete',
|
|
70
|
+
() => import('./cli/alerts/infra-alerts-delete.cli-command.impl.ts')
|
|
71
|
+
),
|
|
72
|
+
loader('infra-audit', () => import('./cli/audit/infra-audit.cli-command.impl.ts')),
|
|
73
|
+
loader(
|
|
74
|
+
'infra-observability.status',
|
|
75
|
+
() => import('./cli/observability/infra-observability-status.cli-command.impl.ts')
|
|
76
|
+
),
|
|
77
|
+
loader(
|
|
78
|
+
'infra-observability.set',
|
|
79
|
+
() => import('./cli/observability/infra-observability-set.cli-command.impl.ts')
|
|
80
|
+
),
|
|
81
|
+
loader('infra-rum.status', () => import('./cli/rum/infra-rum-status.cli-command.impl.ts'))
|
|
82
|
+
]
|
|
83
|
+
});
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wrangler.jsonc regeneration orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Reads an app's `deployment.config.ts` (via the config-loader subprocess,
|
|
5
|
+
* which surfaces the canonical wrangler.jsonc string from
|
|
6
|
+
* `@vibesdotdev/infra-cloudflare/regen` when the export is a managed
|
|
7
|
+
* web-app deployment), compares it against the on-disk `wrangler.jsonc`,
|
|
8
|
+
* and either reports drift or rewrites the file.
|
|
9
|
+
*
|
|
10
|
+
* Two modes:
|
|
11
|
+
* - `check` — read-only; returns `'drift'` when the on-disk file
|
|
12
|
+
* doesn't match the rendered string. Used by CI and pre-deploy gates.
|
|
13
|
+
* - `write` — overwrites the on-disk file with the rendered string.
|
|
14
|
+
* Used during local development after editing `deployment.config.ts`.
|
|
15
|
+
*
|
|
16
|
+
* Apps that haven't opted in via `managed: true` are reported as
|
|
17
|
+
* `'skipped'` — neither check nor write happens. Once every app is on
|
|
18
|
+
* the regen pipeline, the `managed` flag can be defaulted true and the
|
|
19
|
+
* skipped path removed.
|
|
20
|
+
*
|
|
21
|
+
* Provider dispatch is implicit: only Cloudflare web-app deployments
|
|
22
|
+
* currently surface a `wranglerJsoncString`. Other providers (DO App
|
|
23
|
+
* Spec) skip regen by construction.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
27
|
+
import { join, relative, resolve } from 'node:path';
|
|
28
|
+
import { loadDeploymentConfig } from './config-loader.ts';
|
|
29
|
+
|
|
30
|
+
export type RegenStatus = 'unchanged' | 'updated' | 'drift' | 'skipped' | 'error';
|
|
31
|
+
|
|
32
|
+
export interface RegenResult {
|
|
33
|
+
appId: string;
|
|
34
|
+
appDir: string;
|
|
35
|
+
wranglerJsoncPath: string;
|
|
36
|
+
status: RegenStatus;
|
|
37
|
+
/** Workers script name, when known. */
|
|
38
|
+
workerName?: string;
|
|
39
|
+
/** Reason text for 'skipped' (e.g., "not managed") or 'error'. */
|
|
40
|
+
reason?: string;
|
|
41
|
+
/** Unified diff snippet on `drift`. Truncated to ~120 lines. */
|
|
42
|
+
diff?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface RegenerateOptions {
|
|
46
|
+
/** `check`: read-only drift detection. `write`: rewrite on drift. */
|
|
47
|
+
mode: 'check' | 'write';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const CONFIG_FILENAMES = new Set([
|
|
51
|
+
'deployment.config.ts',
|
|
52
|
+
'deployment.config.js',
|
|
53
|
+
'deployment.config.mjs'
|
|
54
|
+
]);
|
|
55
|
+
const IGNORED_DIRS = new Set([
|
|
56
|
+
'node_modules',
|
|
57
|
+
'.git',
|
|
58
|
+
'.svelte-kit',
|
|
59
|
+
'dist',
|
|
60
|
+
'.next',
|
|
61
|
+
'.turbo',
|
|
62
|
+
'.vite',
|
|
63
|
+
'.wrangler'
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Recursive discovery for `deployment.config.ts` under `root`. Mirrors
|
|
68
|
+
* the `infra deploy list` walker (kept private here to avoid a circular
|
|
69
|
+
* dep through the CLI command). Synchronous because the orchestrator
|
|
70
|
+
* is called from short-lived processes (deploy hooks + CLI).
|
|
71
|
+
*/
|
|
72
|
+
function findDeploymentConfigs(root: string, maxDepth = 4): string[] {
|
|
73
|
+
const found: string[] = [];
|
|
74
|
+
function walk(dir: string, depth: number): void {
|
|
75
|
+
if (depth > maxDepth) return;
|
|
76
|
+
let entries: string[];
|
|
77
|
+
try {
|
|
78
|
+
entries = readdirSync(dir);
|
|
79
|
+
} catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const entry of entries) {
|
|
83
|
+
if (CONFIG_FILENAMES.has(entry)) {
|
|
84
|
+
found.push(join(dir, entry));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
if (IGNORED_DIRS.has(entry) || entry.startsWith('.')) continue;
|
|
89
|
+
const full = join(dir, entry);
|
|
90
|
+
let info;
|
|
91
|
+
try {
|
|
92
|
+
info = statSync(full);
|
|
93
|
+
} catch {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (info.isDirectory()) walk(full, depth + 1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
walk(root, 0);
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function unifiedDiffSnippet(existing: string, rendered: string, contextLines = 3): string {
|
|
104
|
+
// Compact line-by-line diff. Not a full unified-diff (no @@ hunks),
|
|
105
|
+
// just enough for a human to spot the drift in a CI log without
|
|
106
|
+
// pulling in a diff library. Caps total output at ~120 lines.
|
|
107
|
+
const a = existing.split('\n');
|
|
108
|
+
const b = rendered.split('\n');
|
|
109
|
+
const max = Math.max(a.length, b.length);
|
|
110
|
+
const lines: string[] = [];
|
|
111
|
+
let lastShown = -contextLines - 1;
|
|
112
|
+
for (let i = 0; i < max; i++) {
|
|
113
|
+
const left = a[i];
|
|
114
|
+
const right = b[i];
|
|
115
|
+
if (left === right) continue;
|
|
116
|
+
// Backfill context above first change.
|
|
117
|
+
for (let j = Math.max(lastShown + 1, i - contextLines); j < i; j++) {
|
|
118
|
+
if (lines.length >= 120) break;
|
|
119
|
+
lines.push(` ${a[j] ?? ''}`);
|
|
120
|
+
}
|
|
121
|
+
if (lines.length >= 120) break;
|
|
122
|
+
if (left !== undefined) lines.push(`- ${left}`);
|
|
123
|
+
if (right !== undefined) lines.push(`+ ${right}`);
|
|
124
|
+
lastShown = i;
|
|
125
|
+
}
|
|
126
|
+
if (lines.length === 0) return '';
|
|
127
|
+
return lines.join('\n');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Regenerate (or check) a single app's wrangler.jsonc. The caller
|
|
132
|
+
* passes the app directory containing `deployment.config.ts`.
|
|
133
|
+
*/
|
|
134
|
+
export async function regenerateApp(
|
|
135
|
+
appDir: string,
|
|
136
|
+
options: RegenerateOptions
|
|
137
|
+
): Promise<RegenResult> {
|
|
138
|
+
const absoluteAppDir = resolve(appDir);
|
|
139
|
+
const wranglerJsoncPath = join(absoluteAppDir, 'wrangler.jsonc');
|
|
140
|
+
let loaded;
|
|
141
|
+
try {
|
|
142
|
+
loaded = await loadDeploymentConfig(absoluteAppDir);
|
|
143
|
+
} catch (err) {
|
|
144
|
+
return {
|
|
145
|
+
appId: relative(process.cwd(), absoluteAppDir) || '.',
|
|
146
|
+
appDir: absoluteAppDir,
|
|
147
|
+
wranglerJsoncPath,
|
|
148
|
+
status: 'error',
|
|
149
|
+
reason: `Failed to load deployment.config: ${(err as Error).message}`
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const appId = loaded.deployment.appId;
|
|
154
|
+
const workerName = loaded.workerName ?? undefined;
|
|
155
|
+
|
|
156
|
+
if (!loaded.managed || loaded.wranglerJsoncString === null) {
|
|
157
|
+
return {
|
|
158
|
+
appId,
|
|
159
|
+
appDir: absoluteAppDir,
|
|
160
|
+
wranglerJsoncPath,
|
|
161
|
+
status: 'skipped',
|
|
162
|
+
workerName,
|
|
163
|
+
reason: loaded.managed
|
|
164
|
+
? 'deployment is not a managed Cloudflare web-app'
|
|
165
|
+
: 'deployment.config.ts does not opt in via managed: true'
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const rendered = loaded.wranglerJsoncString;
|
|
170
|
+
const existing = existsSync(wranglerJsoncPath)
|
|
171
|
+
? readFileSync(wranglerJsoncPath, 'utf-8')
|
|
172
|
+
: null;
|
|
173
|
+
|
|
174
|
+
if (existing === rendered) {
|
|
175
|
+
return {
|
|
176
|
+
appId,
|
|
177
|
+
appDir: absoluteAppDir,
|
|
178
|
+
wranglerJsoncPath,
|
|
179
|
+
status: 'unchanged',
|
|
180
|
+
workerName
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (options.mode === 'check') {
|
|
185
|
+
return {
|
|
186
|
+
appId,
|
|
187
|
+
appDir: absoluteAppDir,
|
|
188
|
+
wranglerJsoncPath,
|
|
189
|
+
status: 'drift',
|
|
190
|
+
workerName,
|
|
191
|
+
diff: existing === null ? '(no existing wrangler.jsonc)' : unifiedDiffSnippet(existing, rendered)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
writeFileSync(wranglerJsoncPath, rendered, 'utf-8');
|
|
196
|
+
return {
|
|
197
|
+
appId,
|
|
198
|
+
appDir: absoluteAppDir,
|
|
199
|
+
wranglerJsoncPath,
|
|
200
|
+
status: 'updated',
|
|
201
|
+
workerName
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Regenerate (or check) every `deployment.config.ts` under `root`.
|
|
207
|
+
* Non-managed deployments report `'skipped'`; the caller decides
|
|
208
|
+
* whether to treat skips as failure (typically: no).
|
|
209
|
+
*/
|
|
210
|
+
export async function regenerateAll(
|
|
211
|
+
root: string,
|
|
212
|
+
options: RegenerateOptions
|
|
213
|
+
): Promise<RegenResult[]> {
|
|
214
|
+
const configPaths = findDeploymentConfigs(resolve(root));
|
|
215
|
+
const results: RegenResult[] = [];
|
|
216
|
+
for (const configPath of configPaths) {
|
|
217
|
+
const appDir = configPath.replace(/\/deployment\.config\.(ts|js|mjs)$/, '');
|
|
218
|
+
results.push(await regenerateApp(appDir, options));
|
|
219
|
+
}
|
|
220
|
+
return results;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Exit code logic for CLI / CI use. */
|
|
224
|
+
export function regenExitCode(results: RegenResult[], mode: 'check' | 'write'): number {
|
|
225
|
+
for (const r of results) {
|
|
226
|
+
if (r.status === 'error') return 1;
|
|
227
|
+
if (mode === 'check' && r.status === 'drift') return 1;
|
|
228
|
+
}
|
|
229
|
+
return 0;
|
|
230
|
+
}
|