-
Notifications
You must be signed in to change notification settings - Fork 8
feat(functions): rewrite deploy to per-function API with zero-config #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yardend-wix
merged 9 commits into
feature/functions-commands
from
feature/functions-deploy-command
Mar 12, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
77758f0
feat(functions): add `functions list` command
yardend-wix 5c77e60
fix: lint formatting and remove unused FunctionInfo type
yardend-wix 83f723c
feat(functions): rewrite deploy to per-function API with zero-config …
yardend-wix 76bedc3
Merge branch 'main' into feature/functions-list-command
kfirstri 0777843
fix: camelCase transforms, runTask spinner, rename auto→automation vars
yardend-wix 5406f17
merge: resolve merge conflict with main (TestAPIServer migration)
yardend-wix 73a2461
merge: resolve merge conflict with base branch (TestAPIServer migration)
yardend-wix fe03e42
resolved comments
yardend-wix 2828644
merge: resolve conflicts with feature/functions-commands branch
yardend-wix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,129 @@ | ||
| import { log } from "@clack/prompts"; | ||
| import { Command } from "commander"; | ||
| import { formatDeployResult } from "@/cli/commands/functions/formatDeployResult.js"; | ||
| import { parseNames } from "@/cli/commands/functions/parseNames.js"; | ||
| import type { CLIContext } from "@/cli/types.js"; | ||
| import { runCommand, runTask } from "@/cli/utils/index.js"; | ||
| import { runCommand } from "@/cli/utils/index.js"; | ||
| import type { RunCommandResult } from "@/cli/utils/runCommand.js"; | ||
| import { ApiError } from "@/core/errors.js"; | ||
| import { theme } from "@/cli/utils/theme.js"; | ||
| import { InvalidInputError } from "@/core/errors.js"; | ||
| import { readProjectConfig } from "@/core/index.js"; | ||
| import { pushFunctions } from "@/core/resources/function/index.js"; | ||
| import { | ||
| deployFunctionsSequentially, | ||
| type PruneResult, | ||
| pruneRemovedFunctions, | ||
| type SingleFunctionDeployResult, | ||
| } from "@/core/resources/function/deploy.js"; | ||
| import type { BackendFunction } from "@/core/resources/function/schema.js"; | ||
|
|
||
| function resolveFunctionsToDeploy( | ||
| names: string[], | ||
| allFunctions: BackendFunction[], | ||
| ): BackendFunction[] { | ||
| if (names.length === 0) return allFunctions; | ||
|
|
||
| const notFound = names.filter((n) => !allFunctions.some((f) => f.name === n)); | ||
| if (notFound.length > 0) { | ||
| throw new InvalidInputError( | ||
| `Function${notFound.length > 1 ? "s" : ""} not found in project: ${notFound.join(", ")}`, | ||
| ); | ||
| } | ||
| return allFunctions.filter((f) => names.includes(f.name)); | ||
| } | ||
|
|
||
| function formatPruneResults(pruneResults: PruneResult[]): void { | ||
| for (const pruneResult of pruneResults) { | ||
| if (pruneResult.deleted) { | ||
| log.success(`${pruneResult.name.padEnd(25)} deleted`); | ||
| } else { | ||
| log.error(`${pruneResult.name.padEnd(25)} error: ${pruneResult.error}`); | ||
| } | ||
| } | ||
|
|
||
| if (pruneResults.length > 0) { | ||
| const pruned = pruneResults.filter((r) => r.deleted).length; | ||
| log.info(`${pruned} function${pruned !== 1 ? "s" : ""} removed`); | ||
| } | ||
| } | ||
|
|
||
| function buildDeploySummary(results: SingleFunctionDeployResult[]): string { | ||
| const deployed = results.filter((r) => r.status === "deployed").length; | ||
| const unchanged = results.filter((r) => r.status === "unchanged").length; | ||
| const failed = results.filter((r) => r.status === "error").length; | ||
|
|
||
| const parts: string[] = []; | ||
| if (deployed > 0) parts.push(`${deployed} deployed`); | ||
| if (unchanged > 0) parts.push(`${unchanged} unchanged`); | ||
| if (failed > 0) parts.push(`${failed} error${failed !== 1 ? "s" : ""}`); | ||
| return parts.join(", ") || "No functions deployed"; | ||
| } | ||
|
|
||
| async function deployFunctionsAction( | ||
| names: string[], | ||
| options: { force?: boolean }, | ||
| ): Promise<RunCommandResult> { | ||
| if (options.force && names.length > 0) { | ||
| throw new InvalidInputError( | ||
| "--force cannot be used when specifying function names", | ||
| ); | ||
| } | ||
|
|
||
| async function deployFunctionsAction(): Promise<RunCommandResult> { | ||
| const { functions } = await readProjectConfig(); | ||
| const toDeploy = resolveFunctionsToDeploy(names, functions); | ||
|
|
||
| if (functions.length === 0) { | ||
| if (toDeploy.length === 0) { | ||
| return { | ||
| outroMessage: | ||
| "No functions found. Create functions in the 'functions' directory.", | ||
| }; | ||
| } | ||
|
|
||
| log.info( | ||
| `Found ${functions.length} ${functions.length === 1 ? "function" : "functions"} to deploy`, | ||
| `Found ${toDeploy.length} ${toDeploy.length === 1 ? "function" : "functions"} to deploy`, | ||
| ); | ||
|
|
||
| const result = await runTask( | ||
| "Deploying functions to Base44", | ||
| async () => { | ||
| return await pushFunctions(functions); | ||
| let completed = 0; | ||
| const total = toDeploy.length; | ||
|
|
||
| const results = await deployFunctionsSequentially(toDeploy, { | ||
| onStart: (startNames) => { | ||
| const label = | ||
| startNames.length === 1 | ||
| ? startNames[0] | ||
| : `${startNames.length} functions`; | ||
| log.step( | ||
| theme.styles.dim(`[${completed + 1}/${total}] Deploying ${label}...`), | ||
| ); | ||
| }, | ||
| { | ||
| successMessage: "Functions deployed successfully", | ||
| errorMessage: "Failed to deploy functions", | ||
| onResult: (result) => { | ||
| completed++; | ||
| formatDeployResult(result); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| if (result.deployed.length > 0) { | ||
| log.success(`Deployed: ${result.deployed.join(", ")}`); | ||
| } | ||
| if (result.deleted.length > 0) { | ||
| log.warn(`Deleted: ${result.deleted.join(", ")}`); | ||
| } | ||
| if (result.errors && result.errors.length > 0) { | ||
| throw new ApiError("Function deployment errors", { | ||
| details: result.errors.map((e) => `'${e.name}': ${e.message}`), | ||
| hints: [ | ||
| { message: "Check the function code for syntax errors" }, | ||
| { message: "Ensure all imports are valid" }, | ||
| ], | ||
| }); | ||
| if (options.force) { | ||
| log.info("Removing remote functions not found locally..."); | ||
| const allLocalNames = functions.map((f) => f.name); | ||
| const pruneResults = await pruneRemovedFunctions(allLocalNames); | ||
| formatPruneResults(pruneResults); | ||
| } | ||
|
|
||
| return { outroMessage: "Functions deployed to Base44" }; | ||
| return { outroMessage: buildDeploySummary(results) }; | ||
| } | ||
|
|
||
| export function getDeployCommand(context: CLIContext): Command { | ||
| return new Command("deploy") | ||
| .description("Deploy local functions to Base44") | ||
| .action(async () => { | ||
| await runCommand(deployFunctionsAction, { requireAuth: true }, context); | ||
| .description("Deploy functions to Base44") | ||
| .argument("[names...]", "Function names to deploy (deploys all if omitted)") | ||
| .option("--force", "Delete remote functions not found locally") | ||
| .action(async (rawNames: string[], options: { force?: boolean }) => { | ||
| await runCommand( | ||
| () => { | ||
| const names = parseNames(rawNames); | ||
| return deployFunctionsAction(names, options); | ||
| }, | ||
| { requireAuth: true }, | ||
| context, | ||
| ); | ||
| }); | ||
| } |
21 changes: 21 additions & 0 deletions
21
packages/cli/src/cli/commands/functions/formatDeployResult.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { log } from "@clack/prompts"; | ||
| import { theme } from "@/cli/utils/theme.js"; | ||
| import type { SingleFunctionDeployResult } from "@/core/resources/function/deploy.js"; | ||
|
|
||
| function formatDuration(ms: number): string { | ||
| return `${(ms / 1000).toFixed(1)}s`; | ||
| } | ||
|
|
||
| export function formatDeployResult(result: SingleFunctionDeployResult): void { | ||
| const label = result.name.padEnd(25); | ||
| if (result.status === "deployed") { | ||
| const timing = result.durationMs | ||
| ? theme.styles.dim(` (${formatDuration(result.durationMs)})`) | ||
| : ""; | ||
| log.success(`${label} deployed${timing}`); | ||
| } else if (result.status === "unchanged") { | ||
| log.success(`${label} unchanged`); | ||
| } else { | ||
| log.error(`${label} error: ${result.error}`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * Parse names from variadic CLI args, supporting comma-separated values. | ||
| * e.g. ["fn-a", "fn-b,fn-c"] → ["fn-a", "fn-b", "fn-c"] | ||
| */ | ||
| export function parseNames(args: string[]): string[] { | ||
yardend-wix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return args | ||
| .flatMap((arg) => arg.split(",")) | ||
| .map((n) => n.trim()) | ||
| .filter(Boolean); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.