@open-document/core 0.11.0 → 0.13.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/{build-BHFGY8eF.js → build-CbgIk6bA.js} +1 -1
- package/dist/{check-UEBmDfT_.js → check-BTroj-5Z.js} +3 -3
- package/dist/cli/bin.js +58 -34
- package/dist/config-BWtOZ1jc.d.ts +45 -0
- package/dist/{config-B_pdNbYg.js → config-DKKNIbvO.js} +1458 -983
- package/dist/{context-BM9_-u9P.js → context-DXNP8v9I.js} +3 -2
- package/dist/deploy-gcp-BUiSuqz7.js +758 -0
- package/dist/{dev-DX3QMIRi.js → dev-YXumw5iX.js} +1 -1
- package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
- package/dist/{diff-DayvbXfX.js → diff-CTFfU4Tz.js} +2 -2
- package/dist/{export-BPsXj1i6.js → export-D2QLtF84.js} +11 -4
- package/dist/flow-CS5apebG.d.ts +252 -0
- package/dist/{import-71wlAsrd.js → import-CcmrFetU.js} +3 -2
- package/dist/index.d.ts +155 -59
- package/dist/index.js +945 -104
- package/dist/open-doc-plugin-DnX5usgI.js +320 -0
- package/dist/ops/index.d.ts +112 -3
- package/dist/ops/index.js +3 -3
- package/dist/{ops-BUo67DaP.js → ops-DmEecq1k.js} +86 -164
- package/dist/package-version-C89gtYSk.js +36 -0
- package/dist/{preview-D3m1-gUL.js → preview-_mHpBhMk.js} +1 -1
- package/dist/templates-MMblHwmT.js +34 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2 -1
- package/package.json +2 -1
- package/skills/apply-comments/SKILL.md +3 -1
- package/skills/create-doc/SKILL.md +2 -0
- package/skills/doc-authoring/SKILL.md +17 -16
- package/skills/doc-authoring/references/long-form.md +43 -2
- package/skills/doc-authoring/references/pagination.md +14 -2
- package/skills/doc-authoring/references/tables-and-charts.md +21 -17
- package/src/app/components/browser/browser-ui.tsx +21 -0
- package/src/app/components/browser/new-document-dialog.tsx +208 -0
- package/src/app/components/callout.tsx +101 -0
- package/src/app/components/changes/changes-overlay.tsx +68 -0
- package/src/app/components/changes/changes-panel.tsx +341 -0
- package/src/app/components/changes/use-changes.ts +85 -0
- package/src/app/components/chart.tsx +191 -33
- package/src/app/components/code-block.tsx +249 -0
- package/src/app/components/comments/comments-overlay.tsx +50 -0
- package/src/app/components/comments/comments-panel.tsx +272 -0
- package/src/app/components/comments/use-comments.ts +61 -0
- package/src/app/components/data-table.tsx +146 -18
- package/src/app/components/doc-sidebar.tsx +32 -2
- package/src/app/components/flow-page.tsx +57 -8
- package/src/app/components/inspector/field-source.tsx +41 -0
- package/src/app/components/inspector/inspector.tsx +64 -65
- package/src/app/components/numbering.tsx +226 -12
- package/src/app/components/overlay-frame.tsx +79 -0
- package/src/app/components/page-frame.tsx +46 -0
- package/src/app/components/page-placement.ts +68 -0
- package/src/app/components/record-picker.tsx +79 -0
- package/src/app/components/themes/theme-preview.tsx +5 -4
- package/src/app/lib/agent-bridge.ts +29 -1
- package/src/app/lib/chart.test.ts +15 -0
- package/src/app/lib/chart.ts +134 -9
- package/src/app/lib/diagnostics.ts +45 -1
- package/src/app/lib/docx/ooxml.test.ts +24 -1
- package/src/app/lib/docx/ooxml.ts +27 -1
- package/src/app/lib/export-docx.ts +3 -1
- package/src/app/lib/export-dom.ts +17 -3
- package/src/app/lib/export-html.ts +4 -2
- package/src/app/lib/export-image.ts +2 -1
- package/src/app/lib/export-pdf.ts +9 -1
- package/src/app/lib/flow-measure.test.ts +30 -0
- package/src/app/lib/flow-measure.ts +68 -14
- package/src/app/lib/flow.test.ts +20 -1
- package/src/app/lib/flow.ts +120 -20
- package/src/app/lib/i18n-ja/browser.ts +10 -0
- package/src/app/lib/i18n-ja/doc.ts +4 -0
- package/src/app/lib/i18n-ja/panels.ts +40 -0
- package/src/app/lib/i18n-ko/browser.ts +10 -0
- package/src/app/lib/i18n-ko/doc.ts +4 -0
- package/src/app/lib/i18n-ko/panels.ts +39 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +38 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +38 -0
- package/src/app/lib/labels.ts +29 -10
- package/src/app/lib/records.test.ts +38 -0
- package/src/app/lib/records.ts +127 -0
- package/src/app/lib/sdk.ts +35 -0
- package/src/app/lib/use-doc-module.ts +7 -0
- package/src/app/lib/use-doc-pages.ts +38 -17
- package/src/app/routes/doc.tsx +275 -13
- package/src/app/routes/home.tsx +30 -5
- package/src/app/styles.css +23 -0
- package/templates/blank/index.tsx +63 -0
- package/templates/blank/template.json +6 -0
- package/templates/certificate/data/recipients.csv +4 -0
- package/templates/certificate/index.tsx +128 -0
- package/templates/certificate/template.json +6 -0
- package/templates/letter/index.tsx +106 -0
- package/templates/letter/template.json +5 -0
- package/templates/meeting-notes/index.tsx +194 -0
- package/templates/meeting-notes/template.json +6 -0
- package/templates/proposal/index.tsx +264 -0
- package/templates/proposal/template.json +6 -0
- package/templates/report/data/metrics.csv +5 -0
- package/templates/report/index.tsx +224 -0
- package/templates/report/template.json +6 -0
- package/dist/config-P61niZMf.d.ts +0 -24
- package/dist/sdk-CpDEGRIo.d.ts +0 -138
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
import { n as loadUserConfig } from "./open-doc-plugin-DnX5usgI.js";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import * as readline from "node:readline/promises";
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
//#region src/cli/deploy-gcp.ts
|
|
9
|
+
const REQUIRED_GCP_APIS = [
|
|
10
|
+
"run.googleapis.com",
|
|
11
|
+
"cloudbuild.googleapis.com",
|
|
12
|
+
"artifactregistry.googleapis.com",
|
|
13
|
+
"storage.googleapis.com"
|
|
14
|
+
];
|
|
15
|
+
const STATE_FILE = ".open-doc-cloud.json";
|
|
16
|
+
function sanitizeKebab(input, fallback = "open-doc-app") {
|
|
17
|
+
return input.toLowerCase().replace(/^@[^/]+\//, "").replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").replace(/-{2,}/g, "-").slice(0, 48).replace(/-+$/g, "") || fallback;
|
|
18
|
+
}
|
|
19
|
+
function defaultBucketName(project, service) {
|
|
20
|
+
return `${sanitizeKebab(project, "gcp")}-${sanitizeKebab(service, "open-doc")}-data`.slice(0, 63).replace(/-+$/g, "");
|
|
21
|
+
}
|
|
22
|
+
function detectPackageManager(userCwd) {
|
|
23
|
+
const pkgPath = path.join(userCwd, "package.json");
|
|
24
|
+
if (existsSync(pkgPath)) try {
|
|
25
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
26
|
+
if (pkg.packageManager?.startsWith("pnpm")) return "pnpm";
|
|
27
|
+
if (pkg.packageManager?.startsWith("yarn")) return "yarn";
|
|
28
|
+
if (pkg.packageManager?.startsWith("npm")) return "npm";
|
|
29
|
+
} catch {}
|
|
30
|
+
if (existsSync(path.join(userCwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
31
|
+
if (existsSync(path.join(userCwd, "yarn.lock"))) return "yarn";
|
|
32
|
+
return "npm";
|
|
33
|
+
}
|
|
34
|
+
function inferDefaultServiceName(userCwd) {
|
|
35
|
+
const pkgPath = path.join(userCwd, "package.json");
|
|
36
|
+
if (existsSync(pkgPath)) try {
|
|
37
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
38
|
+
if (pkg.name) return sanitizeKebab(pkg.name);
|
|
39
|
+
} catch {}
|
|
40
|
+
return sanitizeKebab(path.basename(userCwd));
|
|
41
|
+
}
|
|
42
|
+
function readCloudState(userCwd) {
|
|
43
|
+
const file = path.join(userCwd, STATE_FILE);
|
|
44
|
+
if (!existsSync(file)) return {};
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
47
|
+
} catch {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function writeCloudState(userCwd, state) {
|
|
52
|
+
const file = path.join(userCwd, STATE_FILE);
|
|
53
|
+
writeFileSync(file, `${JSON.stringify(state, null, 2)}\n`, "utf8");
|
|
54
|
+
ensureGitignoreEntry(userCwd, STATE_FILE);
|
|
55
|
+
}
|
|
56
|
+
function ensureGitignoreEntry(userCwd, entry) {
|
|
57
|
+
const gitignorePath = path.join(userCwd, ".gitignore");
|
|
58
|
+
if (!existsSync(gitignorePath)) return;
|
|
59
|
+
try {
|
|
60
|
+
const content = readFileSync(gitignorePath, "utf8");
|
|
61
|
+
if (!content.split(/\r?\n/).map((line) => line.trim()).includes(entry)) {
|
|
62
|
+
const prefix = content.endsWith("\n") || content.length === 0 ? "" : "\n";
|
|
63
|
+
writeFileSync(gitignorePath, `${content}${prefix}${entry}\n`, "utf8");
|
|
64
|
+
}
|
|
65
|
+
} catch {}
|
|
66
|
+
}
|
|
67
|
+
const defaultRunner = (cmd, args, opts) => {
|
|
68
|
+
const res = spawnSync(cmd, args, {
|
|
69
|
+
cwd: opts?.cwd,
|
|
70
|
+
stdio: opts?.inherit ? "inherit" : "pipe",
|
|
71
|
+
encoding: "utf8"
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
ok: res.status === 0,
|
|
75
|
+
status: res.status ?? 1,
|
|
76
|
+
stdout: (res.stdout ?? "").trim(),
|
|
77
|
+
stderr: (res.stderr ?? "").trim()
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
function hasMcpPackageInstalled(userCwd) {
|
|
81
|
+
let dir = path.resolve(userCwd);
|
|
82
|
+
for (;;) {
|
|
83
|
+
if (existsSync(path.join(dir, "node_modules", "@open-document", "mcp", "package.json"))) return true;
|
|
84
|
+
const parent = path.dirname(dir);
|
|
85
|
+
if (parent === dir) break;
|
|
86
|
+
dir = parent;
|
|
87
|
+
}
|
|
88
|
+
const pkgPath = path.join(userCwd, "package.json");
|
|
89
|
+
if (existsSync(pkgPath)) try {
|
|
90
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
91
|
+
return Boolean(pkg.dependencies?.["@open-document/mcp"] || pkg.devDependencies?.["@open-document/mcp"]);
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
async function inspectGcpEnvironment(userCwd, flags = {}, runner = defaultRunner) {
|
|
98
|
+
const items = [];
|
|
99
|
+
const config = await loadUserConfig(userCwd);
|
|
100
|
+
const state = readCloudState(userCwd);
|
|
101
|
+
const mode = flags.mode ?? config.deploy?.gcp?.mode ?? state.mode ?? "editable";
|
|
102
|
+
const versionRes = runner("gcloud", ["--version"]);
|
|
103
|
+
if (!versionRes.ok) {
|
|
104
|
+
items.push({
|
|
105
|
+
id: "gcloud-cli",
|
|
106
|
+
label: "Google Cloud SDK (gcloud)",
|
|
107
|
+
status: "fail",
|
|
108
|
+
detail: "gcloud CLI is not installed or not in PATH",
|
|
109
|
+
remedy: process.platform === "darwin" ? "Run `brew install --cask google-cloud-sdk` to install the Google Cloud CLI." : "Install Google Cloud SDK from https://cloud.google.com/sdk/docs/install"
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
ready: false,
|
|
113
|
+
account: null,
|
|
114
|
+
project: null,
|
|
115
|
+
accessibleProjects: [],
|
|
116
|
+
items
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const firstLine = versionRes.stdout.split(/\r?\n/)[0] ?? "Google Cloud SDK";
|
|
120
|
+
items.push({
|
|
121
|
+
id: "gcloud-cli",
|
|
122
|
+
label: "Google Cloud SDK (gcloud)",
|
|
123
|
+
status: "ok",
|
|
124
|
+
detail: firstLine
|
|
125
|
+
});
|
|
126
|
+
const authRes = runner("gcloud", [
|
|
127
|
+
"auth",
|
|
128
|
+
"list",
|
|
129
|
+
"--filter=status:ACTIVE",
|
|
130
|
+
"--format=value(account)"
|
|
131
|
+
]);
|
|
132
|
+
const account = authRes.ok && authRes.stdout ? authRes.stdout.split(/\r?\n/)[0].trim() : null;
|
|
133
|
+
if (!account) items.push({
|
|
134
|
+
id: "gcloud-auth",
|
|
135
|
+
label: "GCP Authentication",
|
|
136
|
+
status: "fail",
|
|
137
|
+
detail: "No active Google Cloud account logged in",
|
|
138
|
+
remedy: "Run `gcloud auth login` in your terminal to sign in."
|
|
139
|
+
});
|
|
140
|
+
else items.push({
|
|
141
|
+
id: "gcloud-auth",
|
|
142
|
+
label: "GCP Authentication",
|
|
143
|
+
status: "ok",
|
|
144
|
+
detail: `Signed in as ${account}`
|
|
145
|
+
});
|
|
146
|
+
const projectsRes = account ? runner("gcloud", [
|
|
147
|
+
"projects",
|
|
148
|
+
"list",
|
|
149
|
+
"--limit=25",
|
|
150
|
+
"--format=value(projectId)"
|
|
151
|
+
]) : {
|
|
152
|
+
ok: false,
|
|
153
|
+
status: 1,
|
|
154
|
+
stdout: "",
|
|
155
|
+
stderr: ""
|
|
156
|
+
};
|
|
157
|
+
const accessibleProjects = projectsRes.ok ? projectsRes.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean) : [];
|
|
158
|
+
const gcloudDefaultProjectRes = runner("gcloud", [
|
|
159
|
+
"config",
|
|
160
|
+
"get-value",
|
|
161
|
+
"project"
|
|
162
|
+
]);
|
|
163
|
+
const gcloudDefaultProject = gcloudDefaultProjectRes.ok && gcloudDefaultProjectRes.stdout && gcloudDefaultProjectRes.stdout !== "(unset)" ? gcloudDefaultProjectRes.stdout.trim() : void 0;
|
|
164
|
+
const project = flags.project ?? config.deploy?.gcp?.project ?? state.project ?? gcloudDefaultProject ?? null;
|
|
165
|
+
if (!project) {
|
|
166
|
+
const sample = accessibleProjects.length > 0 ? ` (accessible projects: ${accessibleProjects.slice(0, 5).join(", ")})` : "";
|
|
167
|
+
items.push({
|
|
168
|
+
id: "gcp-project",
|
|
169
|
+
label: "GCP Target Project",
|
|
170
|
+
status: "warn",
|
|
171
|
+
detail: `No default GCP project configured${sample}`,
|
|
172
|
+
remedy: "Pass `--project <PROJECT_ID>`, set `deploy.gcp.project` in `open-doc.config.ts`, or run `gcloud config set project <PROJECT_ID>`."
|
|
173
|
+
});
|
|
174
|
+
} else items.push({
|
|
175
|
+
id: "gcp-project",
|
|
176
|
+
label: "GCP Target Project",
|
|
177
|
+
status: "ok",
|
|
178
|
+
detail: `Using project "${project}"`
|
|
179
|
+
});
|
|
180
|
+
if (project && account) {
|
|
181
|
+
const enabledRes = runner("gcloud", [
|
|
182
|
+
"services",
|
|
183
|
+
"list",
|
|
184
|
+
"--enabled",
|
|
185
|
+
`--project=${project}`,
|
|
186
|
+
"--format=value(config.name)"
|
|
187
|
+
]);
|
|
188
|
+
if (enabledRes.ok) {
|
|
189
|
+
const enabledSet = new Set(enabledRes.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean));
|
|
190
|
+
const missingApis = REQUIRED_GCP_APIS.filter((api) => !enabledSet.has(api));
|
|
191
|
+
if (missingApis.length === 0) items.push({
|
|
192
|
+
id: "gcp-apis",
|
|
193
|
+
label: "Required GCP APIs (Run, Build, Artifact Registry, Storage)",
|
|
194
|
+
status: "ok",
|
|
195
|
+
detail: "All 4 required GCP APIs are enabled"
|
|
196
|
+
});
|
|
197
|
+
else items.push({
|
|
198
|
+
id: "gcp-apis",
|
|
199
|
+
label: "Required GCP APIs (Run, Build, Artifact Registry, Storage)",
|
|
200
|
+
status: "warn",
|
|
201
|
+
detail: `APIs not yet enabled on ${project}: ${missingApis.join(", ")}`,
|
|
202
|
+
remedy: "`open-doc deploy gcp` will automatically enable these APIs via `gcloud services enable`."
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (mode === "editable") {
|
|
207
|
+
const hasMcp = hasMcpPackageInstalled(userCwd);
|
|
208
|
+
const pm = detectPackageManager(userCwd);
|
|
209
|
+
const installCmd = pm === "pnpm" ? "pnpm add -D @open-document/mcp" : pm === "yarn" ? "yarn add -D @open-document/mcp" : "npm install -D @open-document/mcp";
|
|
210
|
+
if (hasMcp) items.push({
|
|
211
|
+
id: "mcp-package",
|
|
212
|
+
label: "Antigravity Remote MCP (@open-document/mcp)",
|
|
213
|
+
status: "ok",
|
|
214
|
+
detail: "@open-document/mcp is installed (remote /mcp endpoint ready)"
|
|
215
|
+
});
|
|
216
|
+
else items.push({
|
|
217
|
+
id: "mcp-package",
|
|
218
|
+
label: "Antigravity Remote MCP (@open-document/mcp)",
|
|
219
|
+
status: "warn",
|
|
220
|
+
detail: "@open-document/mcp is not listed in this project; web editing works, but /mcp will be skipped unless installed",
|
|
221
|
+
remedy: `Run \`${installCmd}\` if you want Antigravity to edit cloud pages directly over /mcp.`
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
items.push({
|
|
225
|
+
id: "cloud-build",
|
|
226
|
+
label: "Container Builder (Google Cloud Build)",
|
|
227
|
+
status: "ok",
|
|
228
|
+
detail: "Builds remotely via `gcloud run deploy --source .` (no local Docker required)"
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
ready: !items.some((i) => i.status === "fail") && Boolean(project),
|
|
232
|
+
account,
|
|
233
|
+
project,
|
|
234
|
+
accessibleProjects,
|
|
235
|
+
items
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function generateEntrypointScript(opts) {
|
|
239
|
+
if (opts.mode === "static") return [
|
|
240
|
+
"#!/usr/bin/env sh",
|
|
241
|
+
"set -e",
|
|
242
|
+
"exec npx open-doc preview --host 0.0.0.0 --port \"${PORT:-8080}\"",
|
|
243
|
+
""
|
|
244
|
+
].join("\n");
|
|
245
|
+
return [
|
|
246
|
+
"#!/usr/bin/env sh",
|
|
247
|
+
"set -e",
|
|
248
|
+
"MOUNT_DIR=\"${OPEN_DOC_MOUNT_DIR:-/mnt/gcs}\"",
|
|
249
|
+
"mkdir -p \"$MOUNT_DIR\"",
|
|
250
|
+
"",
|
|
251
|
+
"# Ensure node_modules is resolvable when Vite/Node walks up from /mnt/gcs realpaths",
|
|
252
|
+
"if [ -d \"/app/node_modules\" ] && [ ! -e \"$MOUNT_DIR/node_modules\" ]; then",
|
|
253
|
+
" ln -s /app/node_modules \"$MOUNT_DIR/node_modules\" || true",
|
|
254
|
+
"fi",
|
|
255
|
+
"",
|
|
256
|
+
`for DIR in "${opts.docsDir}" "${opts.assetsDir}" "${opts.themesDir}"; do`,
|
|
257
|
+
" mkdir -p \"$MOUNT_DIR/$DIR\"",
|
|
258
|
+
" if [ -d \"/app/.seed/$DIR\" ] && [ -z \"$(ls -A \"$MOUNT_DIR/$DIR\" 2>/dev/null)\" ]; then",
|
|
259
|
+
" cp -R \"/app/.seed/$DIR/.\" \"$MOUNT_DIR/$DIR/\" || true",
|
|
260
|
+
" fi",
|
|
261
|
+
" rm -rf \"/app/$DIR\"",
|
|
262
|
+
" ln -s \"$MOUNT_DIR/$DIR\" \"/app/$DIR\"",
|
|
263
|
+
"done",
|
|
264
|
+
"",
|
|
265
|
+
"# Initialize Git baseline on persistent storage so the Changes diff panel works in cloud",
|
|
266
|
+
"if command -v git >/dev/null 2>&1; then",
|
|
267
|
+
" if [ ! -d \"$MOUNT_DIR/.git\" ]; then",
|
|
268
|
+
" git -C \"$MOUNT_DIR\" init -q || true",
|
|
269
|
+
" git -C \"$MOUNT_DIR\" config user.email \"cloud@open-doc.local\" || true",
|
|
270
|
+
" git -C \"$MOUNT_DIR\" config user.name \"open-doc cloud\" || true",
|
|
271
|
+
" git -C \"$MOUNT_DIR\" add -A || true",
|
|
272
|
+
" git -C \"$MOUNT_DIR\" commit -q -m \"Initial cloud baseline\" --allow-empty || true",
|
|
273
|
+
" fi",
|
|
274
|
+
" rm -rf /app/.git",
|
|
275
|
+
" ln -s \"$MOUNT_DIR/.git\" /app/.git || true",
|
|
276
|
+
"fi",
|
|
277
|
+
"",
|
|
278
|
+
"exec npx open-doc dev --host 0.0.0.0 --port \"${PORT:-8080}\" --no-skills-check --mcp",
|
|
279
|
+
""
|
|
280
|
+
].join("\n");
|
|
281
|
+
}
|
|
282
|
+
function generateDockerfile(opts) {
|
|
283
|
+
const lines = [
|
|
284
|
+
"FROM node:22-slim",
|
|
285
|
+
"ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0",
|
|
286
|
+
"RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && rm -rf /var/lib/apt/lists/*",
|
|
287
|
+
"WORKDIR /app",
|
|
288
|
+
"COPY . .",
|
|
289
|
+
opts.packageManager === "pnpm" ? "RUN corepack enable && pnpm install --no-frozen-lockfile --shamefully-hoist" : opts.packageManager === "yarn" ? "RUN corepack enable && yarn install" : "RUN npm install"
|
|
290
|
+
];
|
|
291
|
+
if (opts.mode === "static") lines.push("RUN npx open-doc build");
|
|
292
|
+
else lines.push(`RUN mkdir -p /app/.seed && for DIR in "${opts.docsDir}" "${opts.assetsDir}" "${opts.themesDir}"; do if [ -d "/app/$DIR" ]; then cp -R "/app/$DIR" "/app/.seed/$DIR"; fi; done`);
|
|
293
|
+
lines.push("RUN chmod +x /app/.open-doc-entrypoint.sh", "ENV NODE_ENV=development", "ENV OPEN_DOC_CLOUD=1", "ENV OPEN_DOC_MOUNT_DIR=/mnt/gcs", "ENV PORT=8080", "EXPOSE 8080", "CMD [\"/app/.open-doc-entrypoint.sh\"]", "");
|
|
294
|
+
return lines.join("\n");
|
|
295
|
+
}
|
|
296
|
+
function generateDockerignore() {
|
|
297
|
+
return [
|
|
298
|
+
"node_modules",
|
|
299
|
+
"dist",
|
|
300
|
+
"out",
|
|
301
|
+
".git",
|
|
302
|
+
".DS_Store",
|
|
303
|
+
".open-doc-cloud.json",
|
|
304
|
+
"*.log",
|
|
305
|
+
""
|
|
306
|
+
].join("\n");
|
|
307
|
+
}
|
|
308
|
+
function buildGcloudDeployArgs(opts) {
|
|
309
|
+
const baseArgs = [
|
|
310
|
+
"run",
|
|
311
|
+
"deploy",
|
|
312
|
+
opts.service,
|
|
313
|
+
"--source",
|
|
314
|
+
".",
|
|
315
|
+
"--project",
|
|
316
|
+
opts.project,
|
|
317
|
+
"--region",
|
|
318
|
+
opts.region,
|
|
319
|
+
"--execution-environment",
|
|
320
|
+
"gen2",
|
|
321
|
+
"--port",
|
|
322
|
+
"8080",
|
|
323
|
+
"--memory",
|
|
324
|
+
opts.memory,
|
|
325
|
+
"--allow-unauthenticated",
|
|
326
|
+
"--quiet"
|
|
327
|
+
];
|
|
328
|
+
if (opts.mode === "editable") baseArgs.push("--max-instances", "1", "--min-instances", "0", "--add-volume", `name=open-doc-storage,type=cloud-storage,bucket=${opts.bucket}`, "--add-volume-mount", "volume=open-doc-storage,mount-path=/mnt/gcs", "--set-env-vars", `OPEN_DOC_CLOUD=1,OPEN_DOC_MOUNT_DIR=/mnt/gcs,OPEN_DOC_MCP_TOKEN=${opts.mcpToken}`);
|
|
329
|
+
else baseArgs.push("--set-env-vars", "OPEN_DOC_CLOUD=1");
|
|
330
|
+
return baseArgs;
|
|
331
|
+
}
|
|
332
|
+
function formatAntigravityMcpSnippet(service, serviceUrl, mcpToken) {
|
|
333
|
+
const cleanUrl = serviceUrl.replace(/\/$/, "");
|
|
334
|
+
const snippet = { mcpServers: { [`${service}-cloud`]: {
|
|
335
|
+
serverUrl: `${cleanUrl}/mcp`,
|
|
336
|
+
headers: { Authorization: `Bearer ${mcpToken}` }
|
|
337
|
+
} } };
|
|
338
|
+
return JSON.stringify(snippet, null, 2);
|
|
339
|
+
}
|
|
340
|
+
async function promptForProject(accessibleProjects) {
|
|
341
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY || accessibleProjects.length === 0) return null;
|
|
342
|
+
process.stdout.write(`${chalk.bold("\nSelect a Google Cloud project for deployment:")}\n`);
|
|
343
|
+
accessibleProjects.slice(0, 15).forEach((p, idx) => {
|
|
344
|
+
process.stdout.write(` ${chalk.cyan(`${idx + 1})`)} ${p}\n`);
|
|
345
|
+
});
|
|
346
|
+
const rl = readline.createInterface({
|
|
347
|
+
input: process.stdin,
|
|
348
|
+
output: process.stdout
|
|
349
|
+
});
|
|
350
|
+
try {
|
|
351
|
+
const answer = (await rl.question(`\nEnter project number (1-${Math.min(15, accessibleProjects.length)}) or project ID: `)).trim();
|
|
352
|
+
if (!answer) return null;
|
|
353
|
+
const num = Number(answer);
|
|
354
|
+
if (Number.isInteger(num) && num >= 1 && num <= accessibleProjects.length) return accessibleProjects[num - 1];
|
|
355
|
+
return answer;
|
|
356
|
+
} finally {
|
|
357
|
+
rl.close();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
async function resolveGcpDeployOptions(userCwd, flags = {}, runner = defaultRunner, allowInteractive = true) {
|
|
361
|
+
const config = await loadUserConfig(userCwd);
|
|
362
|
+
const gcpCfg = config.deploy?.gcp ?? {};
|
|
363
|
+
const state = readCloudState(userCwd);
|
|
364
|
+
const gcloudDefaultRes = runner("gcloud", [
|
|
365
|
+
"config",
|
|
366
|
+
"get-value",
|
|
367
|
+
"project"
|
|
368
|
+
]);
|
|
369
|
+
const gcloudDefault = gcloudDefaultRes.ok && gcloudDefaultRes.stdout && gcloudDefaultRes.stdout !== "(unset)" ? gcloudDefaultRes.stdout.trim() : void 0;
|
|
370
|
+
let project = flags.project ?? gcpCfg.project ?? state.project ?? gcloudDefault;
|
|
371
|
+
if (!project && allowInteractive) {
|
|
372
|
+
const listRes = runner("gcloud", [
|
|
373
|
+
"projects",
|
|
374
|
+
"list",
|
|
375
|
+
"--limit=15",
|
|
376
|
+
"--format=value(projectId)"
|
|
377
|
+
]);
|
|
378
|
+
project = await promptForProject(listRes.ok ? listRes.stdout.split(/\r?\n/).map((s) => s.trim()).filter(Boolean) : []) ?? void 0;
|
|
379
|
+
}
|
|
380
|
+
if (!project) throw new Error("Missing GCP project ID. Pass `--project <PROJECT_ID>`, set `deploy.gcp.project` in `open-doc.config.ts`, or run `gcloud config set project <PROJECT_ID>`.");
|
|
381
|
+
const region = flags.region ?? gcpCfg.region ?? state.region ?? "asia-east1";
|
|
382
|
+
const service = flags.service ?? gcpCfg.service ?? state.service ?? inferDefaultServiceName(userCwd);
|
|
383
|
+
const bucket = flags.bucket ?? gcpCfg.bucket ?? state.bucket ?? defaultBucketName(project, service);
|
|
384
|
+
const mode = flags.mode ?? gcpCfg.mode ?? state.mode ?? "editable";
|
|
385
|
+
const memory = flags.memory ?? gcpCfg.memory ?? state.memory ?? "1Gi";
|
|
386
|
+
const mcpToken = flags.token ?? process.env.OPEN_DOC_MCP_TOKEN ?? state.mcpToken ?? `od_mcp_${randomBytes(24).toString("hex")}`;
|
|
387
|
+
return {
|
|
388
|
+
userCwd,
|
|
389
|
+
docsDir: config.docsDir ?? "docs",
|
|
390
|
+
assetsDir: config.assetsDir ?? "assets",
|
|
391
|
+
themesDir: config.themesDir ?? "themes",
|
|
392
|
+
project,
|
|
393
|
+
region,
|
|
394
|
+
service,
|
|
395
|
+
bucket,
|
|
396
|
+
mode,
|
|
397
|
+
memory,
|
|
398
|
+
mcpToken,
|
|
399
|
+
packageManager: detectPackageManager(userCwd)
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
async function runGcpCheck(flags = {}, userCwd = process.cwd(), runner = defaultRunner) {
|
|
403
|
+
const report = await inspectGcpEnvironment(userCwd, flags, runner);
|
|
404
|
+
if (flags.json) {
|
|
405
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
406
|
+
return report;
|
|
407
|
+
}
|
|
408
|
+
process.stdout.write(`\n${chalk.bold("open-doc deploy gcp — Environment Check")}\n\n`);
|
|
409
|
+
for (const item of report.items) {
|
|
410
|
+
const icon = item.status === "ok" ? chalk.green("✔") : item.status === "warn" ? chalk.yellow("!") : chalk.red("✖");
|
|
411
|
+
process.stdout.write(` ${icon} ${chalk.bold(item.label)}: ${item.detail}\n`);
|
|
412
|
+
if (item.remedy) process.stdout.write(` ${chalk.dim(`→ ${item.remedy}`)}\n`);
|
|
413
|
+
}
|
|
414
|
+
process.stdout.write("\n");
|
|
415
|
+
return report;
|
|
416
|
+
}
|
|
417
|
+
function syncFoldersWithGcs(direction, opts, flags, runner) {
|
|
418
|
+
const dirs = [
|
|
419
|
+
opts.docsDir,
|
|
420
|
+
opts.assetsDir,
|
|
421
|
+
opts.themesDir
|
|
422
|
+
];
|
|
423
|
+
for (const dir of dirs) {
|
|
424
|
+
const localPath = path.join(opts.userCwd, dir);
|
|
425
|
+
const remoteUri = `gs://${opts.bucket}/${dir}`;
|
|
426
|
+
if (direction === "push" && !existsSync(localPath)) continue;
|
|
427
|
+
if (direction === "pull" && !existsSync(localPath) && !flags.dryRun) mkdirSync(localPath, { recursive: true });
|
|
428
|
+
const args = [
|
|
429
|
+
"storage",
|
|
430
|
+
"rsync",
|
|
431
|
+
direction === "push" ? localPath : remoteUri,
|
|
432
|
+
direction === "push" ? remoteUri : localPath,
|
|
433
|
+
"--recursive",
|
|
434
|
+
`--project=${opts.project}`
|
|
435
|
+
];
|
|
436
|
+
if (flags.delete) args.push("--delete-unmatched-destination-objects");
|
|
437
|
+
if (flags.dryRun) args.push("--dry-run");
|
|
438
|
+
process.stdout.write(` ${chalk.cyan("↻")} Syncing ${chalk.bold(dir)} (${direction === "push" ? "local → GCS" : "GCS → local"})...\n`);
|
|
439
|
+
if (flags.dryRun) {
|
|
440
|
+
process.stdout.write(` ${chalk.dim(`gcloud ${args.join(" ")}`)}\n`);
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
const res = runner("gcloud", args, { cwd: opts.userCwd });
|
|
444
|
+
if (!res.ok && direction === "pull" && /not found|matched no objects/i.test(res.stderr)) continue;
|
|
445
|
+
if (!res.ok) throw new Error(`Failed syncing ${dir}: ${res.stderr || res.stdout}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
async function runGcpUp(flags = {}, userCwd = process.cwd(), runner = defaultRunner) {
|
|
449
|
+
const fatal = (await inspectGcpEnvironment(userCwd, flags, runner)).items.find((i) => i.status === "fail");
|
|
450
|
+
if (fatal && !flags.dryRun) {
|
|
451
|
+
await runGcpCheck(flags, userCwd, runner);
|
|
452
|
+
throw new Error(`${fatal.label}: ${fatal.detail}. ${fatal.remedy ?? ""}`);
|
|
453
|
+
}
|
|
454
|
+
const opts = await resolveGcpDeployOptions(userCwd, flags, runner, !flags.dryRun);
|
|
455
|
+
process.stdout.write(`\n${chalk.bold("Deploying open-doc to Google Cloud Run")}\n`);
|
|
456
|
+
process.stdout.write(` ${chalk.dim("Project:")} ${chalk.cyan(opts.project)}\n`);
|
|
457
|
+
process.stdout.write(` ${chalk.dim("Region:")} ${chalk.cyan(opts.region)}\n`);
|
|
458
|
+
process.stdout.write(` ${chalk.dim("Service:")} ${chalk.cyan(opts.service)}\n`);
|
|
459
|
+
process.stdout.write(` ${chalk.dim("Mode:")} ${chalk.cyan(opts.mode)}\n`);
|
|
460
|
+
if (opts.mode === "editable") process.stdout.write(` ${chalk.dim("Bucket:")} ${chalk.cyan(`gs://${opts.bucket}`)}\n`);
|
|
461
|
+
process.stdout.write("\n");
|
|
462
|
+
const deployArgs = buildGcloudDeployArgs(opts);
|
|
463
|
+
if (flags.dryRun) {
|
|
464
|
+
process.stdout.write(`${chalk.yellow("[dry-run]")} Generated commands:\n`);
|
|
465
|
+
process.stdout.write(` 1. gcloud services enable ${REQUIRED_GCP_APIS.join(" ")} --project=${opts.project}\n`);
|
|
466
|
+
if (opts.mode === "editable") {
|
|
467
|
+
process.stdout.write(` 2. gcloud storage buckets create gs://${opts.bucket} --project=${opts.project} --location=${opts.region}\n`);
|
|
468
|
+
syncFoldersWithGcs("push", opts, { dryRun: true }, runner);
|
|
469
|
+
}
|
|
470
|
+
process.stdout.write(` 3. gcloud ${deployArgs.join(" ")}\n\n`);
|
|
471
|
+
if (opts.mode === "editable") {
|
|
472
|
+
process.stdout.write(`${chalk.bold("Antigravity MCP config preview:")}\n`);
|
|
473
|
+
process.stdout.write(`${formatAntigravityMcpSnippet(opts.service, `https://${opts.service}-<hash>.${opts.region}.run.app`, opts.mcpToken)}\n`);
|
|
474
|
+
}
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
process.stdout.write(` ${chalk.cyan("1/4")} Ensuring required GCP APIs are enabled...\n`);
|
|
478
|
+
const apiRes = runner("gcloud", [
|
|
479
|
+
"services",
|
|
480
|
+
"enable",
|
|
481
|
+
...REQUIRED_GCP_APIS,
|
|
482
|
+
`--project=${opts.project}`
|
|
483
|
+
]);
|
|
484
|
+
if (!apiRes.ok) throw new Error(`Failed enabling GCP APIs: ${apiRes.stderr || apiRes.stdout}`);
|
|
485
|
+
if (opts.mode === "editable") {
|
|
486
|
+
process.stdout.write(` ${chalk.cyan("2/4")} Preparing Cloud Storage bucket ${chalk.bold(`gs://${opts.bucket}`)}...\n`);
|
|
487
|
+
if (!runner("gcloud", [
|
|
488
|
+
"storage",
|
|
489
|
+
"buckets",
|
|
490
|
+
"describe",
|
|
491
|
+
`gs://${opts.bucket}`,
|
|
492
|
+
`--project=${opts.project}`
|
|
493
|
+
]).ok) {
|
|
494
|
+
const createBucket = runner("gcloud", [
|
|
495
|
+
"storage",
|
|
496
|
+
"buckets",
|
|
497
|
+
"create",
|
|
498
|
+
`gs://${opts.bucket}`,
|
|
499
|
+
`--project=${opts.project}`,
|
|
500
|
+
`--location=${opts.region}`,
|
|
501
|
+
"--uniform-bucket-level-access"
|
|
502
|
+
]);
|
|
503
|
+
if (!createBucket.ok) throw new Error(`Failed creating bucket gs://${opts.bucket}: ${createBucket.stderr || createBucket.stdout}`);
|
|
504
|
+
}
|
|
505
|
+
const projNumRes = runner("gcloud", [
|
|
506
|
+
"projects",
|
|
507
|
+
"describe",
|
|
508
|
+
opts.project,
|
|
509
|
+
"--format=value(projectNumber)"
|
|
510
|
+
]);
|
|
511
|
+
const projNum = projNumRes.ok ? projNumRes.stdout.trim() : "";
|
|
512
|
+
if (projNum) {
|
|
513
|
+
const computeSa = `${projNum}-compute@developer.gserviceaccount.com`;
|
|
514
|
+
runner("gcloud", [
|
|
515
|
+
"storage",
|
|
516
|
+
"buckets",
|
|
517
|
+
"add-iam-policy-binding",
|
|
518
|
+
`gs://${opts.bucket}`,
|
|
519
|
+
`--member=serviceAccount:${computeSa}`,
|
|
520
|
+
"--role=roles/storage.objectAdmin",
|
|
521
|
+
`--project=${opts.project}`
|
|
522
|
+
]);
|
|
523
|
+
}
|
|
524
|
+
syncFoldersWithGcs("push", opts, {}, runner);
|
|
525
|
+
}
|
|
526
|
+
process.stdout.write(` ${chalk.cyan("3/4")} Building and deploying container to Cloud Run...\n`);
|
|
527
|
+
const dockerfilePath = path.join(userCwd, "Dockerfile");
|
|
528
|
+
const entrypointPath = path.join(userCwd, ".open-doc-entrypoint.sh");
|
|
529
|
+
const dockerignorePath = path.join(userCwd, ".dockerignore");
|
|
530
|
+
const hadDockerfile = existsSync(dockerfilePath);
|
|
531
|
+
const hadEntrypoint = existsSync(entrypointPath);
|
|
532
|
+
const hadDockerignore = existsSync(dockerignorePath);
|
|
533
|
+
try {
|
|
534
|
+
if (!hadDockerfile) writeFileSync(dockerfilePath, generateDockerfile(opts), "utf8");
|
|
535
|
+
if (!hadEntrypoint) writeFileSync(entrypointPath, generateEntrypointScript(opts), {
|
|
536
|
+
encoding: "utf8",
|
|
537
|
+
mode: 493
|
|
538
|
+
});
|
|
539
|
+
if (!hadDockerignore) writeFileSync(dockerignorePath, generateDockerignore(), "utf8");
|
|
540
|
+
if (!runner("gcloud", deployArgs, {
|
|
541
|
+
cwd: userCwd,
|
|
542
|
+
inherit: true
|
|
543
|
+
}).ok) throw new Error("Cloud Run deployment failed.");
|
|
544
|
+
} finally {
|
|
545
|
+
if (!hadDockerfile && existsSync(dockerfilePath)) rmSync(dockerfilePath, { force: true });
|
|
546
|
+
if (!hadEntrypoint && existsSync(entrypointPath)) rmSync(entrypointPath, { force: true });
|
|
547
|
+
if (!hadDockerignore && existsSync(dockerignorePath)) rmSync(dockerignorePath, { force: true });
|
|
548
|
+
}
|
|
549
|
+
const urlRes = runner("gcloud", [
|
|
550
|
+
"run",
|
|
551
|
+
"services",
|
|
552
|
+
"describe",
|
|
553
|
+
opts.service,
|
|
554
|
+
`--project=${opts.project}`,
|
|
555
|
+
`--region=${opts.region}`,
|
|
556
|
+
"--format=value(status.url)"
|
|
557
|
+
]);
|
|
558
|
+
const serviceUrl = urlRes.ok && urlRes.stdout ? urlRes.stdout.trim() : `https://${opts.service}.run.app`;
|
|
559
|
+
writeCloudState(userCwd, {
|
|
560
|
+
provider: "gcp",
|
|
561
|
+
project: opts.project,
|
|
562
|
+
region: opts.region,
|
|
563
|
+
service: opts.service,
|
|
564
|
+
bucket: opts.bucket,
|
|
565
|
+
mode: opts.mode,
|
|
566
|
+
memory: opts.memory,
|
|
567
|
+
mcpToken: opts.mcpToken,
|
|
568
|
+
serviceUrl,
|
|
569
|
+
stopped: false,
|
|
570
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
571
|
+
});
|
|
572
|
+
process.stdout.write(`\n ${chalk.green("✔")} ${chalk.bold("Deployment complete!")}\n`);
|
|
573
|
+
process.stdout.write(` ${chalk.green("➜")} ${chalk.bold("Cloud URL")}: ${chalk.cyan(serviceUrl)}\n`);
|
|
574
|
+
if (opts.mode === "editable") {
|
|
575
|
+
process.stdout.write(` ${chalk.green("➜")} ${chalk.bold("MCP URL")}: ${chalk.cyan(`${serviceUrl.replace(/\/$/, "")}/mcp`)}\n\n`);
|
|
576
|
+
process.stdout.write(`${chalk.bold("Add this to your Antigravity `mcp_config.json` to edit cloud pages directly:")}\n`);
|
|
577
|
+
process.stdout.write(`${chalk.dim(formatAntigravityMcpSnippet(opts.service, serviceUrl, opts.mcpToken))}\n\n`);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async function runGcpStatus(flags = {}, userCwd = process.cwd(), runner = defaultRunner) {
|
|
581
|
+
const opts = await resolveGcpDeployOptions(userCwd, flags, runner, false);
|
|
582
|
+
const state = readCloudState(userCwd);
|
|
583
|
+
const descRes = runner("gcloud", [
|
|
584
|
+
"run",
|
|
585
|
+
"services",
|
|
586
|
+
"describe",
|
|
587
|
+
opts.service,
|
|
588
|
+
`--project=${opts.project}`,
|
|
589
|
+
`--region=${opts.region}`,
|
|
590
|
+
"--format=value(status.url)"
|
|
591
|
+
]);
|
|
592
|
+
const deployed = descRes.ok && Boolean(descRes.stdout.trim());
|
|
593
|
+
const serviceUrl = deployed ? descRes.stdout.trim() : state.serviceUrl;
|
|
594
|
+
const iamRes = deployed ? runner("gcloud", [
|
|
595
|
+
"run",
|
|
596
|
+
"services",
|
|
597
|
+
"get-iam-policy",
|
|
598
|
+
opts.service,
|
|
599
|
+
`--project=${opts.project}`,
|
|
600
|
+
`--region=${opts.region}`,
|
|
601
|
+
"--format=json"
|
|
602
|
+
]) : {
|
|
603
|
+
ok: false,
|
|
604
|
+
status: 1,
|
|
605
|
+
stdout: "",
|
|
606
|
+
stderr: ""
|
|
607
|
+
};
|
|
608
|
+
const publicAccess = iamRes.ok && iamRes.stdout.includes("allUsers");
|
|
609
|
+
const payload = {
|
|
610
|
+
deployed,
|
|
611
|
+
project: opts.project,
|
|
612
|
+
region: opts.region,
|
|
613
|
+
service: opts.service,
|
|
614
|
+
bucket: opts.bucket,
|
|
615
|
+
mode: opts.mode,
|
|
616
|
+
serviceUrl: serviceUrl ?? null,
|
|
617
|
+
publicAccess,
|
|
618
|
+
mcpEndpoint: serviceUrl && opts.mode === "editable" ? `${serviceUrl.replace(/\/$/, "")}/mcp` : null
|
|
619
|
+
};
|
|
620
|
+
if (flags.json) {
|
|
621
|
+
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
process.stdout.write(`\n${chalk.bold("open-doc deploy gcp — Service Status")}\n\n`);
|
|
625
|
+
process.stdout.write(` ${chalk.dim("Status:")} ${!deployed ? chalk.red("Not deployed") : publicAccess ? chalk.green("Active (publicly reachable)") : chalk.yellow("Stopped / Locked (403 to external traffic, scaled to 0)")}\n`);
|
|
626
|
+
process.stdout.write(` ${chalk.dim("Project:")} ${opts.project}\n`);
|
|
627
|
+
process.stdout.write(` ${chalk.dim("Region:")} ${opts.region}\n`);
|
|
628
|
+
process.stdout.write(` ${chalk.dim("Service:")} ${opts.service}\n`);
|
|
629
|
+
process.stdout.write(` ${chalk.dim("Bucket:")} gs://${opts.bucket}\n`);
|
|
630
|
+
if (serviceUrl) {
|
|
631
|
+
process.stdout.write(` ${chalk.dim("Cloud URL:")} ${chalk.cyan(serviceUrl)}\n`);
|
|
632
|
+
if (opts.mode === "editable") process.stdout.write(`\n${chalk.bold("Antigravity MCP Configuration:")}\n${chalk.dim(formatAntigravityMcpSnippet(opts.service, serviceUrl, opts.mcpToken))}\n`);
|
|
633
|
+
}
|
|
634
|
+
process.stdout.write("\n");
|
|
635
|
+
}
|
|
636
|
+
async function runGcpPull(flags = {}, userCwd = process.cwd(), runner = defaultRunner) {
|
|
637
|
+
const opts = await resolveGcpDeployOptions(userCwd, flags, runner, false);
|
|
638
|
+
process.stdout.write(`\n${chalk.bold(`Pulling latest documents from gs://${opts.bucket}...`)}\n`);
|
|
639
|
+
syncFoldersWithGcs("pull", opts, {
|
|
640
|
+
dryRun: flags.dryRun,
|
|
641
|
+
delete: flags.delete
|
|
642
|
+
}, runner);
|
|
643
|
+
process.stdout.write(` ${chalk.green("✔")} Local workspace updated from Cloud Storage.\n\n`);
|
|
644
|
+
}
|
|
645
|
+
async function runGcpPush(flags = {}, userCwd = process.cwd(), runner = defaultRunner) {
|
|
646
|
+
const opts = await resolveGcpDeployOptions(userCwd, flags, runner, false);
|
|
647
|
+
process.stdout.write(`\n${chalk.bold(`Pushing local documents to gs://${opts.bucket}...`)}\n`);
|
|
648
|
+
syncFoldersWithGcs("push", opts, {
|
|
649
|
+
dryRun: flags.dryRun,
|
|
650
|
+
delete: flags.delete
|
|
651
|
+
}, runner);
|
|
652
|
+
process.stdout.write(` ${chalk.green("✔")} Cloud Storage updated from local workspace.\n\n`);
|
|
653
|
+
}
|
|
654
|
+
async function runGcpStop(flags = {}, userCwd = process.cwd(), runner = defaultRunner) {
|
|
655
|
+
const opts = await resolveGcpDeployOptions(userCwd, flags, runner, false);
|
|
656
|
+
if (flags.pull) await runGcpPull(flags, userCwd, runner);
|
|
657
|
+
process.stdout.write(`\n${chalk.bold(`Stopping public access to Cloud Run service "${opts.service}"...`)}\n`);
|
|
658
|
+
const res = runner("gcloud", [
|
|
659
|
+
"run",
|
|
660
|
+
"services",
|
|
661
|
+
"remove-iam-policy-binding",
|
|
662
|
+
opts.service,
|
|
663
|
+
"--member=allUsers",
|
|
664
|
+
"--role=roles/run.invoker",
|
|
665
|
+
`--project=${opts.project}`,
|
|
666
|
+
`--region=${opts.region}`,
|
|
667
|
+
"--quiet"
|
|
668
|
+
]);
|
|
669
|
+
if (!res.ok && !/Policy binding .* not found/i.test(res.stderr)) throw new Error(`Failed stopping service: ${res.stderr || res.stdout}`);
|
|
670
|
+
const prev = readCloudState(userCwd);
|
|
671
|
+
writeCloudState(userCwd, {
|
|
672
|
+
provider: "gcp",
|
|
673
|
+
project: opts.project,
|
|
674
|
+
region: opts.region,
|
|
675
|
+
service: opts.service,
|
|
676
|
+
bucket: opts.bucket,
|
|
677
|
+
mode: opts.mode,
|
|
678
|
+
memory: opts.memory,
|
|
679
|
+
mcpToken: opts.mcpToken,
|
|
680
|
+
...prev.serviceUrl ? { serviceUrl: prev.serviceUrl } : {},
|
|
681
|
+
stopped: true,
|
|
682
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
683
|
+
});
|
|
684
|
+
process.stdout.write(` ${chalk.green("✔")} Service "${opts.service}" is now locked (403) and scaled to 0 instances.\n`);
|
|
685
|
+
process.stdout.write(` ${chalk.dim("Run `open-doc deploy gcp start` anytime to restore public access.")}\n\n`);
|
|
686
|
+
}
|
|
687
|
+
async function runGcpStart(flags = {}, userCwd = process.cwd(), runner = defaultRunner) {
|
|
688
|
+
const opts = await resolveGcpDeployOptions(userCwd, flags, runner, false);
|
|
689
|
+
process.stdout.write(`\n${chalk.bold(`Restoring public access to Cloud Run service "${opts.service}"...`)}\n`);
|
|
690
|
+
const res = runner("gcloud", [
|
|
691
|
+
"run",
|
|
692
|
+
"services",
|
|
693
|
+
"add-iam-policy-binding",
|
|
694
|
+
opts.service,
|
|
695
|
+
"--member=allUsers",
|
|
696
|
+
"--role=roles/run.invoker",
|
|
697
|
+
`--project=${opts.project}`,
|
|
698
|
+
`--region=${opts.region}`,
|
|
699
|
+
"--quiet"
|
|
700
|
+
]);
|
|
701
|
+
if (!res.ok) throw new Error(`Failed starting service: ${res.stderr || res.stdout}`);
|
|
702
|
+
const prev = readCloudState(userCwd);
|
|
703
|
+
writeCloudState(userCwd, {
|
|
704
|
+
provider: "gcp",
|
|
705
|
+
project: opts.project,
|
|
706
|
+
region: opts.region,
|
|
707
|
+
service: opts.service,
|
|
708
|
+
bucket: opts.bucket,
|
|
709
|
+
mode: opts.mode,
|
|
710
|
+
memory: opts.memory,
|
|
711
|
+
mcpToken: opts.mcpToken,
|
|
712
|
+
...prev.serviceUrl ? { serviceUrl: prev.serviceUrl } : {},
|
|
713
|
+
stopped: false,
|
|
714
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
715
|
+
});
|
|
716
|
+
process.stdout.write(` ${chalk.green("✔")} Service "${opts.service}" is live again!\n\n`);
|
|
717
|
+
}
|
|
718
|
+
async function runGcpDown(flags = {}, userCwd = process.cwd(), runner = defaultRunner) {
|
|
719
|
+
const opts = await resolveGcpDeployOptions(userCwd, flags, runner, false);
|
|
720
|
+
if (!flags.skipPull && opts.mode === "editable") {
|
|
721
|
+
process.stdout.write(`\n ${chalk.cyan("1/2")} Backing up latest cloud edits from gs://${opts.bucket} to local workspace...\n`);
|
|
722
|
+
syncFoldersWithGcs("pull", opts, { dryRun: flags.dryRun }, runner);
|
|
723
|
+
}
|
|
724
|
+
process.stdout.write(` ${chalk.cyan("2/2")} Deleting Cloud Run service "${opts.service}" in ${opts.region}...\n`);
|
|
725
|
+
const delArgs = [
|
|
726
|
+
"run",
|
|
727
|
+
"services",
|
|
728
|
+
"delete",
|
|
729
|
+
opts.service,
|
|
730
|
+
`--project=${opts.project}`,
|
|
731
|
+
`--region=${opts.region}`,
|
|
732
|
+
"--quiet"
|
|
733
|
+
];
|
|
734
|
+
if (flags.dryRun) process.stdout.write(` ${chalk.dim(`gcloud ${delArgs.join(" ")}`)}\n`);
|
|
735
|
+
else {
|
|
736
|
+
const delRes = runner("gcloud", delArgs);
|
|
737
|
+
if (!delRes.ok && !/could not be found|not found/i.test(delRes.stderr)) throw new Error(`Failed deleting Cloud Run service: ${delRes.stderr || delRes.stdout}`);
|
|
738
|
+
}
|
|
739
|
+
if (flags.purgeStorage) {
|
|
740
|
+
const bucketArgs = [
|
|
741
|
+
"storage",
|
|
742
|
+
"rm",
|
|
743
|
+
"--recursive",
|
|
744
|
+
`gs://${opts.bucket}`,
|
|
745
|
+
`--project=${opts.project}`,
|
|
746
|
+
"--quiet"
|
|
747
|
+
];
|
|
748
|
+
process.stdout.write(` ${chalk.yellow("!")} Purging bucket gs://${opts.bucket}...\n`);
|
|
749
|
+
if (flags.dryRun) process.stdout.write(` ${chalk.dim(`gcloud ${bucketArgs.join(" ")}`)}\n`);
|
|
750
|
+
else {
|
|
751
|
+
const rmRes = runner("gcloud", bucketArgs);
|
|
752
|
+
if (!rmRes.ok && !/not found/i.test(rmRes.stderr)) throw new Error(`Failed purging bucket: ${rmRes.stderr || rmRes.stdout}`);
|
|
753
|
+
}
|
|
754
|
+
} else process.stdout.write(` ${chalk.dim(`Cloud Storage bucket gs://${opts.bucket} was preserved (pass --purge-storage to delete it).`)}\n`);
|
|
755
|
+
process.stdout.write(` ${chalk.green("✔")} Cloud Run service "${opts.service}" torn down.\n\n`);
|
|
756
|
+
}
|
|
757
|
+
//#endregion
|
|
758
|
+
export { runGcpCheck, runGcpDown, runGcpPull, runGcpPush, runGcpStart, runGcpStatus, runGcpStop, runGcpUp };
|