-
-
Notifications
You must be signed in to change notification settings - Fork 128
feat(cli): offer Capgo Builder on incompatible upload #2368
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
15 commits
Select commit
Hold shift + click to select a range
ee494a0
docs: Builder CTA on incompatible upload — spec + implementation plan
WcaleNieWolny ebeff32
feat(cli): add per-app Builder prompt snooze state
WcaleNieWolny eba5256
feat(cli): add Builder CTA decision + prompt orchestrator (injectable…
WcaleNieWolny 9a2e35f
feat(cli): offer Capgo Builder on incompatible upload
WcaleNieWolny 7bd5465
fix(cli): don't pass upload webDir as Builder build project path
WcaleNieWolny ef5b5a7
fix(cli): address review — harden Builder CTA, extract upload handler
WcaleNieWolny 0a87288
docs: fix spec — snooze path typo, credential detection, fenced-block…
WcaleNieWolny 5ff914c
feat(cli): simplify Builder CTA to a single question
WcaleNieWolny c2f09c7
docs: remove builder-cta implementation plan (superseded)
WcaleNieWolny b97e7be
feat(cli): reword Builder CTA prompt + add clickable Learn link
WcaleNieWolny 12aad49
refactor(cli): split Builder CTA into a context message + short prompt
WcaleNieWolny 80bfc09
refactor: consolidate Builder CI ad to one line, inject hasCredentials
WcaleNieWolny e64b260
docs: align Decisions section with two-message prompt flow
WcaleNieWolny 8f1b98a
refactor: drop CAPGO_NO_BUILDER_PROMPT opt-out (YAGNI)
WcaleNieWolny 93eb529
Merge origin/main into feat/builder-cta-on-incompatible-upload
WcaleNieWolny 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 |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { confirm as pConfirm, isCancel as pIsCancel, log } from '@clack/prompts' | ||
| import { trackEvent } from '../analytics/track' | ||
|
|
||
| export type BuilderCtaSurface = 'skip' | 'ci-ad' | 'prompt-onboarding' | 'prompt-build' | ||
| export type BuilderCtaAction = 'continue' | 'launch-onboarding' | 'launch-build' | ||
|
|
||
| export interface BuilderCtaContext { | ||
| incompatible: boolean | ||
| interactive: boolean | ||
| hasCredentials: boolean | ||
| } | ||
|
|
||
| /** | ||
| * Pure decision: which Builder CTA surface (if any) to show for this upload. | ||
| * - `skip`: do nothing (compatible bundle). | ||
| * - `ci-ad`: non-interactive — print a one-off ad, never prompt. | ||
| * - `prompt-onboarding` / `prompt-build`: interactive prompt, branched on | ||
| * whether the app already has build credentials. | ||
| */ | ||
| export function decideBuilderCtaSurface(ctx: BuilderCtaContext): BuilderCtaSurface { | ||
| if (!ctx.incompatible) | ||
| return 'skip' | ||
| if (!ctx.interactive) | ||
| return 'ci-ad' | ||
| return ctx.hasCredentials ? 'prompt-build' : 'prompt-onboarding' | ||
| } | ||
|
|
||
| const DOCS_URL = 'https://capgo.app/docs/cli/cloud-build/' | ||
| const LEARN_URL = 'https://capgo.app/native-build/' | ||
|
|
||
| // Why a native build is needed — folded into the prompt and the CI ad. | ||
| const REASON = 'This update includes native changes. An app store update may be required for these changes to take effect. Capgo Builder can help you build and publish the required native update.' | ||
|
|
||
| /** | ||
| * Render a clickable terminal hyperlink (OSC 8). Clicking it opens the URL in the | ||
| * browser **without dismissing the active prompt**. Terminals that don't support | ||
| * OSC 8 just render `text`. | ||
| */ | ||
| function terminalLink(text: string, url: string): string { | ||
| const ESC = String.fromCharCode(27) // \x1B | ||
| const BEL = String.fromCharCode(7) // \x07 | ||
| return `${ESC}]8;;${url}${BEL}${text}${ESC}]8;;${BEL}` | ||
| } | ||
|
|
||
| export function printBuilderCiAd(hasCredentials: boolean): void { | ||
| const action = hasCredentials | ||
| ? 'run a native build (npx @capgo/cli build request --platform <ios|android>)' | ||
| : 'set up Capgo Builder (npx @capgo/cli build onboarding)' | ||
| log.warn(`${REASON} To ${action} — learn more: ${LEARN_URL} · docs: ${DOCS_URL}`) | ||
| } | ||
|
|
||
| /** Confirm-prompt seam (`@clack/prompts` `confirm` satisfies it); injectable for tests. */ | ||
| export type BuilderConfirm = (opts: { message: string, initialValue?: boolean }) => Promise<boolean | symbol> | ||
|
|
||
| export interface MaybePromptBuilderCtaParams { | ||
| incompatible: boolean | ||
| interactive: boolean | ||
| /** Whether the app already has saved build credentials (resolved by the caller). */ | ||
| hasCredentials: boolean | ||
| appId: string | ||
| orgId: string | ||
| apikey: string | ||
| incompatibleCount: number | ||
| /** Injectable for tests; defaults to the `@clack/prompts` confirm prompt. */ | ||
| confirm?: BuilderConfirm | ||
| } | ||
|
|
||
| /** | ||
| * Surface the Capgo Builder CTA for an incompatible upload and return the action | ||
| * the caller should take. Never throws; telemetry and prompt failures degrade to | ||
| * `continue` so the upload is never blocked by the CTA. | ||
| */ | ||
| export async function maybePromptBuilderCta(params: MaybePromptBuilderCtaParams): Promise<BuilderCtaAction> { | ||
| try { | ||
| return await runBuilderCta(params) | ||
| } | ||
| catch { | ||
| // A CTA failure (prompt, telemetry) must never block the upload. | ||
| return 'continue' | ||
| } | ||
| } | ||
|
|
||
| async function runBuilderCta(params: MaybePromptBuilderCtaParams): Promise<BuilderCtaAction> { | ||
| const { hasCredentials } = params | ||
|
|
||
| const surface = decideBuilderCtaSurface({ | ||
| incompatible: params.incompatible, | ||
| interactive: params.interactive, | ||
| hasCredentials, | ||
| }) | ||
| if (surface === 'skip') | ||
| return 'continue' | ||
|
|
||
| const mode: 'build' | 'onboarding' = hasCredentials ? 'build' : 'onboarding' | ||
| void trackEvent({ | ||
| channel: 'bundle', | ||
| event: 'Builder CTA Shown', | ||
| icon: '📣', | ||
| apikey: params.apikey, | ||
| appId: params.appId, | ||
| orgId: params.orgId, | ||
| tags: { surface: surface === 'ci-ad' ? 'ci' : 'interactive', mode, incompatible_count: params.incompatibleCount }, | ||
| }) | ||
|
|
||
| if (surface === 'ci-ad') { | ||
| printBuilderCiAd(hasCredentials) | ||
| return 'continue' | ||
| } | ||
|
|
||
| // Message 1: the context, printed above the prompt so the question stays short. | ||
| log.info(REASON) | ||
|
|
||
| // Message 2: the short yes/no question, plus a clickable "learn more" hyperlink | ||
| // that opens in the browser without dismissing this prompt. | ||
| const confirm = params.confirm ?? pConfirm | ||
| const question = mode === 'build' | ||
| ? 'Start a native build with Capgo Builder now?' | ||
| : 'Would you like to configure Capgo Builder now?' | ||
| const accepted = await confirm({ | ||
| message: `${question}\n${terminalLink('Learn what Capgo Builder is', LEARN_URL)}`, | ||
| initialValue: true, | ||
| }) | ||
| if (pIsCancel(accepted)) | ||
| return 'continue' | ||
|
|
||
| if (accepted === true) { | ||
| void trackEvent({ channel: 'bundle', event: 'Builder CTA Accepted', icon: '✅', apikey: params.apikey, appId: params.appId, orgId: params.orgId, tags: { mode } }) | ||
| return mode === 'build' ? 'launch-build' : 'launch-onboarding' | ||
| } | ||
|
|
||
| // Declined → just continue the OTA upload (no follow-up prompt). | ||
| void trackEvent({ channel: 'bundle', event: 'Builder CTA Declined', icon: '🚫', apikey: params.apikey, appId: params.appId, orgId: params.orgId, tags: { mode } }) | ||
| return 'continue' | ||
| } | ||
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,23 @@ | ||
| import type { OptionsUpload } from './upload_interface' | ||
| import { onboardingBuilderCommand } from '../build/onboarding/command' | ||
| import { requestBuildCommand } from '../build/request' | ||
| import { uploadBundle } from './upload' | ||
|
|
||
| /** | ||
| * `bundle upload` command handler. Uploads the bundle, then — when the bundle is | ||
| * incompatible and the user opted into Capgo Builder — launches the Ink-based | ||
| * build flow. Kept out of `upload.ts` so the programmatic SDK bundle (which | ||
| * imports `uploadBundleInternal`) never statically pulls in `ink`. | ||
| */ | ||
| export async function handleBundleUploadCommand(appId: string, options: OptionsUpload): Promise<void> { | ||
| const result = await uploadBundle(appId, options) | ||
| if (!result?.builderAction) | ||
| return | ||
|
|
||
| if (result.builderAction === 'launch-onboarding') | ||
| await onboardingBuilderCommand({ apikey: options.apikey }) | ||
| else | ||
| // Don't forward options.path — for `bundle upload` it's the web asset dir, | ||
| // but `build request` treats `path` as the Capacitor project root. | ||
| await requestBuildCommand(appId ?? '', { apikey: options.apikey, supaHost: options.supaHost, supaAnon: options.supaAnon }) | ||
| } |
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
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.