Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"inquirer": "^10.2.2",
"nanoid": "^5.0.0",
"postgres": "^3.4.0",
"zod": "^3.23.8"
"zod": "^3.23.8",
"cli-table3": "^0.6.5",
"ora": "^8.0.0"
},
"devDependencies": {
"@types/bun": "^1.3.9",
Expand Down
29 changes: 23 additions & 6 deletions packages/cli/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync } from "fs";
import { join, relative } from "path";
import chalk from "chalk";
import { ContextGenerator } from "../utils/context-generator";
import { error, info, success, warn } from "../utils/logger";
import { blank, error, info, keyValue, sym, warn } from "../utils/logger";
import { ProcessManager } from "./dev/process-manager";
import { queryLog } from "./dev/query-log";
import { DevWatcher } from "./dev/watcher";
Expand All @@ -13,8 +13,15 @@ export async function runDevCommand(projectRoot: string) {
const hasBetterBase = existsSync(join(projectRoot, "betterbase"));
const hasIaC = hasBetterBase;

// Print banner
console.log(chalk.bold.cyan("\n BetterBase Dev\n"));
blank();
console.log(chalk.bold(" bb dev") + chalk.dim(" — watching for changes"));
blank();
keyValue("Project root", projectRoot);
keyValue("Server URL", "http://localhost:3000");
keyValue("Dashboard", "http://localhost:3000/admin");
blank();
console.log(chalk.dim(" Press Ctrl+C to stop"));
blank();
if (hasIaC) {
info("IaC layer detected — betterbase/ will be watched for schema and function changes.");
}
Expand Down Expand Up @@ -54,7 +61,9 @@ export async function runDevCommand(projectRoot: string) {

switch (event.kind) {
case "schema": {
info(`[iac] Schema changed: ${label}`);
console.log(
` ${chalk.dim(new Date().toLocaleTimeString("en-US", { hour12: false }))} ${chalk.yellow("~")} ${chalk.dim(label)} ${chalk.dim("→ regenerating context")}`,
);
const result = await runIacSync(projectRoot, { force: false, silent: false }).catch(
(e: Error) => {
warn(`[iac] ${e.message}`);
Expand Down Expand Up @@ -94,9 +103,17 @@ export async function runDevCommand(projectRoot: string) {
}

// Regenerate context on every change
ctxGen.generate(projectRoot).catch((e: Error) => {
const startedAt = Date.now();
ctxGen.generate(projectRoot)
.then(() => {
const elapsed = Date.now() - startedAt;
console.log(
` ${chalk.dim(new Date().toLocaleTimeString("en-US", { hour12: false }))} ${chalk.green(sym.success)} context updated ${chalk.dim(`(${elapsed}ms)`)}`,
);
})
.catch((e: Error) => {
warn(`Context regeneration failed: ${e.message}`);
});
});
});

watcher.start(projectRoot);
Expand Down
41 changes: 28 additions & 13 deletions packages/cli/src/commands/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
getVercelLogs,
syncEnvToCloudflare,
} from "@betterbase/core/functions";
import chalk from "chalk";
import * as logger from "../utils/logger";
import { createSpinner, withSpinner } from "../utils/spinner";

// Store running function processes for cleanup
const runningFunctions: Map<string, ChildProcess> = new Map();
Expand Down Expand Up @@ -380,9 +382,18 @@ async function runFunctionDeploy(
return;
}

// First, build the function
console.log(`Building function "${name}" before deployment...`);
const buildResult = await bundleFunction(name, projectRoot);
const config = await readFunctionConfig(name, projectRoot);
const runtime = config?.runtime ?? "cloudflare-workers";
logger.section(`Deploying ${chalk.cyan(name)}`);
logger.keyValue("Target", runtime);
logger.keyValue("Function", name);
logger.blank();

const buildResult = await withSpinner(
"Bundling function...",
async () => await bundleFunction(name, projectRoot),
{ successText: `Bundled ${chalk.dim(`dist/${name}.js`)}` },
);

if (!buildResult.success) {
logger.error("Build failed:");
Expand All @@ -391,16 +402,11 @@ async function runFunctionDeploy(
}
return;
}

console.log(`Build successful (${(buildResult.size / 1024).toFixed(2)} KB)\n`);

// Get function config
const config = await readFunctionConfig(name, projectRoot);
const runtime = config?.runtime ?? "cloudflare-workers";

console.log(`Deploying to ${runtime}...`);
logger.info(`Bundle size: ${(buildResult.size / 1024).toFixed(2)} KB`);

let deployResult: DeployResult | undefined;
const spinner = createSpinner("Deploying to edge...").start();
spinner.text = `Deploying to ${runtime}...`;

if (runtime === "cloudflare-workers") {
deployResult = await deployToCloudflare(
Expand All @@ -419,15 +425,24 @@ async function runFunctionDeploy(
}

if (!deployResult.success) {
spinner.stop();
logger.error("Deployment failed:");
for (const log of deployResult.logs) {
console.log(` ${log}`);
}
return;
}
spinner.stopAndPersist({
symbol: chalk.green(logger.sym.success),
text: `Deployed ${chalk.cyan(name)}`,
});

console.log("\nDeployment successful!");
console.log(` URL: ${deployResult.url}`);
logger.blank();
logger.box("Deployment complete", [
{ label: "Function", value: name },
{ label: "Target", value: runtime },
{ label: "URL", value: deployResult.url ?? "pending" },
]);

// Handle env sync
if (syncEnv && config && config.env.length > 0) {
Expand Down
Loading
Loading