@treeseed/cli 0.1.1 → 0.4.2
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,277 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, relative, resolve, sep } from 'node:path';
|
|
3
|
-
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
-
import { corePackageRoot, sdkPackageRoot } from './package-tools.js';
|
|
5
|
-
const WATCH_INTERVAL_MS = 900;
|
|
6
|
-
const DEBOUNCE_MS = 350;
|
|
7
|
-
const DEV_RELOAD_FILE = 'public/__treeseed/dev-reload.json';
|
|
8
|
-
const PROCESS_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
9
|
-
const WATCH_BUILD_ROOT = '.local/treeseed-watch';
|
|
10
|
-
const PROCESS_SETTLE_DELAY_MS = 300;
|
|
11
|
-
function isNodeModulesPath(filePath) {
|
|
12
|
-
return filePath.split(sep).includes('node_modules');
|
|
13
|
-
}
|
|
14
|
-
export function isEditablePackageWorkspace() {
|
|
15
|
-
return !isNodeModulesPath(corePackageRoot);
|
|
16
|
-
}
|
|
17
|
-
export function workspaceSdkRoot() {
|
|
18
|
-
return existsSync(resolve(sdkPackageRoot, 'package.json')) ? sdkPackageRoot : null;
|
|
19
|
-
}
|
|
20
|
-
export function writeDevReloadStamp(projectRoot) {
|
|
21
|
-
const outputPath = resolve(projectRoot, DEV_RELOAD_FILE);
|
|
22
|
-
mkdirSync(dirname(outputPath), { recursive: true });
|
|
23
|
-
writeFileSync(outputPath, `${JSON.stringify({
|
|
24
|
-
buildId: `${Date.now()}`,
|
|
25
|
-
updatedAt: new Date().toISOString(),
|
|
26
|
-
}, null, 2)}\n`, 'utf8');
|
|
27
|
-
}
|
|
28
|
-
function shouldIgnoreWatchPath(filePath, rootPath) {
|
|
29
|
-
const rel = relative(rootPath, filePath);
|
|
30
|
-
if (!rel || rel.startsWith(`..${sep}`) || rel === '..') {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const normalized = rel.split(sep).join('/');
|
|
34
|
-
return (normalized === '.git' ||
|
|
35
|
-
normalized.startsWith('.git/') ||
|
|
36
|
-
normalized === 'node_modules' ||
|
|
37
|
-
normalized.startsWith('node_modules/') ||
|
|
38
|
-
normalized === '.astro' ||
|
|
39
|
-
normalized.startsWith('.astro/') ||
|
|
40
|
-
normalized === '.wrangler' ||
|
|
41
|
-
normalized.startsWith('.wrangler/') ||
|
|
42
|
-
normalized === '.local' ||
|
|
43
|
-
normalized.startsWith('.local/') ||
|
|
44
|
-
normalized === '.treeseed' ||
|
|
45
|
-
normalized.startsWith('.treeseed/') ||
|
|
46
|
-
normalized === 'dist' ||
|
|
47
|
-
normalized.startsWith('dist/') ||
|
|
48
|
-
normalized === 'coverage' ||
|
|
49
|
-
normalized.startsWith('coverage/') ||
|
|
50
|
-
normalized === '.dev.vars' ||
|
|
51
|
-
normalized === 'books' ||
|
|
52
|
-
normalized.startsWith('books/') ||
|
|
53
|
-
normalized === '__treeseed' ||
|
|
54
|
-
normalized.startsWith('__treeseed/') ||
|
|
55
|
-
normalized.startsWith('public/books/') ||
|
|
56
|
-
normalized.startsWith('public/__treeseed/'));
|
|
57
|
-
}
|
|
58
|
-
function collectRootSnapshot(rootPath, snapshot) {
|
|
59
|
-
if (!existsSync(rootPath)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const rootStats = statSync(rootPath);
|
|
63
|
-
if (rootStats.isFile()) {
|
|
64
|
-
snapshot.set(rootPath, `${rootStats.mtimeMs}:${rootStats.size}`);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
for (const entry of readdirSync(rootPath, { withFileTypes: true })) {
|
|
68
|
-
const fullPath = resolve(rootPath, entry.name);
|
|
69
|
-
if (shouldIgnoreWatchPath(fullPath, rootPath)) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (entry.isDirectory()) {
|
|
73
|
-
collectDirectorySnapshot(fullPath, rootPath, snapshot);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const stats = statSync(fullPath);
|
|
77
|
-
snapshot.set(fullPath, `${stats.mtimeMs}:${stats.size}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function collectDirectorySnapshot(directoryPath, rootPath, snapshot) {
|
|
81
|
-
if (shouldIgnoreWatchPath(directoryPath, rootPath)) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
for (const entry of readdirSync(directoryPath, { withFileTypes: true })) {
|
|
85
|
-
const fullPath = resolve(directoryPath, entry.name);
|
|
86
|
-
if (shouldIgnoreWatchPath(fullPath, rootPath)) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if (entry.isDirectory()) {
|
|
90
|
-
collectDirectorySnapshot(fullPath, rootPath, snapshot);
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
const stats = statSync(fullPath);
|
|
94
|
-
snapshot.set(fullPath, `${stats.mtimeMs}:${stats.size}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function collectSnapshot(entries) {
|
|
98
|
-
const snapshot = new Map();
|
|
99
|
-
for (const entry of entries) {
|
|
100
|
-
collectRootSnapshot(entry.root, snapshot);
|
|
101
|
-
}
|
|
102
|
-
return snapshot;
|
|
103
|
-
}
|
|
104
|
-
function diffSnapshots(previousSnapshot, nextSnapshot) {
|
|
105
|
-
const changed = new Set();
|
|
106
|
-
for (const [filePath, signature] of nextSnapshot.entries()) {
|
|
107
|
-
if (previousSnapshot.get(filePath) !== signature) {
|
|
108
|
-
changed.add(filePath);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
for (const filePath of previousSnapshot.keys()) {
|
|
112
|
-
if (!nextSnapshot.has(filePath)) {
|
|
113
|
-
changed.add(filePath);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return [...changed];
|
|
117
|
-
}
|
|
118
|
-
function classifyChanges(changedPaths, watchEntries) {
|
|
119
|
-
function matchesEntry(filePath, entry) {
|
|
120
|
-
return filePath === entry.root || filePath.startsWith(`${entry.root}${sep}`);
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
changedPaths,
|
|
124
|
-
sdkChanged: changedPaths.some((filePath) => watchEntries.some((entry) => entry.kind === 'sdk' && matchesEntry(filePath, entry))),
|
|
125
|
-
packageChanged: changedPaths.some((filePath) => watchEntries.some((entry) => entry.kind === 'package' && matchesEntry(filePath, entry))),
|
|
126
|
-
tenantChanged: changedPaths.some((filePath) => watchEntries.some((entry) => entry.kind === 'tenant' && matchesEntry(filePath, entry))),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
export function readDevReloadState(projectRoot) {
|
|
130
|
-
const filePath = resolve(projectRoot, DEV_RELOAD_FILE);
|
|
131
|
-
if (!existsSync(filePath)) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
try {
|
|
135
|
-
return JSON.parse(readFileSync(filePath, 'utf8'));
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
export function createTenantWatchEntries(tenantRoot) {
|
|
142
|
-
const entries = [
|
|
143
|
-
{ kind: 'tenant', root: resolve(tenantRoot, 'src') },
|
|
144
|
-
{ kind: 'tenant', root: resolve(tenantRoot, 'public') },
|
|
145
|
-
{ kind: 'tenant', root: resolve(tenantRoot, 'astro.config.ts') },
|
|
146
|
-
{ kind: 'tenant', root: resolve(tenantRoot, 'treeseed.site.yaml') },
|
|
147
|
-
{ kind: 'tenant', root: resolve(tenantRoot, '.env.local') },
|
|
148
|
-
{ kind: 'tenant', root: resolve(tenantRoot, '.env.local.example') },
|
|
149
|
-
];
|
|
150
|
-
if (isEditablePackageWorkspace()) {
|
|
151
|
-
const sdkRoot = workspaceSdkRoot();
|
|
152
|
-
entries.push({ kind: 'package', root: resolve(corePackageRoot, 'src') }, { kind: 'package', root: resolve(corePackageRoot, 'scripts') }, { kind: 'package', root: resolve(corePackageRoot, 'services') }, { kind: 'package', root: resolve(corePackageRoot, 'tsconfigs') }, { kind: 'package', root: resolve(corePackageRoot, 'package.json') });
|
|
153
|
-
if (sdkRoot) {
|
|
154
|
-
entries.push({ kind: 'sdk', root: resolve(sdkRoot, 'src') }, { kind: 'sdk', root: resolve(sdkRoot, 'scripts') }, { kind: 'sdk', root: resolve(sdkRoot, 'package.json') });
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return entries;
|
|
158
|
-
}
|
|
159
|
-
export function startPollingWatch({ watchEntries, onChange }) {
|
|
160
|
-
let previousSnapshot = collectSnapshot(watchEntries);
|
|
161
|
-
let queuedPaths = [];
|
|
162
|
-
let debounceTimer = null;
|
|
163
|
-
let running = false;
|
|
164
|
-
let intervalId = null;
|
|
165
|
-
async function flush() {
|
|
166
|
-
if (running || queuedPaths.length === 0) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
const changedPaths = [...new Set(queuedPaths)];
|
|
170
|
-
queuedPaths = [];
|
|
171
|
-
running = true;
|
|
172
|
-
try {
|
|
173
|
-
await onChange(classifyChanges(changedPaths, watchEntries));
|
|
174
|
-
}
|
|
175
|
-
finally {
|
|
176
|
-
running = false;
|
|
177
|
-
if (queuedPaths.length > 0) {
|
|
178
|
-
debounceTimer = setTimeout(flush, DEBOUNCE_MS);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function queueChanges(changedPaths) {
|
|
183
|
-
if (changedPaths.length === 0) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
queuedPaths.push(...changedPaths);
|
|
187
|
-
if (debounceTimer) {
|
|
188
|
-
clearTimeout(debounceTimer);
|
|
189
|
-
}
|
|
190
|
-
debounceTimer = setTimeout(flush, DEBOUNCE_MS);
|
|
191
|
-
}
|
|
192
|
-
intervalId = setInterval(() => {
|
|
193
|
-
const nextSnapshot = collectSnapshot(watchEntries);
|
|
194
|
-
const changedPaths = diffSnapshots(previousSnapshot, nextSnapshot);
|
|
195
|
-
previousSnapshot = nextSnapshot;
|
|
196
|
-
queueChanges(changedPaths);
|
|
197
|
-
}, WATCH_INTERVAL_MS);
|
|
198
|
-
return () => {
|
|
199
|
-
if (debounceTimer) {
|
|
200
|
-
clearTimeout(debounceTimer);
|
|
201
|
-
}
|
|
202
|
-
if (intervalId) {
|
|
203
|
-
clearInterval(intervalId);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
export async function stopManagedProcess(child, signal = 'SIGTERM') {
|
|
208
|
-
if (!child || child.exitCode !== null || child.killed) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const groupSignalSupported = process.platform !== 'win32' && child.pid && child.spawnargs;
|
|
212
|
-
let signaled = false;
|
|
213
|
-
if (groupSignalSupported) {
|
|
214
|
-
try {
|
|
215
|
-
process.kill(-child.pid, signal);
|
|
216
|
-
signaled = true;
|
|
217
|
-
}
|
|
218
|
-
catch {
|
|
219
|
-
signaled = false;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (!signaled) {
|
|
223
|
-
child.kill(signal);
|
|
224
|
-
}
|
|
225
|
-
await Promise.race([
|
|
226
|
-
new Promise((resolve) => child.once('exit', resolve)),
|
|
227
|
-
delay(PROCESS_SHUTDOWN_TIMEOUT_MS),
|
|
228
|
-
]);
|
|
229
|
-
if (child.exitCode === null && !child.killed) {
|
|
230
|
-
if (groupSignalSupported) {
|
|
231
|
-
try {
|
|
232
|
-
process.kill(-child.pid, 'SIGKILL');
|
|
233
|
-
}
|
|
234
|
-
catch {
|
|
235
|
-
child.kill('SIGKILL');
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
child.kill('SIGKILL');
|
|
240
|
-
}
|
|
241
|
-
await Promise.race([
|
|
242
|
-
new Promise((resolve) => child.once('exit', resolve)),
|
|
243
|
-
delay(PROCESS_SHUTDOWN_TIMEOUT_MS),
|
|
244
|
-
]);
|
|
245
|
-
}
|
|
246
|
-
await delay(PROCESS_SETTLE_DELAY_MS);
|
|
247
|
-
}
|
|
248
|
-
export function createWatchBuildPaths(projectRoot) {
|
|
249
|
-
const watchRoot = resolve(projectRoot, WATCH_BUILD_ROOT);
|
|
250
|
-
return {
|
|
251
|
-
watchRoot,
|
|
252
|
-
stagedDistRoot: resolve(watchRoot, 'dist-next'),
|
|
253
|
-
backupDistRoot: resolve(watchRoot, 'dist-prev'),
|
|
254
|
-
liveDistRoot: resolve(projectRoot, 'dist'),
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
export function swapStagedBuildOutput(projectRoot) {
|
|
258
|
-
const { watchRoot, stagedDistRoot, backupDistRoot, liveDistRoot } = createWatchBuildPaths(projectRoot);
|
|
259
|
-
mkdirSync(watchRoot, { recursive: true });
|
|
260
|
-
rmSync(backupDistRoot, { recursive: true, force: true });
|
|
261
|
-
if (existsSync(liveDistRoot)) {
|
|
262
|
-
try {
|
|
263
|
-
renameSync(liveDistRoot, backupDistRoot);
|
|
264
|
-
}
|
|
265
|
-
catch {
|
|
266
|
-
// Some rebuild cycles leave the previous backup path occupied long enough that the
|
|
267
|
-
// rename can fail. In that case, drop the old live output and replace it directly.
|
|
268
|
-
rmSync(liveDistRoot, { recursive: true, force: true });
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
renameSync(stagedDistRoot, liveDistRoot);
|
|
272
|
-
rmSync(backupDistRoot, { recursive: true, force: true });
|
|
273
|
-
}
|
|
274
|
-
export function clearStagedBuildOutput(projectRoot) {
|
|
275
|
-
const { stagedDistRoot } = createWatchBuildPaths(projectRoot);
|
|
276
|
-
rmSync(stagedDistRoot, { recursive: true, force: true });
|
|
277
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { applyTreeseedEnvironmentToProcess } from './config-runtime-lib.js';
|
|
3
|
-
import { cleanupDestroyedState, createBranchPreviewDeployTarget, destroyCloudflareResources, loadDeployState, printDestroySummary, validateDestroyPrerequisites, } from './deploy-lib.js';
|
|
4
|
-
import { assertFeatureBranch, deleteLocalBranch, deleteRemoteBranch, mergeCurrentBranchIntoStaging, } from './git-workflow-lib.js';
|
|
5
|
-
import { loadCliDeployConfig } from './package-tools.js';
|
|
6
|
-
import { runWorkspaceSavePreflight } from './save-deploy-preflight-lib.js';
|
|
7
|
-
const tenantRoot = process.cwd();
|
|
8
|
-
const featureBranch = assertFeatureBranch(tenantRoot);
|
|
9
|
-
const previewTarget = createBranchPreviewDeployTarget(featureBranch);
|
|
10
|
-
const deployConfig = loadCliDeployConfig(tenantRoot);
|
|
11
|
-
const previewState = loadDeployState(tenantRoot, deployConfig, { target: previewTarget });
|
|
12
|
-
runWorkspaceSavePreflight({ cwd: tenantRoot });
|
|
13
|
-
const repoDir = mergeCurrentBranchIntoStaging(tenantRoot, featureBranch);
|
|
14
|
-
if (previewState.readiness?.initialized) {
|
|
15
|
-
applyTreeseedEnvironmentToProcess({ tenantRoot, scope: 'staging' });
|
|
16
|
-
validateDestroyPrerequisites(tenantRoot, { requireRemote: true });
|
|
17
|
-
const result = destroyCloudflareResources(tenantRoot, { target: previewTarget });
|
|
18
|
-
printDestroySummary(result);
|
|
19
|
-
}
|
|
20
|
-
cleanupDestroyedState(tenantRoot, { target: previewTarget });
|
|
21
|
-
deleteRemoteBranch(repoDir, featureBranch);
|
|
22
|
-
deleteLocalBranch(repoDir, featureBranch);
|
|
23
|
-
console.log('Treeseed close completed successfully.');
|
|
24
|
-
console.log(`Merged ${featureBranch} into staging and removed branch artifacts.`);
|