@treeseed/cli 0.1.1 → 0.4.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 +27 -26
- package/dist/cli/handlers/auth-login.d.ts +2 -0
- package/dist/cli/handlers/auth-login.js +67 -0
- package/dist/cli/handlers/auth-logout.d.ts +2 -0
- package/dist/cli/handlers/auth-logout.js +20 -0
- package/dist/cli/handlers/auth-whoami.d.ts +2 -0
- package/dist/cli/handlers/auth-whoami.js +24 -0
- package/dist/cli/handlers/close.js +19 -53
- package/dist/cli/handlers/config.js +33 -53
- package/dist/cli/handlers/destroy.js +34 -79
- package/dist/{src/cli/handlers/ship.d.ts → cli/handlers/dev.d.ts} +1 -1
- package/dist/cli/handlers/dev.js +19 -0
- package/dist/cli/handlers/doctor.js +13 -6
- package/dist/cli/handlers/init.js +32 -8
- package/dist/cli/handlers/release.js +21 -53
- package/dist/cli/handlers/rollback.js +8 -8
- package/dist/cli/handlers/save.js +21 -79
- package/dist/cli/handlers/stage.d.ts +2 -0
- package/dist/cli/handlers/stage.js +28 -0
- package/dist/cli/handlers/status.js +35 -26
- package/dist/{src/cli/handlers/deploy.d.ts → cli/handlers/switch.d.ts} +1 -1
- package/dist/cli/handlers/switch.js +29 -0
- package/dist/{src/cli/handlers/next.d.ts → cli/handlers/sync.d.ts} +1 -1
- package/dist/cli/handlers/sync.js +26 -0
- package/dist/cli/handlers/tasks.d.ts +2 -0
- package/dist/cli/handlers/tasks.js +31 -0
- package/dist/cli/handlers/template.d.ts +2 -0
- package/dist/cli/handlers/template.js +27 -0
- package/dist/cli/handlers/workflow.d.ts +6 -0
- package/dist/cli/handlers/workflow.js +71 -0
- package/dist/{src/cli → cli}/help.d.ts +2 -2
- package/dist/cli/help.js +36 -24
- package/dist/cli/main.d.ts +6 -0
- package/dist/cli/main.js +14 -19
- package/dist/cli/operations-help.d.ts +1 -0
- package/dist/cli/operations-help.js +1 -0
- package/dist/cli/operations-parser.d.ts +1 -0
- package/dist/cli/operations-parser.js +1 -0
- package/dist/cli/operations-registry.d.ts +5 -0
- package/dist/cli/operations-registry.js +260 -0
- package/dist/cli/operations-types.d.ts +72 -0
- package/dist/cli/parser.d.ts +3 -0
- package/dist/cli/parser.js +1 -6
- package/dist/cli/registry.d.ts +25 -0
- package/dist/cli/registry.js +28 -416
- package/dist/cli/repair.js +6 -4
- package/dist/cli/runtime.d.ts +31 -0
- package/dist/cli/runtime.js +240 -111
- package/dist/cli/types.d.ts +1 -0
- package/dist/{src/cli → cli}/workflow-state.d.ts +9 -0
- package/dist/cli/workflow-state.js +45 -21
- package/package.json +13 -13
- package/dist/cli/handlers/continue.js +0 -23
- package/dist/cli/handlers/deploy.js +0 -139
- package/dist/cli/handlers/next.js +0 -27
- package/dist/cli/handlers/prepare.js +0 -8
- package/dist/cli/handlers/promote.js +0 -8
- package/dist/cli/handlers/publish.js +0 -8
- package/dist/cli/handlers/setup.js +0 -48
- package/dist/cli/handlers/ship.js +0 -49
- package/dist/cli/handlers/start.js +0 -97
- package/dist/cli/handlers/teardown.js +0 -50
- package/dist/cli/handlers/work.js +0 -85
- package/dist/scripts/aggregate-book.d.ts +0 -1
- package/dist/scripts/aggregate-book.js +0 -121
- package/dist/scripts/assert-release-tag-version.d.ts +0 -1
- package/dist/scripts/assert-release-tag-version.js +0 -21
- package/dist/scripts/build-dist.d.ts +0 -1
- package/dist/scripts/build-dist.js +0 -108
- package/dist/scripts/build-tenant-worker.d.ts +0 -1
- package/dist/scripts/build-tenant-worker.js +0 -36
- package/dist/scripts/cleanup-markdown.d.ts +0 -2
- package/dist/scripts/cleanup-markdown.js +0 -373
- package/dist/scripts/config-runtime-lib.d.ts +0 -122
- package/dist/scripts/config-runtime-lib.js +0 -505
- package/dist/scripts/config-treeseed.d.ts +0 -2
- package/dist/scripts/config-treeseed.js +0 -81
- package/dist/scripts/d1-migration-lib.d.ts +0 -6
- package/dist/scripts/d1-migration-lib.js +0 -90
- package/dist/scripts/deploy-lib.d.ts +0 -127
- package/dist/scripts/deploy-lib.js +0 -841
- package/dist/scripts/ensure-mailpit.d.ts +0 -1
- package/dist/scripts/ensure-mailpit.js +0 -29
- package/dist/scripts/git-workflow-lib.d.ts +0 -25
- package/dist/scripts/git-workflow-lib.js +0 -136
- package/dist/scripts/github-automation-lib.d.ts +0 -156
- package/dist/scripts/github-automation-lib.js +0 -242
- package/dist/scripts/local-dev-lib.d.ts +0 -9
- package/dist/scripts/local-dev-lib.js +0 -84
- package/dist/scripts/local-dev.d.ts +0 -1
- package/dist/scripts/local-dev.js +0 -129
- package/dist/scripts/logs-mailpit.d.ts +0 -1
- package/dist/scripts/logs-mailpit.js +0 -2
- package/dist/scripts/mailpit-runtime.d.ts +0 -4
- package/dist/scripts/mailpit-runtime.js +0 -57
- package/dist/scripts/package-tools.d.ts +0 -22
- package/dist/scripts/package-tools.js +0 -255
- package/dist/scripts/patch-starlight-content-path.d.ts +0 -1
- package/dist/scripts/patch-starlight-content-path.js +0 -172
- package/dist/scripts/paths.d.ts +0 -17
- package/dist/scripts/paths.js +0 -26
- package/dist/scripts/publish-package.d.ts +0 -1
- package/dist/scripts/publish-package.js +0 -19
- package/dist/scripts/release-verify.d.ts +0 -1
- package/dist/scripts/release-verify.js +0 -136
- package/dist/scripts/run-fixture-astro-command.d.ts +0 -1
- package/dist/scripts/run-fixture-astro-command.js +0 -18
- package/dist/scripts/save-deploy-preflight-lib.d.ts +0 -34
- package/dist/scripts/save-deploy-preflight-lib.js +0 -69
- package/dist/scripts/scaffold-site.d.ts +0 -2
- package/dist/scripts/scaffold-site.js +0 -92
- package/dist/scripts/stop-mailpit.d.ts +0 -1
- package/dist/scripts/stop-mailpit.js +0 -5
- package/dist/scripts/sync-dev-vars.d.ts +0 -1
- package/dist/scripts/sync-dev-vars.js +0 -6
- package/dist/scripts/template-registry-lib.d.ts +0 -47
- package/dist/scripts/template-registry-lib.js +0 -137
- package/dist/scripts/tenant-astro-command.d.ts +0 -1
- package/dist/scripts/tenant-astro-command.js +0 -3
- package/dist/scripts/tenant-build.d.ts +0 -1
- package/dist/scripts/tenant-build.js +0 -16
- package/dist/scripts/tenant-check.d.ts +0 -1
- package/dist/scripts/tenant-check.js +0 -7
- package/dist/scripts/tenant-d1-migrate-local.d.ts +0 -1
- package/dist/scripts/tenant-d1-migrate-local.js +0 -11
- package/dist/scripts/tenant-deploy.d.ts +0 -2
- package/dist/scripts/tenant-deploy.js +0 -180
- package/dist/scripts/tenant-destroy.d.ts +0 -2
- package/dist/scripts/tenant-destroy.js +0 -104
- package/dist/scripts/tenant-dev.d.ts +0 -1
- package/dist/scripts/tenant-dev.js +0 -171
- package/dist/scripts/tenant-lint.d.ts +0 -1
- package/dist/scripts/tenant-lint.js +0 -4
- package/dist/scripts/tenant-test.d.ts +0 -1
- package/dist/scripts/tenant-test.js +0 -4
- package/dist/scripts/test-cloudflare-local.d.ts +0 -1
- package/dist/scripts/test-cloudflare-local.js +0 -212
- package/dist/scripts/test-scaffold.d.ts +0 -2
- package/dist/scripts/test-scaffold.js +0 -297
- package/dist/scripts/treeseed.d.ts +0 -2
- package/dist/scripts/treeseed.js +0 -4
- package/dist/scripts/validate-templates.d.ts +0 -2
- package/dist/scripts/validate-templates.js +0 -4
- package/dist/scripts/watch-dev-lib.d.ts +0 -21
- package/dist/scripts/watch-dev-lib.js +0 -277
- package/dist/scripts/workspace-close.d.ts +0 -2
- package/dist/scripts/workspace-close.js +0 -24
- package/dist/scripts/workspace-command-e2e.d.ts +0 -2
- package/dist/scripts/workspace-command-e2e.js +0 -718
- package/dist/scripts/workspace-lint.d.ts +0 -1
- package/dist/scripts/workspace-lint.js +0 -9
- package/dist/scripts/workspace-preflight-lib.d.ts +0 -36
- package/dist/scripts/workspace-preflight-lib.js +0 -179
- package/dist/scripts/workspace-preflight.d.ts +0 -2
- package/dist/scripts/workspace-preflight.js +0 -22
- package/dist/scripts/workspace-publish-changed-packages.d.ts +0 -1
- package/dist/scripts/workspace-publish-changed-packages.js +0 -16
- package/dist/scripts/workspace-release-verify.d.ts +0 -1
- package/dist/scripts/workspace-release-verify.js +0 -81
- package/dist/scripts/workspace-release.d.ts +0 -2
- package/dist/scripts/workspace-release.js +0 -42
- package/dist/scripts/workspace-save-lib.d.ts +0 -42
- package/dist/scripts/workspace-save-lib.js +0 -220
- package/dist/scripts/workspace-save.d.ts +0 -2
- package/dist/scripts/workspace-save.js +0 -124
- package/dist/scripts/workspace-start-warning.js +0 -3
- package/dist/scripts/workspace-start.d.ts +0 -2
- package/dist/scripts/workspace-start.js +0 -71
- package/dist/scripts/workspace-test-unit.d.ts +0 -1
- package/dist/scripts/workspace-test-unit.js +0 -4
- package/dist/scripts/workspace-test.d.ts +0 -1
- package/dist/scripts/workspace-test.js +0 -11
- package/dist/scripts/workspace-tools.d.ts +0 -13
- package/dist/scripts/workspace-tools.js +0 -226
- package/dist/src/cli/handlers/continue.d.ts +0 -2
- package/dist/src/cli/handlers/prepare.d.ts +0 -2
- package/dist/src/cli/handlers/promote.d.ts +0 -2
- package/dist/src/cli/handlers/publish.d.ts +0 -2
- package/dist/src/cli/handlers/setup.d.ts +0 -2
- package/dist/src/cli/handlers/start.d.ts +0 -3
- package/dist/src/cli/handlers/teardown.d.ts +0 -2
- package/dist/src/cli/handlers/work.d.ts +0 -2
- package/dist/src/cli/main.d.ts +0 -6
- package/dist/src/cli/parser.d.ts +0 -3
- package/dist/src/cli/registry.d.ts +0 -27
- package/dist/src/cli/runtime.d.ts +0 -4
- package/dist/src/cli/types.d.ts +0 -71
- /package/dist/{src/cli → cli}/handlers/close.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/config.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/destroy.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/doctor.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/init.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/release.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/rollback.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/save.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/status.d.ts +0 -0
- /package/dist/{src/cli → cli}/handlers/utils.d.ts +0 -0
- /package/dist/{scripts/workspace-start-warning.d.ts → cli/operations-types.js} +0 -0
- /package/dist/{src/cli → cli}/repair.d.ts +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
import { runLocalD1Migrations } from './d1-migration-lib.js';
|
|
3
|
-
import { ensureGeneratedWranglerConfig } from './deploy-lib.js';
|
|
4
|
-
const tenantRoot = process.cwd();
|
|
5
|
-
const migrationsRoot = resolve(tenantRoot, 'migrations');
|
|
6
|
-
const { wranglerPath: wranglerConfig } = ensureGeneratedWranglerConfig(tenantRoot);
|
|
7
|
-
runLocalD1Migrations({
|
|
8
|
-
cwd: tenantRoot,
|
|
9
|
-
wranglerConfig,
|
|
10
|
-
migrationsRoot,
|
|
11
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { dirname, resolve } from 'node:path';
|
|
5
|
-
import { applyTreeseedEnvironmentToProcess } from './config-runtime-lib.js';
|
|
6
|
-
import { assertDeploymentInitialized, createBranchPreviewDeployTarget, createPersistentDeployTarget, deployTargetLabel, ensureGeneratedWranglerConfig, finalizeDeploymentState, runRemoteD1Migrations, } from './deploy-lib.js';
|
|
7
|
-
import { currentManagedBranch, PRODUCTION_BRANCH, STAGING_BRANCH } from './git-workflow-lib.js';
|
|
8
|
-
import { packageScriptPath, resolveWranglerBin } from './package-tools.js';
|
|
9
|
-
import { runTenantDeployPreflight } from './save-deploy-preflight-lib.js';
|
|
10
|
-
const tenantRoot = process.cwd();
|
|
11
|
-
const args = process.argv.slice(2);
|
|
12
|
-
function writeDeployReport(payload) {
|
|
13
|
-
const target = process.env.TREESEED_DEPLOY_REPORT_PATH;
|
|
14
|
-
if (!target) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const filePath = resolve(target);
|
|
18
|
-
mkdirSync(dirname(filePath), { recursive: true });
|
|
19
|
-
writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}\n`, 'utf8');
|
|
20
|
-
}
|
|
21
|
-
function parseArgs(argv) {
|
|
22
|
-
const parsed = {
|
|
23
|
-
dryRun: false,
|
|
24
|
-
only: null,
|
|
25
|
-
name: null,
|
|
26
|
-
environment: null,
|
|
27
|
-
targetBranch: null,
|
|
28
|
-
};
|
|
29
|
-
const rest = [...argv];
|
|
30
|
-
while (rest.length) {
|
|
31
|
-
const current = rest.shift();
|
|
32
|
-
if (!current)
|
|
33
|
-
continue;
|
|
34
|
-
if (current === '--dry-run') {
|
|
35
|
-
parsed.dryRun = true;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (current === '--only') {
|
|
39
|
-
parsed.only = rest.shift() ?? null;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (current === '--name') {
|
|
43
|
-
parsed.name = rest.shift() ?? null;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (current === '--environment') {
|
|
47
|
-
parsed.environment = rest.shift() ?? null;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (current.startsWith('--environment=')) {
|
|
51
|
-
parsed.environment = current.split('=', 2)[1] ?? null;
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (current === '--target-branch') {
|
|
55
|
-
parsed.targetBranch = rest.shift() ?? null;
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (current.startsWith('--target-branch=')) {
|
|
59
|
-
parsed.targetBranch = current.split('=', 2)[1] ?? null;
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
throw new Error(`Unknown deploy argument: ${current}`);
|
|
63
|
-
}
|
|
64
|
-
return parsed;
|
|
65
|
-
}
|
|
66
|
-
function inferEnvironmentFromBranch() {
|
|
67
|
-
const branch = currentManagedBranch(tenantRoot);
|
|
68
|
-
if (branch === STAGING_BRANCH) {
|
|
69
|
-
return 'staging';
|
|
70
|
-
}
|
|
71
|
-
if (branch === PRODUCTION_BRANCH) {
|
|
72
|
-
return 'prod';
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
function resolveTarget(options) {
|
|
77
|
-
if (options.targetBranch) {
|
|
78
|
-
return {
|
|
79
|
-
target: createBranchPreviewDeployTarget(options.targetBranch),
|
|
80
|
-
scope: 'staging',
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
const environment = options.environment ?? (process.env.CI ? inferEnvironmentFromBranch() : null);
|
|
84
|
-
if (!environment) {
|
|
85
|
-
throw new Error('Treeseed deploy requires `--environment local|staging|prod` outside CI.');
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
target: createPersistentDeployTarget(environment),
|
|
89
|
-
scope: environment,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function runNodeScript(scriptPath, scriptArgs = [], env = {}) {
|
|
93
|
-
const result = spawnSync(process.execPath, [scriptPath, ...scriptArgs], {
|
|
94
|
-
stdio: 'inherit',
|
|
95
|
-
cwd: tenantRoot,
|
|
96
|
-
env: { ...process.env, ...env },
|
|
97
|
-
});
|
|
98
|
-
if (result.status !== 0) {
|
|
99
|
-
process.exit(result.status ?? 1);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function runWranglerDeploy(configPath) {
|
|
103
|
-
const result = spawnSync(process.execPath, [resolveWranglerBin(), 'deploy', '--config', configPath], {
|
|
104
|
-
stdio: 'inherit',
|
|
105
|
-
cwd: tenantRoot,
|
|
106
|
-
env: { ...process.env },
|
|
107
|
-
});
|
|
108
|
-
if (result.status !== 0) {
|
|
109
|
-
process.exit(result.status ?? 1);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async function main() {
|
|
113
|
-
const options = parseArgs(args);
|
|
114
|
-
const { target, scope } = resolveTarget(options);
|
|
115
|
-
applyTreeseedEnvironmentToProcess({ tenantRoot, scope });
|
|
116
|
-
const allowedSteps = new Set(['migrate', 'build', 'publish']);
|
|
117
|
-
if (options.only && !allowedSteps.has(options.only)) {
|
|
118
|
-
throw new Error(`Unsupported deploy step "${options.only}". Expected one of ${[...allowedSteps].join(', ')}.`);
|
|
119
|
-
}
|
|
120
|
-
const shouldRun = (step) => !options.only || options.only === step;
|
|
121
|
-
if (options.name) {
|
|
122
|
-
console.log(`Deploy target label: ${options.name}`);
|
|
123
|
-
}
|
|
124
|
-
if (scope === 'local') {
|
|
125
|
-
runTenantDeployPreflight({ cwd: tenantRoot, scope: 'local' });
|
|
126
|
-
runNodeScript(packageScriptPath('tenant-build'));
|
|
127
|
-
writeDeployReport({ ok: true, kind: 'success', scope, dryRun: options.dryRun, target: deployTargetLabel(target) });
|
|
128
|
-
console.log('Treeseed local deploy completed as a build-only publish target.');
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
assertDeploymentInitialized(tenantRoot, { target });
|
|
133
|
-
runTenantDeployPreflight({ cwd: tenantRoot, scope });
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
writeDeployReport({
|
|
137
|
-
ok: false,
|
|
138
|
-
kind: 'preflight_failed',
|
|
139
|
-
target: deployTargetLabel(target),
|
|
140
|
-
message: error instanceof Error ? error.message : String(error),
|
|
141
|
-
});
|
|
142
|
-
throw error;
|
|
143
|
-
}
|
|
144
|
-
const { wranglerPath } = ensureGeneratedWranglerConfig(tenantRoot, { target });
|
|
145
|
-
if (shouldRun('migrate')) {
|
|
146
|
-
const result = runRemoteD1Migrations(tenantRoot, { dryRun: options.dryRun, target });
|
|
147
|
-
console.log(`${options.dryRun ? 'Planned' : 'Applied'} remote migrations for ${result.databaseName}.`);
|
|
148
|
-
}
|
|
149
|
-
if (shouldRun('build')) {
|
|
150
|
-
if (options.dryRun) {
|
|
151
|
-
console.log('Dry run: skipped tenant build.');
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
runNodeScript(packageScriptPath('tenant-build'));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (shouldRun('publish')) {
|
|
158
|
-
if (options.dryRun) {
|
|
159
|
-
console.log(`Dry run: would deploy ${deployTargetLabel(target)} with generated Wrangler config at ${resolve(wranglerPath)}.`);
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
runWranglerDeploy(wranglerPath);
|
|
163
|
-
finalizeDeploymentState(tenantRoot, { target });
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
writeDeployReport({
|
|
167
|
-
ok: true,
|
|
168
|
-
kind: 'success',
|
|
169
|
-
dryRun: options.dryRun,
|
|
170
|
-
only: options.only,
|
|
171
|
-
target: deployTargetLabel(target),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
try {
|
|
175
|
-
await main();
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
179
|
-
process.exit(1);
|
|
180
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import readline from 'node:readline/promises';
|
|
3
|
-
import { stdin as input, stdout as output } from 'node:process';
|
|
4
|
-
import { applyTreeseedEnvironmentToProcess, assertTreeseedCommandEnvironment } from './config-runtime-lib.js';
|
|
5
|
-
import { cleanupDestroyedState, createPersistentDeployTarget, destroyCloudflareResources, loadDeployState, printDestroySummary, validateDestroyPrerequisites, } from './deploy-lib.js';
|
|
6
|
-
import { deriveCloudflareWorkerName } from '@treeseed/core/deploy/config';
|
|
7
|
-
const tenantRoot = process.cwd();
|
|
8
|
-
function parseArgs(argv) {
|
|
9
|
-
const parsed = {
|
|
10
|
-
dryRun: false,
|
|
11
|
-
force: false,
|
|
12
|
-
skipConfirmation: false,
|
|
13
|
-
confirm: null,
|
|
14
|
-
removeBuildArtifacts: false,
|
|
15
|
-
environment: null,
|
|
16
|
-
};
|
|
17
|
-
const rest = [...argv];
|
|
18
|
-
while (rest.length) {
|
|
19
|
-
const current = rest.shift();
|
|
20
|
-
if (!current)
|
|
21
|
-
continue;
|
|
22
|
-
if (current === '--dry-run') {
|
|
23
|
-
parsed.dryRun = true;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (current === '--force') {
|
|
27
|
-
parsed.force = true;
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (current === '--skip-confirmation') {
|
|
31
|
-
parsed.skipConfirmation = true;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (current === '--confirm') {
|
|
35
|
-
parsed.confirm = rest.shift() ?? null;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (current === '--remove-build-artifacts') {
|
|
39
|
-
parsed.removeBuildArtifacts = true;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (current === '--environment') {
|
|
43
|
-
parsed.environment = rest.shift() ?? null;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (current.startsWith('--environment=')) {
|
|
47
|
-
parsed.environment = current.split('=', 2)[1] ?? null;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
throw new Error(`Unknown destroy argument: ${current}`);
|
|
51
|
-
}
|
|
52
|
-
return parsed;
|
|
53
|
-
}
|
|
54
|
-
function getExpectedConfirmation(deployConfig) {
|
|
55
|
-
return deployConfig.slug;
|
|
56
|
-
}
|
|
57
|
-
function printDangerMessage(deployConfig, state, expectedConfirmation) {
|
|
58
|
-
console.error('DANGER: treeseed destroy will permanently delete this site and its Cloudflare resources.');
|
|
59
|
-
console.error(` Site: ${deployConfig.name}`);
|
|
60
|
-
console.error(` Slug: ${deployConfig.slug}`);
|
|
61
|
-
console.error(` Worker: ${state.workerName ?? deriveCloudflareWorkerName(deployConfig)}`);
|
|
62
|
-
console.error(` D1: ${state.d1Databases.SITE_DATA_DB.databaseName}`);
|
|
63
|
-
console.error(` KV FORM_GUARD_KV: ${state.kvNamespaces.FORM_GUARD_KV.name}`);
|
|
64
|
-
console.error(` KV SESSION: ${state.kvNamespaces.SESSION.name}`);
|
|
65
|
-
console.error(' This action is irreversible.');
|
|
66
|
-
console.error(` To continue, type exactly: ${expectedConfirmation}`);
|
|
67
|
-
}
|
|
68
|
-
async function readConfirmation(expectedConfirmation) {
|
|
69
|
-
const rl = readline.createInterface({ input, output });
|
|
70
|
-
try {
|
|
71
|
-
return (await rl.question('Confirmation: ')).trim() === expectedConfirmation;
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
rl.close();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const options = parseArgs(process.argv.slice(2));
|
|
78
|
-
const scope = options.environment ?? 'prod';
|
|
79
|
-
const target = createPersistentDeployTarget(scope);
|
|
80
|
-
applyTreeseedEnvironmentToProcess({ tenantRoot, scope });
|
|
81
|
-
assertTreeseedCommandEnvironment({ tenantRoot, scope, purpose: 'destroy' });
|
|
82
|
-
const deployConfig = validateDestroyPrerequisites(tenantRoot, { requireRemote: !options.dryRun });
|
|
83
|
-
const state = loadDeployState(tenantRoot, deployConfig, { target });
|
|
84
|
-
const expectedConfirmation = getExpectedConfirmation(deployConfig);
|
|
85
|
-
if (!options.skipConfirmation) {
|
|
86
|
-
printDangerMessage(deployConfig, state, expectedConfirmation);
|
|
87
|
-
const confirmed = options.confirm !== null ? options.confirm === expectedConfirmation : await readConfirmation(expectedConfirmation);
|
|
88
|
-
if (!confirmed) {
|
|
89
|
-
console.error('Destroy aborted: confirmation text did not match.');
|
|
90
|
-
process.exit(1);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const result = destroyCloudflareResources(tenantRoot, {
|
|
94
|
-
dryRun: options.dryRun,
|
|
95
|
-
force: options.force,
|
|
96
|
-
target,
|
|
97
|
-
});
|
|
98
|
-
printDestroySummary(result);
|
|
99
|
-
if (options.dryRun) {
|
|
100
|
-
console.log('Dry run: no remote resources were deleted.');
|
|
101
|
-
process.exit(0);
|
|
102
|
-
}
|
|
103
|
-
cleanupDestroyedState(tenantRoot, { target, removeBuildArtifacts: options.removeBuildArtifacts });
|
|
104
|
-
console.log('Treeseed destroy completed and local deployment state was removed.');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { corePackageRoot, packageScriptPath, spawnNodeBinary, resolveWranglerBin } from './package-tools.js';
|
|
3
|
-
import { applyTreeseedEnvironmentToProcess, assertTreeseedCommandEnvironment } from './config-runtime-lib.js';
|
|
4
|
-
import { ensureGeneratedWranglerConfig } from './deploy-lib.js';
|
|
5
|
-
import { loadTreeseedDeployConfig } from '@treeseed/core/deploy/config';
|
|
6
|
-
import { createTenantWatchEntries, isEditablePackageWorkspace, startPollingWatch, stopManagedProcess, writeDevReloadStamp, workspaceSdkRoot, } from './watch-dev-lib.js';
|
|
7
|
-
const tenantRoot = process.cwd();
|
|
8
|
-
const cliArgs = process.argv.slice(2);
|
|
9
|
-
const watchMode = cliArgs.includes('--watch');
|
|
10
|
-
const wranglerArgs = cliArgs.filter((arg) => arg !== '--watch');
|
|
11
|
-
let wranglerChild = null;
|
|
12
|
-
let stopWatching = null;
|
|
13
|
-
let isStoppingForRebuild = false;
|
|
14
|
-
let shuttingDown = false;
|
|
15
|
-
function shouldEnsureMailpit() {
|
|
16
|
-
if (process.env.TREESEED_DEV_FORCE_MAILPIT === '1') {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
return loadTreeseedDeployConfig().smtp?.enabled === true;
|
|
20
|
-
}
|
|
21
|
-
function runStep(command, args, { cwd = tenantRoot, env = {}, fatal = true } = {}) {
|
|
22
|
-
const result = spawnSync(command, args, {
|
|
23
|
-
stdio: 'inherit',
|
|
24
|
-
cwd,
|
|
25
|
-
env: { ...process.env, ...env },
|
|
26
|
-
});
|
|
27
|
-
if (result.status !== 0 && fatal) {
|
|
28
|
-
process.exit(result.status ?? 1);
|
|
29
|
-
}
|
|
30
|
-
return result.status === 0;
|
|
31
|
-
}
|
|
32
|
-
function runNodeScript(scriptPath, args = [], options = {}) {
|
|
33
|
-
return runStep(process.execPath, [scriptPath, ...args], options);
|
|
34
|
-
}
|
|
35
|
-
function runTenantBuildCycle({ includePackageBuild = false, includeSdkBuild = false, fatal = true } = {}) {
|
|
36
|
-
const envOverrides = ['TREESEED_LOCAL_DEV_MODE=cloudflare'];
|
|
37
|
-
if (watchMode) {
|
|
38
|
-
envOverrides.push('TREESEED_PUBLIC_DEV_WATCH_RELOAD=true');
|
|
39
|
-
}
|
|
40
|
-
if (includeSdkBuild && isEditablePackageWorkspace()) {
|
|
41
|
-
const sdkRoot = workspaceSdkRoot();
|
|
42
|
-
if (sdkRoot) {
|
|
43
|
-
const sdkBuilt = runStep('npm', ['run', 'build:dist'], {
|
|
44
|
-
cwd: sdkRoot,
|
|
45
|
-
fatal,
|
|
46
|
-
});
|
|
47
|
-
if (!sdkBuilt) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (includePackageBuild && isEditablePackageWorkspace()) {
|
|
53
|
-
const distBuilt = runStep('npm', ['run', 'build:dist'], {
|
|
54
|
-
cwd: corePackageRoot,
|
|
55
|
-
fatal,
|
|
56
|
-
});
|
|
57
|
-
if (!distBuilt) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const buildScripts = [
|
|
62
|
-
['patch-starlight-content-path', []],
|
|
63
|
-
['aggregate-book', []],
|
|
64
|
-
['sync-dev-vars', envOverrides],
|
|
65
|
-
['tenant-d1-migrate-local', []],
|
|
66
|
-
];
|
|
67
|
-
if (shouldEnsureMailpit()) {
|
|
68
|
-
buildScripts.splice(2, 0, ['ensure-mailpit', []]);
|
|
69
|
-
}
|
|
70
|
-
for (const [scriptName, args] of buildScripts) {
|
|
71
|
-
const ok = runNodeScript(packageScriptPath(scriptName), args, { fatal });
|
|
72
|
-
if (!ok) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
ensureGeneratedWranglerConfig(tenantRoot);
|
|
77
|
-
if (watchMode) {
|
|
78
|
-
writeDevReloadStamp(tenantRoot);
|
|
79
|
-
}
|
|
80
|
-
const built = runNodeScript(packageScriptPath('tenant-build'), [], {
|
|
81
|
-
fatal,
|
|
82
|
-
env: watchMode ? { TREESEED_PUBLIC_DEV_WATCH_RELOAD: 'true' } : {},
|
|
83
|
-
});
|
|
84
|
-
if (!built) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
function startWrangler() {
|
|
90
|
-
const { wranglerPath } = ensureGeneratedWranglerConfig(tenantRoot);
|
|
91
|
-
const child = spawnNodeBinary(resolveWranglerBin(), ['dev', '--local', '--config', wranglerPath, ...wranglerArgs], {
|
|
92
|
-
cwd: tenantRoot,
|
|
93
|
-
env: watchMode ? { TREESEED_PUBLIC_DEV_WATCH_RELOAD: 'true' } : {},
|
|
94
|
-
detached: process.platform !== 'win32',
|
|
95
|
-
});
|
|
96
|
-
wranglerChild = child;
|
|
97
|
-
child.on('exit', (code, signal) => {
|
|
98
|
-
if (child !== wranglerChild) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
wranglerChild = null;
|
|
102
|
-
if (isStoppingForRebuild || shuttingDown) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (stopWatching) {
|
|
106
|
-
stopWatching();
|
|
107
|
-
}
|
|
108
|
-
if (signal) {
|
|
109
|
-
process.kill(process.pid, signal);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
process.exit(code ?? 0);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
async function restartWranglerAfterBuild() {
|
|
116
|
-
if (wranglerChild) {
|
|
117
|
-
isStoppingForRebuild = true;
|
|
118
|
-
await stopManagedProcess(wranglerChild);
|
|
119
|
-
isStoppingForRebuild = false;
|
|
120
|
-
}
|
|
121
|
-
if (!shuttingDown) {
|
|
122
|
-
startWrangler();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
async function shutdownAndExit(code = 0) {
|
|
126
|
-
shuttingDown = true;
|
|
127
|
-
if (stopWatching) {
|
|
128
|
-
stopWatching();
|
|
129
|
-
}
|
|
130
|
-
await stopManagedProcess(wranglerChild);
|
|
131
|
-
process.exit(code);
|
|
132
|
-
}
|
|
133
|
-
process.on('SIGINT', () => {
|
|
134
|
-
void shutdownAndExit(130);
|
|
135
|
-
});
|
|
136
|
-
process.on('SIGTERM', () => {
|
|
137
|
-
void shutdownAndExit(143);
|
|
138
|
-
});
|
|
139
|
-
process.env.TREESEED_LOCAL_DEV_MODE = process.env.TREESEED_LOCAL_DEV_MODE ?? 'cloudflare';
|
|
140
|
-
applyTreeseedEnvironmentToProcess({ tenantRoot, scope: 'local' });
|
|
141
|
-
assertTreeseedCommandEnvironment({ tenantRoot, scope: 'local', purpose: 'dev' });
|
|
142
|
-
runTenantBuildCycle({
|
|
143
|
-
includeSdkBuild: isEditablePackageWorkspace(),
|
|
144
|
-
includePackageBuild: isEditablePackageWorkspace(),
|
|
145
|
-
fatal: true,
|
|
146
|
-
});
|
|
147
|
-
startWrangler();
|
|
148
|
-
if (watchMode) {
|
|
149
|
-
console.log('Starting unified Wrangler watch mode. Changes will rebuild the app and refresh the browser.');
|
|
150
|
-
stopWatching = startPollingWatch({
|
|
151
|
-
watchEntries: createTenantWatchEntries(tenantRoot),
|
|
152
|
-
onChange: async ({ changedPaths, packageChanged, sdkChanged }) => {
|
|
153
|
-
console.log(`Detected ${changedPaths.length} change${changedPaths.length === 1 ? '' : 's'}; rebuilding ${sdkChanged ? 'sdk, core, and tenant' : packageChanged ? 'core and tenant' : 'tenant'} output...`);
|
|
154
|
-
isStoppingForRebuild = true;
|
|
155
|
-
await stopManagedProcess(wranglerChild);
|
|
156
|
-
isStoppingForRebuild = false;
|
|
157
|
-
const ok = runTenantBuildCycle({
|
|
158
|
-
includeSdkBuild: sdkChanged,
|
|
159
|
-
includePackageBuild: packageChanged || sdkChanged,
|
|
160
|
-
fatal: false,
|
|
161
|
-
});
|
|
162
|
-
if (ok) {
|
|
163
|
-
startWrangler();
|
|
164
|
-
console.log('Rebuild complete. Wrangler restarted with the updated output.');
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
console.error('Rebuild failed. Wrangler remains stopped until the next successful save.');
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|