@dz9systems/vibeinfra 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -2
- package/TERMS.md +19 -0
- package/dist/bin.js +841 -0
- package/dist/chunks/chunk-ZDFLQZGF.js +1452 -0
- package/dist/chunks/src-AV3FZUMU.js +794 -0
- package/package.json +46 -4
package/dist/bin.js
ADDED
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
VibeInfraError,
|
|
4
|
+
assertProjectId,
|
|
5
|
+
createDeploymentPlan,
|
|
6
|
+
deployApplication,
|
|
7
|
+
exitCodeFor,
|
|
8
|
+
findSecretIds,
|
|
9
|
+
isPermissiveRules,
|
|
10
|
+
loadPlanContext,
|
|
11
|
+
readJournal,
|
|
12
|
+
readOptionalJson,
|
|
13
|
+
redact,
|
|
14
|
+
resumeOptions,
|
|
15
|
+
toVibeInfraError
|
|
16
|
+
} from "./chunks/chunk-ZDFLQZGF.js";
|
|
17
|
+
|
|
18
|
+
// packages/cli/src/bin.ts
|
|
19
|
+
import readline from "node:readline";
|
|
20
|
+
|
|
21
|
+
// packages/cli/src/program.ts
|
|
22
|
+
import { Command, CommanderError } from "commander";
|
|
23
|
+
|
|
24
|
+
// packages/framework-detector/src/analyze.ts
|
|
25
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
26
|
+
import path from "node:path";
|
|
27
|
+
var TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
28
|
+
".js",
|
|
29
|
+
".jsx",
|
|
30
|
+
".ts",
|
|
31
|
+
".tsx",
|
|
32
|
+
".mjs",
|
|
33
|
+
".cjs",
|
|
34
|
+
".mts",
|
|
35
|
+
".cts",
|
|
36
|
+
".json",
|
|
37
|
+
".rules",
|
|
38
|
+
".html",
|
|
39
|
+
".css",
|
|
40
|
+
".vue",
|
|
41
|
+
".md",
|
|
42
|
+
".yml",
|
|
43
|
+
".yaml",
|
|
44
|
+
".txt"
|
|
45
|
+
]);
|
|
46
|
+
var SKIP_DIRECTORIES = /* @__PURE__ */ new Set(["node_modules", "dist", ".git", ".vibeinfra", ".vibedeploy", "coverage", "build"]);
|
|
47
|
+
var LOCKFILES = [
|
|
48
|
+
{ file: "package-lock.json", manager: "npm" },
|
|
49
|
+
{ file: "pnpm-lock.yaml", manager: "pnpm" },
|
|
50
|
+
{ file: "yarn.lock", manager: "yarn" },
|
|
51
|
+
{ file: "bun.lock", manager: "bun" },
|
|
52
|
+
{ file: "bun.lockb", manager: "bun" }
|
|
53
|
+
];
|
|
54
|
+
var VITE_CONFIGS = ["vite.config.ts", "vite.config.js", "vite.config.mjs", "vite.config.cjs", "vite.config.mts", "vite.config.cts"];
|
|
55
|
+
var MAX_FILES = 2e3;
|
|
56
|
+
var MAX_BYTES = 512 * 1024;
|
|
57
|
+
async function analyzeProject(projectPath) {
|
|
58
|
+
const root = path.resolve(projectPath);
|
|
59
|
+
const info = await stat(root).catch(() => null);
|
|
60
|
+
if (!info?.isDirectory()) {
|
|
61
|
+
throw new VibeInfraError({
|
|
62
|
+
code: "project_path_missing",
|
|
63
|
+
message: `Project directory ${root} does not exist.`,
|
|
64
|
+
remediation: "Pass the directory that contains the application's package.json."
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const packageJson = await readOptionalJson(path.join(root, "package.json"));
|
|
68
|
+
const firebaseJson = await readOptionalJson(path.join(root, "firebase.json"));
|
|
69
|
+
const firebaserc = await readOptionalJson(path.join(root, ".firebaserc"));
|
|
70
|
+
const dependencies = {
|
|
71
|
+
...packageJson.value?.dependencies ?? {},
|
|
72
|
+
...packageJson.value?.devDependencies ?? {}
|
|
73
|
+
};
|
|
74
|
+
const viteConfigs = (await Promise.all(VITE_CONFIGS.map(async (file) => await exists(path.join(root, file)) ? file : null))).filter((file) => file !== null);
|
|
75
|
+
const hasViteDependency = Boolean(dependencies.vite) || viteConfigs.length > 0;
|
|
76
|
+
const vite = viteConfigs.length > 0 ? await readViteConfig(root, viteConfigs) : hasViteDependency ? { outDir: "dist", ambiguous: false, appType: null, ssr: false } : emptyVite();
|
|
77
|
+
const packageManagers = await detectPackageManagers(root, packageJson.value?.packageManager);
|
|
78
|
+
const hosting = describeHosting(firebaseJson.value, firebaseJson.error);
|
|
79
|
+
const scan = await scanSource(root);
|
|
80
|
+
const hasFunctionsDirectory = await exists(path.join(root, "functions", "package.json")) || await exists(path.join(root, "functions", "index.js"));
|
|
81
|
+
const framework = packageJson.error ? {
|
|
82
|
+
id: "unknown",
|
|
83
|
+
label: "Unknown",
|
|
84
|
+
supported: false,
|
|
85
|
+
reason: `package.json could not be parsed: ${packageJson.error}`
|
|
86
|
+
} : classifyFramework({
|
|
87
|
+
hasPackageJson: packageJson.value !== null,
|
|
88
|
+
hasVite: hasViteDependency,
|
|
89
|
+
hasReact: Boolean(dependencies.react),
|
|
90
|
+
hasNext: Boolean(dependencies.next),
|
|
91
|
+
hasReactScripts: Boolean(dependencies["react-scripts"])
|
|
92
|
+
});
|
|
93
|
+
const warnings = [];
|
|
94
|
+
if (viteConfigs.length > 1) {
|
|
95
|
+
warnings.push(`Multiple Vite config files were found: ${viteConfigs.join(", ")}.`);
|
|
96
|
+
}
|
|
97
|
+
if (packageManagers.length > 1) {
|
|
98
|
+
warnings.push(`Multiple package manager signals were found: ${packageManagers.join(", ")}.`);
|
|
99
|
+
}
|
|
100
|
+
if (scan.truncated) {
|
|
101
|
+
warnings.push("File inspection reached its limit before the whole project was read.");
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
path: root,
|
|
105
|
+
framework: framework.id,
|
|
106
|
+
frameworkLabel: framework.label,
|
|
107
|
+
supported: framework.supported,
|
|
108
|
+
...framework.reason ? { unsupportedReason: framework.reason } : {},
|
|
109
|
+
packageName: packageJson.value?.name ?? null,
|
|
110
|
+
dependencies: { ...packageJson.value?.dependencies ?? {} },
|
|
111
|
+
devDependencies: { ...packageJson.value?.devDependencies ?? {} },
|
|
112
|
+
packageManagers,
|
|
113
|
+
buildScript: packageJson.value?.scripts?.build ? "build" : null,
|
|
114
|
+
scripts: Object.keys(packageJson.value?.scripts ?? {}),
|
|
115
|
+
viteConfigFiles: viteConfigs,
|
|
116
|
+
viteOutDir: vite.outDir,
|
|
117
|
+
viteOutDirAmbiguous: vite.ambiguous || viteConfigs.length > 1,
|
|
118
|
+
viteAppType: vite.appType,
|
|
119
|
+
viteSsr: vite.ssr,
|
|
120
|
+
spaRewrite: framework.supported && !vite.ssr && vite.appType !== "mpa",
|
|
121
|
+
hostingKind: hosting.kind,
|
|
122
|
+
hostingPublic: hosting.publicDir,
|
|
123
|
+
hostingSite: hosting.site,
|
|
124
|
+
hostingSites: hosting.sites,
|
|
125
|
+
firebaseJson: firebaseJson.error ? null : firebaseJson.value,
|
|
126
|
+
firebaseJsonError: firebaseJson.error,
|
|
127
|
+
firebaserc: firebaserc.error ? null : firebaserc.value,
|
|
128
|
+
firebasercError: firebaserc.error,
|
|
129
|
+
firebaseImports: scan.firebaseImports,
|
|
130
|
+
envReferences: scan.envReferences,
|
|
131
|
+
hasFunctionsDirectory,
|
|
132
|
+
rules: scan.rules,
|
|
133
|
+
secretFindings: scan.secrets,
|
|
134
|
+
warnings,
|
|
135
|
+
scanTruncated: scan.truncated
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function classifyFramework(input) {
|
|
139
|
+
if (!input.hasPackageJson) {
|
|
140
|
+
return { id: "unknown", label: "Unknown", supported: false, reason: "No package.json was found." };
|
|
141
|
+
}
|
|
142
|
+
if (input.hasNext && input.hasVite) {
|
|
143
|
+
return {
|
|
144
|
+
id: "ambiguous",
|
|
145
|
+
label: "Ambiguous",
|
|
146
|
+
supported: false,
|
|
147
|
+
reason: "Both Next.js and Vite are dependencies. VibeInfra will not guess which application to deploy."
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (input.hasNext) {
|
|
151
|
+
return { id: "next", label: "Next.js", supported: false, reason: "Next.js is not supported in Phase 1. Phase 1 deploys a static React + Vite SPA." };
|
|
152
|
+
}
|
|
153
|
+
if (input.hasVite && input.hasReact) {
|
|
154
|
+
return { id: "react-vite", label: "React + Vite", supported: true };
|
|
155
|
+
}
|
|
156
|
+
if (input.hasVite) {
|
|
157
|
+
return { id: "vite", label: "Vite", supported: false, reason: "Vite without React is not supported in Phase 1." };
|
|
158
|
+
}
|
|
159
|
+
if (input.hasReactScripts) {
|
|
160
|
+
return { id: "react", label: "Create React App", supported: false, reason: "Create React App is not supported in Phase 1." };
|
|
161
|
+
}
|
|
162
|
+
if (input.hasReact) {
|
|
163
|
+
return { id: "react", label: "React", supported: false, reason: "React without Vite is not supported in Phase 1." };
|
|
164
|
+
}
|
|
165
|
+
return { id: "unknown", label: "Unknown", supported: false, reason: "No supported React + Vite application was detected." };
|
|
166
|
+
}
|
|
167
|
+
async function detectPackageManagers(root, packageManagerField) {
|
|
168
|
+
const found = /* @__PURE__ */ new Set();
|
|
169
|
+
for (const lockfile of LOCKFILES) {
|
|
170
|
+
if (await exists(path.join(root, lockfile.file))) {
|
|
171
|
+
found.add(lockfile.manager);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const declared = packageManagerField?.split("@")[0];
|
|
175
|
+
if (declared === "npm" || declared === "pnpm" || declared === "yarn" || declared === "bun") {
|
|
176
|
+
found.add(declared);
|
|
177
|
+
}
|
|
178
|
+
return [...found];
|
|
179
|
+
}
|
|
180
|
+
async function readViteConfig(root, files) {
|
|
181
|
+
if (files.length !== 1) {
|
|
182
|
+
return { outDir: null, ambiguous: true, appType: null, ssr: false };
|
|
183
|
+
}
|
|
184
|
+
const text = stripComments(await readFile(path.join(root, files[0]), "utf8"));
|
|
185
|
+
const outDirs = [...text.matchAll(/outDir\s*:\s*['"]([^'"]+)['"]/g)].map((match) => match[1]);
|
|
186
|
+
const unique2 = [...new Set(outDirs)];
|
|
187
|
+
const mentionsOutDir = /\boutDir\b/.test(text);
|
|
188
|
+
const appType = /appType\s*:\s*['"]([^'"]+)['"]/.exec(text)?.[1] ?? null;
|
|
189
|
+
const ssr = /\bssr\s*:\s*(?:true|\{)/.test(text);
|
|
190
|
+
if (mentionsOutDir && unique2.length === 0 || unique2.length > 1) {
|
|
191
|
+
return { outDir: null, ambiguous: true, appType, ssr };
|
|
192
|
+
}
|
|
193
|
+
return { outDir: unique2[0] ?? "dist", ambiguous: false, appType, ssr };
|
|
194
|
+
}
|
|
195
|
+
function emptyVite() {
|
|
196
|
+
return { outDir: null, ambiguous: false, appType: null, ssr: false };
|
|
197
|
+
}
|
|
198
|
+
function describeHosting(config, error) {
|
|
199
|
+
if (error) {
|
|
200
|
+
return { kind: "invalid", publicDir: null, site: null, sites: [] };
|
|
201
|
+
}
|
|
202
|
+
if (!config?.hosting) {
|
|
203
|
+
return { kind: "missing", publicDir: null, site: null, sites: [] };
|
|
204
|
+
}
|
|
205
|
+
if (Array.isArray(config.hosting)) {
|
|
206
|
+
const sites = config.hosting.flatMap((site) => typeof site.site === "string" ? [site.site] : []);
|
|
207
|
+
return { kind: "array", publicDir: null, site: null, sites };
|
|
208
|
+
}
|
|
209
|
+
const hosting = config.hosting;
|
|
210
|
+
if (typeof hosting.source === "string") {
|
|
211
|
+
return { kind: "framework-source", publicDir: nullableString(hosting.public), site: nullableString(hosting.site), sites: hosting.site ? [hosting.site] : [] };
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
kind: "object",
|
|
215
|
+
publicDir: nullableString(hosting.public),
|
|
216
|
+
site: nullableString(hosting.site),
|
|
217
|
+
sites: hosting.site ? [hosting.site] : []
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
async function scanSource(root) {
|
|
221
|
+
const firebaseImports = /* @__PURE__ */ new Set();
|
|
222
|
+
const envReferences = /* @__PURE__ */ new Set();
|
|
223
|
+
const rules = [];
|
|
224
|
+
const secrets = [];
|
|
225
|
+
const state = { files: 0, truncated: false };
|
|
226
|
+
await walk(root, async (file) => {
|
|
227
|
+
const relative = path.relative(root, file).split(path.sep).join("/");
|
|
228
|
+
const name = path.basename(file);
|
|
229
|
+
if (!isScannable(name)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const fileStat = await stat(file);
|
|
233
|
+
if (fileStat.size > MAX_BYTES) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const text = await readFile(file, "utf8");
|
|
237
|
+
for (const match of text.matchAll(/from\s+['"](firebase(?:\/[^'"]*)?)['"]/g)) {
|
|
238
|
+
firebaseImports.add(match[1]);
|
|
239
|
+
}
|
|
240
|
+
for (const match of text.matchAll(/require\(\s*['"](firebase(?:\/[^'"]*)?)['"]\s*\)/g)) {
|
|
241
|
+
firebaseImports.add(match[1]);
|
|
242
|
+
}
|
|
243
|
+
for (const match of text.matchAll(/\b(VITE_[A-Z0-9_]+)\b/g)) {
|
|
244
|
+
envReferences.add(match[1]);
|
|
245
|
+
}
|
|
246
|
+
for (const match of text.matchAll(/\bimport\.meta\.env\.([A-Z0-9_]+)/g)) {
|
|
247
|
+
envReferences.add(match[1]);
|
|
248
|
+
}
|
|
249
|
+
if (name.endsWith(".rules")) {
|
|
250
|
+
rules.push({ path: relative, permissive: isPermissiveRules(text) });
|
|
251
|
+
}
|
|
252
|
+
for (const id of findSecretIds(text)) {
|
|
253
|
+
secrets.push({ path: relative, id });
|
|
254
|
+
}
|
|
255
|
+
}, state);
|
|
256
|
+
return {
|
|
257
|
+
firebaseImports: [...firebaseImports].sort(),
|
|
258
|
+
envReferences: [...envReferences].sort(),
|
|
259
|
+
rules,
|
|
260
|
+
secrets,
|
|
261
|
+
truncated: state.truncated
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
async function walk(directory, visit, state) {
|
|
265
|
+
if (state.truncated) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
269
|
+
for (const entry of entries) {
|
|
270
|
+
if (state.files >= MAX_FILES) {
|
|
271
|
+
state.truncated = true;
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (entry.isSymbolicLink()) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const full = path.join(directory, entry.name);
|
|
278
|
+
if (entry.isDirectory()) {
|
|
279
|
+
if (!SKIP_DIRECTORIES.has(entry.name)) {
|
|
280
|
+
await walk(full, visit, state);
|
|
281
|
+
}
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (!entry.isFile()) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
state.files += 1;
|
|
288
|
+
await visit(full);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function isScannable(name) {
|
|
292
|
+
if (name === ".env" || name.startsWith(".env.") || name.endsWith(".rules")) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
if (name === "package-lock.json" || name === "yarn.lock" || name === "pnpm-lock.yaml" || name === "bun.lock") {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return TEXT_EXTENSIONS.has(path.extname(name));
|
|
299
|
+
}
|
|
300
|
+
function stripComments(source) {
|
|
301
|
+
return source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1");
|
|
302
|
+
}
|
|
303
|
+
function nullableString(value) {
|
|
304
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
305
|
+
}
|
|
306
|
+
async function exists(file) {
|
|
307
|
+
try {
|
|
308
|
+
await stat(file);
|
|
309
|
+
return true;
|
|
310
|
+
} catch {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// packages/cli/src/format.ts
|
|
316
|
+
function formatPlan(plan) {
|
|
317
|
+
const lines = [
|
|
318
|
+
"VibeInfra plan",
|
|
319
|
+
`App: ${plan.frameworkLabel}${plan.supported ? "" : " (unsupported)"}`,
|
|
320
|
+
`Path: ${plan.path}`,
|
|
321
|
+
`Package manager: ${plan.packageManager ?? "unresolved"}`,
|
|
322
|
+
`Build: ${plan.buildCommand ?? "unresolved"}`,
|
|
323
|
+
`Output: ${plan.outputDirectory ?? "unresolved"}`,
|
|
324
|
+
`Project: ${plan.projectId ?? "not selected"} (${plan.projectAction})`,
|
|
325
|
+
`Services: ${plan.services.join(", ")}`,
|
|
326
|
+
`Billing: ${plan.billing.summary}`,
|
|
327
|
+
"This plan does not attach a billing account."
|
|
328
|
+
];
|
|
329
|
+
if (plan.identity) {
|
|
330
|
+
lines.push(`Account: ${plan.identity.account ?? "unknown"} via ${plan.identity.source}`);
|
|
331
|
+
}
|
|
332
|
+
if (plan.parent) {
|
|
333
|
+
lines.push(`Parent: ${plan.parent}`);
|
|
334
|
+
}
|
|
335
|
+
lines.push("", "Permissions:");
|
|
336
|
+
for (const permission of plan.requiredPermissions) {
|
|
337
|
+
lines.push(` - ${permission}`);
|
|
338
|
+
}
|
|
339
|
+
lines.push("", "APIs:");
|
|
340
|
+
for (const api of plan.requiredApis) {
|
|
341
|
+
lines.push(` - ${api}`);
|
|
342
|
+
}
|
|
343
|
+
lines.push("", "File changes:");
|
|
344
|
+
for (const change of plan.fileChanges) {
|
|
345
|
+
lines.push(` - ${change.action} ${change.path}: ${change.description}`);
|
|
346
|
+
}
|
|
347
|
+
if (plan.blockers.length > 0) {
|
|
348
|
+
lines.push("", "Blockers:");
|
|
349
|
+
for (const blocker of plan.blockers) {
|
|
350
|
+
lines.push(` - ${blocker.message}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (plan.warnings.length > 0) {
|
|
354
|
+
lines.push("", "Warnings:");
|
|
355
|
+
for (const warning of plan.warnings) {
|
|
356
|
+
lines.push(` - ${warning}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
lines.push("", "Steps:");
|
|
360
|
+
for (const step of plan.steps) {
|
|
361
|
+
lines.push(` - ${step.title}`);
|
|
362
|
+
}
|
|
363
|
+
return lines.join("\n");
|
|
364
|
+
}
|
|
365
|
+
function formatResult(result) {
|
|
366
|
+
const showPlan = result.status === "dry-run" || result.steps.every((step) => step.status === "pending" || step.status === "skipped");
|
|
367
|
+
const lines = [
|
|
368
|
+
...showPlan ? [formatPlan(result.plan), ""] : [],
|
|
369
|
+
`Status: ${result.status}`
|
|
370
|
+
];
|
|
371
|
+
if (result.verifiedUrl) {
|
|
372
|
+
lines.push(`URL: ${result.verifiedUrl}`);
|
|
373
|
+
}
|
|
374
|
+
lines.push("", "Steps:");
|
|
375
|
+
for (const step of result.steps) {
|
|
376
|
+
lines.push(` - ${step.status} ${step.title}${step.detail ? `: ${step.detail}` : ""}`);
|
|
377
|
+
}
|
|
378
|
+
if (result.warnings.length > 0) {
|
|
379
|
+
lines.push("", "Warnings:");
|
|
380
|
+
for (const warning of unique(result.warnings)) {
|
|
381
|
+
lines.push(` - ${warning}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (result.remediation.length > 0) {
|
|
385
|
+
lines.push("", "Next:");
|
|
386
|
+
for (const item of result.remediation) {
|
|
387
|
+
lines.push(` - ${item}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return lines.join("\n");
|
|
391
|
+
}
|
|
392
|
+
function formatAnalysis(analysis) {
|
|
393
|
+
const lines = [
|
|
394
|
+
"VibeInfra analyze",
|
|
395
|
+
`Path: ${analysis.path}`,
|
|
396
|
+
`Package: ${analysis.packageName ?? "not named"}`,
|
|
397
|
+
`Framework: ${analysis.frameworkLabel}${analysis.supported ? " (supported)" : " (unsupported)"}`
|
|
398
|
+
];
|
|
399
|
+
if (analysis.unsupportedReason) {
|
|
400
|
+
lines.push(`Reason: ${analysis.unsupportedReason}`);
|
|
401
|
+
}
|
|
402
|
+
lines.push(
|
|
403
|
+
`Package manager: ${analysis.packageManagers.join(", ") || "unresolved"}`,
|
|
404
|
+
`Build script: ${analysis.buildScript ?? "missing"}`,
|
|
405
|
+
`Scripts: ${analysis.scripts.length > 0 ? analysis.scripts.join(", ") : "none"}`,
|
|
406
|
+
"",
|
|
407
|
+
"Dependencies:",
|
|
408
|
+
...dependencyLines(analysis.dependencies),
|
|
409
|
+
"",
|
|
410
|
+
"Dev dependencies:",
|
|
411
|
+
...dependencyLines(analysis.devDependencies),
|
|
412
|
+
"",
|
|
413
|
+
"Firebase:",
|
|
414
|
+
` firebase.json: ${firebaseJsonStatus(analysis)}`,
|
|
415
|
+
` Hosting: ${hostingStatus(analysis)}`,
|
|
416
|
+
` .firebaserc: ${firebasercStatus(analysis)}`,
|
|
417
|
+
` Firebase imports: ${analysis.firebaseImports.length > 0 ? analysis.firebaseImports.join(", ") : "none"}`,
|
|
418
|
+
` Env references: ${analysis.envReferences.length > 0 ? analysis.envReferences.join(", ") : "none"}`,
|
|
419
|
+
` Functions directory: ${analysis.hasFunctionsDirectory ? "present" : "not found"}`
|
|
420
|
+
);
|
|
421
|
+
if (analysis.rules.length === 0) {
|
|
422
|
+
lines.push(" Rules files: none");
|
|
423
|
+
} else {
|
|
424
|
+
for (const rule of analysis.rules) {
|
|
425
|
+
lines.push(` Rules ${rule.path}: ${rule.permissive ? "permissive" : "not flagged as permissive"}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (analysis.secretFindings.length > 0) {
|
|
429
|
+
lines.push(` Secret patterns: ${analysis.secretFindings.map((finding) => `${finding.id} in ${finding.path}`).join(", ")}`);
|
|
430
|
+
}
|
|
431
|
+
if (analysis.warnings.length > 0) {
|
|
432
|
+
lines.push("", "Warnings:");
|
|
433
|
+
for (const warning of analysis.warnings) {
|
|
434
|
+
lines.push(` - ${warning}`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return redact(lines.join("\n"));
|
|
438
|
+
}
|
|
439
|
+
function dependencyLines(dependencies) {
|
|
440
|
+
const names = Object.keys(dependencies).sort();
|
|
441
|
+
if (names.length === 0) {
|
|
442
|
+
return [" none"];
|
|
443
|
+
}
|
|
444
|
+
return names.map((name) => ` ${name}@${dependencies[name]}`);
|
|
445
|
+
}
|
|
446
|
+
function firebaseJsonStatus(analysis) {
|
|
447
|
+
if (analysis.firebaseJsonError) {
|
|
448
|
+
return `could not be parsed (${analysis.firebaseJsonError})`;
|
|
449
|
+
}
|
|
450
|
+
if (!analysis.firebaseJson) {
|
|
451
|
+
return "not found";
|
|
452
|
+
}
|
|
453
|
+
const keys = Object.keys(analysis.firebaseJson);
|
|
454
|
+
return keys.length > 0 ? `present (${keys.join(", ")})` : "present";
|
|
455
|
+
}
|
|
456
|
+
function hostingStatus(analysis) {
|
|
457
|
+
if (analysis.hostingKind === "missing") {
|
|
458
|
+
return "not configured";
|
|
459
|
+
}
|
|
460
|
+
if (analysis.hostingKind === "invalid") {
|
|
461
|
+
return "invalid";
|
|
462
|
+
}
|
|
463
|
+
if (analysis.hostingKind === "array") {
|
|
464
|
+
return `multiple sites${analysis.hostingSites.length > 0 ? ` (${analysis.hostingSites.join(", ")})` : ""}`;
|
|
465
|
+
}
|
|
466
|
+
const details = [
|
|
467
|
+
analysis.hostingKind === "framework-source" ? "framework source" : "static site",
|
|
468
|
+
analysis.hostingPublic ? `public ${analysis.hostingPublic}` : null,
|
|
469
|
+
analysis.hostingSite ? `site ${analysis.hostingSite}` : null
|
|
470
|
+
].filter((item) => item !== null);
|
|
471
|
+
return details.join(", ");
|
|
472
|
+
}
|
|
473
|
+
function firebasercStatus(analysis) {
|
|
474
|
+
if (analysis.firebasercError) {
|
|
475
|
+
return `could not be parsed (${analysis.firebasercError})`;
|
|
476
|
+
}
|
|
477
|
+
const projects = analysis.firebaserc?.projects;
|
|
478
|
+
if (!projects || Object.keys(projects).length === 0) {
|
|
479
|
+
return analysis.firebaserc ? "present, no project aliases" : "not found";
|
|
480
|
+
}
|
|
481
|
+
return Object.entries(projects).map(([alias, projectId]) => `${alias}=${projectId}`).join(", ");
|
|
482
|
+
}
|
|
483
|
+
function formatProjects(projects, identity) {
|
|
484
|
+
const lines = [
|
|
485
|
+
`Signed in as ${identity.account ?? "an account ADC did not identify"} (${identity.source}).`,
|
|
486
|
+
projects.length === 0 ? "No Firebase projects were returned for this account." : "Firebase projects:"
|
|
487
|
+
];
|
|
488
|
+
for (const project of projects.slice(0, 20)) {
|
|
489
|
+
lines.push(` - ${project.projectId}${project.displayName ? ` (${project.displayName})` : ""}`);
|
|
490
|
+
}
|
|
491
|
+
if (projects.length > 20) {
|
|
492
|
+
lines.push(` - ${projects.length - 20} more. Pass --project with the exact id.`);
|
|
493
|
+
}
|
|
494
|
+
return lines.join("\n");
|
|
495
|
+
}
|
|
496
|
+
function formatDoctor(report) {
|
|
497
|
+
const lines = [
|
|
498
|
+
"VibeInfra doctor",
|
|
499
|
+
`App: ${report.frameworkLabel}${report.supported ? " (supported)" : " (unsupported)"}`,
|
|
500
|
+
report.unsupportedReason ? `Reason: ${report.unsupportedReason}` : "",
|
|
501
|
+
`Package manager: ${report.packageManagers.join(", ") || "unresolved"}`,
|
|
502
|
+
`Build script: ${report.buildScript ?? "missing"}`,
|
|
503
|
+
`Output: ${report.outputDirectory ?? "unresolved"}`,
|
|
504
|
+
`Credentials: ${report.credentials}`,
|
|
505
|
+
"Management API calls use Application Default Credentials. `firebase login` is separate and is not read by VibeInfra.",
|
|
506
|
+
"Firebase CLI deploy uses its own precedence: FIREBASE_TOKEN, Firebase CLI login, GOOGLE_APPLICATION_CREDENTIALS, then ADC."
|
|
507
|
+
];
|
|
508
|
+
if (report.project) {
|
|
509
|
+
lines.push(`Project lookup: ${report.project}`);
|
|
510
|
+
}
|
|
511
|
+
if (report.webApps) {
|
|
512
|
+
lines.push(`Web apps: ${report.webApps}`);
|
|
513
|
+
}
|
|
514
|
+
if (report.warnings.length > 0) {
|
|
515
|
+
lines.push("", "Warnings:");
|
|
516
|
+
for (const warning of report.warnings) {
|
|
517
|
+
lines.push(` - ${warning}`);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return lines.filter((line) => line !== "").join("\n");
|
|
521
|
+
}
|
|
522
|
+
function unique(values) {
|
|
523
|
+
return [...new Set(values)];
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// packages/cli/src/options.ts
|
|
527
|
+
var PACKAGE_MANAGERS = /* @__PURE__ */ new Set(["npm", "pnpm", "yarn", "bun"]);
|
|
528
|
+
function toDeployOptions(projectPath, flags) {
|
|
529
|
+
if (flags.project && flags.createProject) {
|
|
530
|
+
throw new VibeInfraError({
|
|
531
|
+
code: "conflicting_project_flags",
|
|
532
|
+
message: "Pass either --project or --create-project, not both.",
|
|
533
|
+
remediation: "--project selects an existing Google Cloud or Firebase project. --create-project creates a project when it does not already exist."
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
let packageManager;
|
|
537
|
+
if (flags.packageManager) {
|
|
538
|
+
if (!PACKAGE_MANAGERS.has(flags.packageManager)) {
|
|
539
|
+
throw new VibeInfraError({
|
|
540
|
+
code: "invalid_package_manager",
|
|
541
|
+
message: `Unsupported package manager "${flags.packageManager}".`,
|
|
542
|
+
remediation: "Use npm, pnpm, yarn, or bun."
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
packageManager = flags.packageManager;
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
path: projectPath,
|
|
549
|
+
...flags.createProject ? { projectId: flags.createProject, createProject: true } : {},
|
|
550
|
+
...flags.project ? { projectId: flags.project, createProject: false } : {},
|
|
551
|
+
...flags.parent ? { parent: flags.parent } : {},
|
|
552
|
+
...packageManager ? { packageManager } : {},
|
|
553
|
+
...flags.buildScript ? { buildScript: flags.buildScript } : {},
|
|
554
|
+
...flags.output ? { outputDirectory: flags.output } : {},
|
|
555
|
+
...flags.app ? { appId: flags.app } : {},
|
|
556
|
+
...flags.displayName ? { displayName: flags.displayName } : {},
|
|
557
|
+
...flags.yes ? { yes: true } : {},
|
|
558
|
+
...flags.dryRun ? { dryRun: true } : {},
|
|
559
|
+
...flags.nonInteractive ? { nonInteractive: true } : {},
|
|
560
|
+
...flags.resume ? { resume: true } : {},
|
|
561
|
+
...flags.json ? { json: true } : {}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
function applyProjectAnswer(options, answer) {
|
|
565
|
+
const trimmed = answer.trim();
|
|
566
|
+
if (trimmed.toLowerCase().startsWith("new:")) {
|
|
567
|
+
const projectId = trimmed.slice(4).trim();
|
|
568
|
+
assertProjectId(projectId);
|
|
569
|
+
return { ...options, projectId, createProject: true };
|
|
570
|
+
}
|
|
571
|
+
assertProjectId(trimmed);
|
|
572
|
+
return { ...options, projectId: trimmed, createProject: false };
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// packages/cli/src/report.ts
|
|
576
|
+
async function createDoctorReport(input) {
|
|
577
|
+
const context = await loadPlanContext(input.analysis.path);
|
|
578
|
+
const plan = createDeploymentPlan(input.analysis, { path: input.analysis.path, ...input.projectId ? { projectId: input.projectId } : {} }, context);
|
|
579
|
+
const warnings = [...plan.warnings];
|
|
580
|
+
let credentials = "unavailable";
|
|
581
|
+
let identityError = null;
|
|
582
|
+
try {
|
|
583
|
+
const identity = await input.provider.authenticate();
|
|
584
|
+
credentials = `${identity.account ?? "unidentified account"} via ${identity.source} (${identity.credentialKind})`;
|
|
585
|
+
if (identity.credentialKind === "service-account") {
|
|
586
|
+
warnings.push("A service account is active. Prefer `gcloud auth application-default login` for local use.");
|
|
587
|
+
}
|
|
588
|
+
} catch (error) {
|
|
589
|
+
const vibe = toVibeInfraError(error);
|
|
590
|
+
identityError = vibe.message;
|
|
591
|
+
credentials = `${vibe.message} ${vibe.remediation}`;
|
|
592
|
+
}
|
|
593
|
+
let project;
|
|
594
|
+
let webApps;
|
|
595
|
+
if (input.projectId && !identityError) {
|
|
596
|
+
try {
|
|
597
|
+
const firebase = await input.provider.getFirebaseProject(input.projectId);
|
|
598
|
+
if (firebase) {
|
|
599
|
+
project = `Firebase project ${firebase.projectId} (${firebase.state ?? "unknown state"})`;
|
|
600
|
+
const apps = await input.provider.listWebApps(input.projectId);
|
|
601
|
+
webApps = apps.length === 0 ? "none" : apps.map((app) => `${app.appId}${app.displayName ? ` ${app.displayName}` : ""}`).join(", ");
|
|
602
|
+
} else {
|
|
603
|
+
const cloud = await input.provider.getCloudProject(input.projectId);
|
|
604
|
+
project = cloud ? `Google Cloud project ${cloud.projectId} does not have Firebase yet.` : `Project ${input.projectId} was not found.`;
|
|
605
|
+
}
|
|
606
|
+
} catch (error) {
|
|
607
|
+
const vibe = toVibeInfraError(error);
|
|
608
|
+
project = `${vibe.message} ${vibe.remediation}`;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const projectMissing = project?.includes("was not found") ?? false;
|
|
612
|
+
return {
|
|
613
|
+
supported: input.analysis.supported,
|
|
614
|
+
frameworkLabel: input.analysis.frameworkLabel,
|
|
615
|
+
...input.analysis.unsupportedReason ? { unsupportedReason: input.analysis.unsupportedReason } : {},
|
|
616
|
+
packageManagers: input.analysis.packageManagers,
|
|
617
|
+
buildScript: input.analysis.buildScript,
|
|
618
|
+
outputDirectory: plan.outputDirectory,
|
|
619
|
+
credentials,
|
|
620
|
+
...project ? { project } : {},
|
|
621
|
+
...webApps ? { webApps } : {},
|
|
622
|
+
warnings,
|
|
623
|
+
ok: input.analysis.supported && !identityError && !projectMissing && plan.blockers.length === 0
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// packages/cli/src/version.ts
|
|
628
|
+
import { readFileSync } from "node:fs";
|
|
629
|
+
import path2 from "node:path";
|
|
630
|
+
import { fileURLToPath } from "node:url";
|
|
631
|
+
function cliVersion() {
|
|
632
|
+
let directory = path2.dirname(fileURLToPath(import.meta.url));
|
|
633
|
+
for (let depth = 0; depth < 6; depth += 1) {
|
|
634
|
+
try {
|
|
635
|
+
const manifest = JSON.parse(readFileSync(path2.join(directory, "package.json"), "utf8"));
|
|
636
|
+
if (manifest.name === "vibeinfra" && typeof manifest.version === "string" && manifest.version.length > 0) {
|
|
637
|
+
return manifest.version;
|
|
638
|
+
}
|
|
639
|
+
} catch {
|
|
640
|
+
}
|
|
641
|
+
const parent = path2.dirname(directory);
|
|
642
|
+
if (parent === directory) {
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
directory = parent;
|
|
646
|
+
}
|
|
647
|
+
return "0.0.1";
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// packages/cli/src/program.ts
|
|
651
|
+
function createDefaultDependencies(io2) {
|
|
652
|
+
return {
|
|
653
|
+
io: io2,
|
|
654
|
+
provider: lazyFirebaseProvider(),
|
|
655
|
+
engine: { analyzer: { analyze: analyzeProject } }
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function lazyFirebaseProvider() {
|
|
659
|
+
let provider;
|
|
660
|
+
const load = async () => {
|
|
661
|
+
provider ??= import("./chunks/src-AV3FZUMU.js").then((module) => module.createFirebaseProvider());
|
|
662
|
+
return provider;
|
|
663
|
+
};
|
|
664
|
+
return {
|
|
665
|
+
authenticate: async () => (await load()).authenticate(),
|
|
666
|
+
listFirebaseProjects: async () => (await load()).listFirebaseProjects(),
|
|
667
|
+
listAvailableCloudProjects: async () => (await load()).listAvailableCloudProjects(),
|
|
668
|
+
getFirebaseProject: async (projectId) => (await load()).getFirebaseProject(projectId),
|
|
669
|
+
getCloudProject: async (projectId) => (await load()).getCloudProject(projectId),
|
|
670
|
+
createCloudProject: async (input) => (await load()).createCloudProject(input),
|
|
671
|
+
addFirebase: async (projectId) => (await load()).addFirebase(projectId),
|
|
672
|
+
enableServices: async (projectId, serviceIds) => (await load()).enableServices(projectId, serviceIds),
|
|
673
|
+
listWebApps: async (projectId) => (await load()).listWebApps(projectId),
|
|
674
|
+
getWebApp: async (projectId, appId) => (await load()).getWebApp(projectId, appId),
|
|
675
|
+
createWebApp: async (projectId, displayName) => (await load()).createWebApp(projectId, displayName),
|
|
676
|
+
getWebAppConfig: async (projectId, appId) => (await load()).getWebAppConfig(projectId, appId),
|
|
677
|
+
deployHosting: async (input) => (await load()).deployHosting(input)
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
async function run(argv, dependencies) {
|
|
681
|
+
const state = { code: 0 };
|
|
682
|
+
const program = new Command();
|
|
683
|
+
program.name("vibeinfra").description("Inspect a React + Vite app and deploy it to a Firebase project you own.").version(cliVersion()).configureOutput({
|
|
684
|
+
writeOut: (text) => dependencies.io.stdout(text.replace(/\s+$/u, "")),
|
|
685
|
+
writeErr: (text) => dependencies.io.stderr(text.replace(/\s+$/u, ""))
|
|
686
|
+
}).exitOverride();
|
|
687
|
+
program.command("analyze").argument("[path]", "application directory", ".").option("--json", "print machine-readable JSON").description("Inspect the application directory, dependencies, and Firebase configuration.").action(async (projectPath, options) => {
|
|
688
|
+
state.code = await guard(dependencies, Boolean(options.json), async () => {
|
|
689
|
+
const analysis = await dependencies.engine.analyzer.analyze(projectPath);
|
|
690
|
+
emit(dependencies.io, Boolean(options.json), analysis, formatAnalysis(analysis));
|
|
691
|
+
return 0;
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
const withSharedFlags = (command) => command.option("--project <id>", "existing Firebase or Google Cloud project id").option("--create-project <id>", "create this project when it does not exist, then add Firebase").option("--parent <resource>", "organizations/ID or folders/ID for project creation").option("--package-manager <name>", "npm, pnpm, yarn, or bun").option("--build-script <name>", "package.json script to run").option("--output <dir>", "build output directory").option("--app <appId>", "Firebase web app id to reuse").option("--display-name <name>", "display name used when creating a project").option("--json", "print machine-readable JSON");
|
|
695
|
+
withSharedFlags(program.command("plan").argument("[path]", "application directory", ".")).action(async (projectPath, options) => {
|
|
696
|
+
state.code = await guard(dependencies, Boolean(options.json), async () => {
|
|
697
|
+
const deployOptions = toDeployOptions(projectPath, options);
|
|
698
|
+
const analysis = await dependencies.engine.analyzer.analyze(deployOptions.path);
|
|
699
|
+
const plan = createDeploymentPlan(analysis, deployOptions, await loadPlanContext(analysis.path));
|
|
700
|
+
emit(dependencies.io, Boolean(options.json), plan, formatPlan(plan));
|
|
701
|
+
return plan.appReady ? 0 : 1;
|
|
702
|
+
});
|
|
703
|
+
});
|
|
704
|
+
withSharedFlags(program.command("deploy").argument("[path]", "application directory", ".")).option("--yes", "approve the reconciled plan without a prompt").option("--dry-run", "print the local plan without contacting Google or writing files").option("--non-interactive", "fail instead of prompting").option("--resume", "continue using the journaled project in this directory").action(async (projectPath, options) => {
|
|
705
|
+
state.code = await guard(dependencies, Boolean(options.json), async () => {
|
|
706
|
+
let deployOptions = await resumeOptions(toDeployOptions(projectPath, options));
|
|
707
|
+
if (!deployOptions.dryRun && !deployOptions.projectId) {
|
|
708
|
+
deployOptions = await selectProject(deployOptions, dependencies);
|
|
709
|
+
}
|
|
710
|
+
const result = await deployApplication(deployOptions, {
|
|
711
|
+
analyzer: dependencies.engine.analyzer,
|
|
712
|
+
provider: dependencies.provider,
|
|
713
|
+
confirm: (plan) => confirmPlan(plan, deployOptions, dependencies.io),
|
|
714
|
+
...dependencies.engine.runCommand ? { runCommand: dependencies.engine.runCommand } : {},
|
|
715
|
+
...dependencies.engine.fetch ? { fetch: dependencies.engine.fetch } : {},
|
|
716
|
+
...dependencies.engine.sleep ? { sleep: dependencies.engine.sleep } : {},
|
|
717
|
+
...dependencies.engine.now ? { now: dependencies.engine.now } : {},
|
|
718
|
+
...dependencies.engine.id ? { id: dependencies.engine.id } : {}
|
|
719
|
+
});
|
|
720
|
+
emit(dependencies.io, Boolean(options.json), result, formatResult(result));
|
|
721
|
+
return exitCodeFor(result);
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
program.command("doctor").argument("[path]", "application directory", ".").option("--project <id>", "read-only project lookup").option("--json", "print machine-readable JSON").action(async (projectPath, options) => {
|
|
725
|
+
state.code = await guard(dependencies, Boolean(options.json), async () => {
|
|
726
|
+
const analysis = await dependencies.engine.analyzer.analyze(projectPath);
|
|
727
|
+
const report = await createDoctorReport({
|
|
728
|
+
analysis,
|
|
729
|
+
provider: dependencies.provider,
|
|
730
|
+
...options.project ? { projectId: options.project } : {}
|
|
731
|
+
});
|
|
732
|
+
emit(dependencies.io, Boolean(options.json), report, formatDoctor(report));
|
|
733
|
+
return report.ok ? 0 : 1;
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
program.command("status").argument("[path]", "application directory", ".").option("--json", "print machine-readable JSON").action(async (projectPath, options) => {
|
|
737
|
+
state.code = await guard(dependencies, Boolean(options.json), async () => {
|
|
738
|
+
const journal = await readJournal(projectPath);
|
|
739
|
+
if (!journal) {
|
|
740
|
+
const payload = {
|
|
741
|
+
found: false,
|
|
742
|
+
message: "No deployment journal exists. VibeInfra has no local record of a deployment in this directory."
|
|
743
|
+
};
|
|
744
|
+
emit(dependencies.io, Boolean(options.json), payload, payload.message);
|
|
745
|
+
return 1;
|
|
746
|
+
}
|
|
747
|
+
const text = [
|
|
748
|
+
`Status: ${journal.status}`,
|
|
749
|
+
`Project: ${journal.projectId ?? "unknown"}`,
|
|
750
|
+
`URL: ${journal.verifiedUrl ?? "not verified"}`,
|
|
751
|
+
`Updated: ${journal.updatedAt}`
|
|
752
|
+
].join("\n");
|
|
753
|
+
emit(dependencies.io, Boolean(options.json), journal, text);
|
|
754
|
+
return journal.status === "succeeded" ? 0 : 1;
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
try {
|
|
758
|
+
await program.parseAsync(argv);
|
|
759
|
+
return state.code;
|
|
760
|
+
} catch (error) {
|
|
761
|
+
if (error instanceof CommanderError && (error.code === "commander.helpDisplayed" || error.code === "commander.version")) {
|
|
762
|
+
return 0;
|
|
763
|
+
}
|
|
764
|
+
if (error instanceof CommanderError) {
|
|
765
|
+
dependencies.io.stderr(error.message);
|
|
766
|
+
return error.exitCode;
|
|
767
|
+
}
|
|
768
|
+
return printFailure(dependencies.io, false, error);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
async function selectProject(options, dependencies) {
|
|
772
|
+
if (options.nonInteractive || !dependencies.io.isTTY) {
|
|
773
|
+
throw new VibeInfraError({
|
|
774
|
+
code: "project_required",
|
|
775
|
+
message: "A Firebase project id is required before VibeInfra can deploy.",
|
|
776
|
+
remediation: "Pass --project PROJECT_ID or --create-project PROJECT_ID. Noninteractive execution also requires --yes. VibeInfra will not choose or create a project implicitly."
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
const identity = await dependencies.provider.authenticate();
|
|
780
|
+
const projects = await dependencies.provider.listFirebaseProjects();
|
|
781
|
+
dependencies.io.stderr(formatProjects(projects, identity));
|
|
782
|
+
const answer = await dependencies.io.prompt("Enter a project id, or new:<project-id> to create one: ");
|
|
783
|
+
return applyProjectAnswer(options, answer);
|
|
784
|
+
}
|
|
785
|
+
async function confirmPlan(plan, options, io2) {
|
|
786
|
+
const rendered = formatPlan(plan);
|
|
787
|
+
if (options.json) {
|
|
788
|
+
io2.stderr(rendered);
|
|
789
|
+
} else {
|
|
790
|
+
io2.stdout(rendered);
|
|
791
|
+
}
|
|
792
|
+
if (options.yes) {
|
|
793
|
+
io2.stderr("Approved with --yes. No billing account will be attached.");
|
|
794
|
+
return true;
|
|
795
|
+
}
|
|
796
|
+
if (options.nonInteractive || !io2.isTTY) {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
const answer = await io2.prompt("Approve this plan and deploy? Type yes: ");
|
|
800
|
+
return answer.trim() === "yes";
|
|
801
|
+
}
|
|
802
|
+
async function guard(dependencies, json, action) {
|
|
803
|
+
try {
|
|
804
|
+
return await action();
|
|
805
|
+
} catch (error) {
|
|
806
|
+
return printFailure(dependencies.io, json, error);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
function printFailure(io2, json, error) {
|
|
810
|
+
const vibe = toVibeInfraError(error);
|
|
811
|
+
if (json) {
|
|
812
|
+
io2.stdout(JSON.stringify({ ok: false, error: vibe.toJSON() }, null, 2));
|
|
813
|
+
} else {
|
|
814
|
+
io2.stderr(`${vibe.message}
|
|
815
|
+
${vibe.remediation}`);
|
|
816
|
+
}
|
|
817
|
+
return vibe.category === "provider" ? 2 : 1;
|
|
818
|
+
}
|
|
819
|
+
function emit(io2, json, payload, text) {
|
|
820
|
+
io2.stdout(redact(json ? JSON.stringify(payload, null, 2) : text));
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// packages/cli/src/bin.ts
|
|
824
|
+
var io = {
|
|
825
|
+
stdout: (text) => process.stdout.write(`${text}
|
|
826
|
+
`),
|
|
827
|
+
stderr: (text) => process.stderr.write(`${text}
|
|
828
|
+
`),
|
|
829
|
+
isTTY: Boolean(process.stdin.isTTY),
|
|
830
|
+
prompt: (message) => {
|
|
831
|
+
const prompt = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
832
|
+
return new Promise((resolve) => {
|
|
833
|
+
prompt.question(message, (answer) => {
|
|
834
|
+
prompt.close();
|
|
835
|
+
resolve(answer);
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
var code = await run(process.argv, createDefaultDependencies(io));
|
|
841
|
+
process.exit(code);
|