-
Notifications
You must be signed in to change notification settings - Fork 30
feat(build): add base44 build — site buildCommand with the app id injected #586
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,32 @@ | ||
| import type { Command } from "commander"; | ||
| import { runSiteBuild } from "@/cli/commands/project/site-build.js"; | ||
| import type { CLIContext, RunCommandResult } from "@/cli/types.js"; | ||
| import { Base44Command, theme } from "@/cli/utils/index.js"; | ||
| import { ConfigInvalidError } from "@/core/errors.js"; | ||
| import { readProjectConfig } from "@/core/project/index.js"; | ||
|
|
||
| async function buildAction(ctx: CLIContext): Promise<RunCommandResult> { | ||
| const { app } = ctx; | ||
| if (!app?.projectRoot) { | ||
| throw new ConfigInvalidError( | ||
| "base44 build requires a linked local project. Run it from a project with base44/.app.jsonc.", | ||
| ); | ||
| } | ||
|
|
||
| const { project } = await readProjectConfig(app.projectRoot); | ||
| await runSiteBuild(ctx, { | ||
| root: project.root, | ||
| buildCommand: project.site?.buildCommand, | ||
| appId: app.id, | ||
| }); | ||
|
|
||
| return { | ||
| outroMessage: `Site built with app id ${theme.styles.bold(app.id)}`, | ||
| }; | ||
| } | ||
|
|
||
| export function getBuildCommand(): Command { | ||
| return new Base44Command("build") | ||
| .description("Build the site with the Base44 app id injected") | ||
| .action(buildAction); | ||
| } |
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,39 @@ | ||
| import { execa } from "execa"; | ||
| import type { CLIContext } from "@/cli/types.js"; | ||
| import { ConfigNotFoundError } from "@/core/errors.js"; | ||
|
|
||
| interface SiteBuildTarget { | ||
| root: string; | ||
| buildCommand?: string; | ||
| appId: string; | ||
| } | ||
|
|
||
| export async function runSiteBuild( | ||
| { runTask }: Pick<CLIContext, "runTask">, | ||
| { root, buildCommand, appId }: SiteBuildTarget, | ||
| ): Promise<void> { | ||
| if (!buildCommand) { | ||
| throw new ConfigNotFoundError("No site build command found.", { | ||
| hints: [ | ||
| { | ||
| message: | ||
| 'Add \'site.buildCommand\' to your config.jsonc (e.g., "site": { "buildCommand": "npm run build" })', | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| await runTask( | ||
| "Building site...", | ||
| () => | ||
| execa({ | ||
| cwd: root, | ||
| shell: true, | ||
| env: { VITE_BASE44_APP_ID: appId }, | ||
| })`${buildCommand}`, | ||
| { | ||
| successMessage: "Site built successfully", | ||
| errorMessage: "Build failed", | ||
| }, | ||
| ); | ||
| } | ||
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
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,43 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { fixture, setupCLITests } from "./testkit/index.js"; | ||
|
|
||
| describe("build command", () => { | ||
| const t = setupCLITests(); | ||
|
|
||
| it("runs the site buildCommand with the app id injected", async () => { | ||
| await t.givenLoggedInWithProject(fixture("with-buildable-site")); | ||
|
|
||
| const result = await t.run("build"); | ||
|
|
||
| t.expectResult(result).toSucceed(); | ||
| expect(await t.readProjectFile("build-env.txt")).toBe( | ||
| `BUILD_APP=${t.api.appId}`, | ||
| ); | ||
| }); | ||
|
|
||
| it("fails when the project has no site.buildCommand", async () => { | ||
| await t.givenLoggedInWithProject(fixture("with-site")); | ||
|
|
||
| const result = await t.run("build"); | ||
|
|
||
| t.expectResult(result).toFail(); | ||
| t.expectResult(result).toContain("No site build command found"); | ||
| }); | ||
|
|
||
| it("fails when the buildCommand fails", async () => { | ||
| await t.givenLoggedInWithProject(fixture("with-failing-build")); | ||
|
|
||
| const result = await t.run("build"); | ||
|
|
||
| t.expectResult(result).toFail(); | ||
| t.expectResult(result).toContain("Build failed"); | ||
| }); | ||
|
|
||
| it("fails when not in a project directory", async () => { | ||
| await t.givenLoggedIn({ email: "test@example.com", name: "Test User" }); | ||
|
|
||
| const result = await t.run("build"); | ||
|
|
||
| t.expectResult(result).toFail(); | ||
| }); | ||
| }); |
6 changes: 6 additions & 0 deletions
6
packages/cli/tests/fixtures/with-buildable-site/base44/config.jsonc
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,6 @@ | ||
| { | ||
| "name": "Buildable Site Project", | ||
| "site": { | ||
| "buildCommand": "node -e \"require('fs').writeFileSync('build-env.txt', 'BUILD_APP=' + process.env.VITE_BASE44_APP_ID)\"" | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
packages/cli/tests/fixtures/with-failing-build/base44/config.jsonc
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,6 @@ | ||
| { | ||
| "name": "Failing Build Project", | ||
| "site": { | ||
| "buildCommand": "node -e \"process.exit(1)\"" | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case of editor app => github clone => base44 build, what is the source of the app id? the user should use the --app-id flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The id comes from
base44 link, not a flag. An editor-app clone shipsbase44/config.jsoncbut deliberately no.app.jsonc(the platform git-ignores it), so the firstbase44 buildfails pointing atbase44 link; link lists editor-created apps since #577 and writes.app.jsonc, and build resolves the id from there like every project command.--app-id/BASE44_APP_IDintentionally don't work here: they carry an id without a project root, andbuildrequires a linked project — injecting app X's id into app Y's checkout is exactly the mistake that guard blocks. If we ever want--app-idto override in unlinked checkouts, that's a product decision to take deliberately, not a gap.