ReviewOS

also looking at this

craft-native/craft

feat: finish native customization and platform seams

#401
Merged glennmichael123 wants to merge codex/issues-388-400-344 into main
21 files +707 -17
packages/ios/src/index.tsmodified+62-0
Changes to packages/ios/src/index.ts
@@ -68,6 +68,21 @@ const CRAFT_VERSION = resolveCraftVersion()
6868
6969export type CraftAppearance = 'light' | 'dark' | 'system'
7070
71/** A declared command Craft runs after the native project has been generated. */
72export interface CraftPostGenerateHook {
73 command: string
74 args?: string[]
75}
76
77export interface CraftTabBarConfig {
78 selection?: {
79 /** The selected tab indicator's corner radius in points; omitted keeps a capsule. */
80 cornerRadius?: number
81 /** The selected tab indicator fill as #RRGGBB. */
82 color?: string
83 }
84}
85
7186export interface CraftConfig {
7287 appShortcuts?: CraftAppShortcut[]
7388 /** Bundled font files keyed by their PostScript font name, used as native fontFamily. */
@@ -86,6 +101,10 @@ export interface CraftConfig {
86101 * and `dark` pin one. Unset keeps the older `darkMode` switch.
87102 */
88103 appearance?: CraftAppearance
104 /** Static native tab-bar styling applied before the page's own tabBar.set call. */
105 tabBar?: CraftTabBarConfig
106 /** Runs from the generated project root after `craft ios build` writes it. */
107 postGenerate?: CraftPostGenerateHook
89108 backgroundColor?: string
90109 /** The launch and webview background while the phone is in Dark Mode. */
91110 backgroundColorDark?: string
@@ -639,6 +658,42 @@ export interface BuildOptions {
639658 runtimeDir?: string | null
640659}
641660
661/**
662 * Run the app's declared generator hook without invoking a shell.
663 *
664 * A hook gets the generated project as its cwd and explicit metadata so a
665 * patch can target the right platform and phase without guessing from paths.
666 */
667export function runPostGenerateHook(
668 hook: CraftPostGenerateHook | undefined,
669 output: string,
670 phase: 'build' = 'build',
671): void {
672 if (!hook) return
673 if (typeof hook.command !== 'string' || !hook.command.trim())
674 throw new Error('iOS postGenerate.command must be a non-empty executable')
675 if (hook.args !== undefined && (!Array.isArray(hook.args) || hook.args.some(argument => typeof argument !== 'string')))
676 throw new Error('iOS postGenerate.args must be an array of strings')
677
678 const command = [hook.command, ...(hook.args ?? [])]
679 let result: ReturnType<typeof Bun.spawnSync>
680 try {
681 result = Bun.spawnSync(command, {
682 cwd: output,
683 env: { ...process.env, CRAFT_PROJECT_ROOT: output, CRAFT_PLATFORM: 'ios', CRAFT_GENERATE_PHASE: phase },
684 stdout: 'inherit',
685 stderr: 'pipe',
686 })
687 }
688 catch (error) {
689 throw new Error(`iOS postGenerate hook could not start in ${output}: ${hook.command}`, { cause: error })
690 }
691 if (result.exitCode !== 0) {
692 const stderr = result.stderr?.toString().trim()
693 throw new Error(`iOS postGenerate hook failed in ${output} with exit code ${result.exitCode}${stderr ? `: ${stderr}` : ''}`)
694 }
695}
696
642697export interface OpenOptions {
643698 output: string
644699}
@@ -1502,6 +1557,11 @@ export async function init(options: InitOptions): Promise<void> {
15021557 if (config.renderer !== 'web' && config.renderer !== 'native') {
15031558 throw new Error(`Unknown iOS renderer: ${config.renderer}. Expected web or native.`)
15041559 }
1560 const selection = config.tabBar?.selection
1561 if (selection?.cornerRadius !== undefined && (!Number.isFinite(selection.cornerRadius) || selection.cornerRadius < 0))
1562 throw new Error('iOS tabBar.selection.cornerRadius must be a finite non-negative number')
1563 if (selection?.color !== undefined && !/^#[0-9a-f]{6}$/i.test(selection.color))
1564 throw new Error('iOS tabBar.selection.color must be a #RRGGBB color')
15051565 if (config.enableBackgroundLocation) config.enableGeolocation = true
15061566 const problems = hybridConfigProblems(config)
15071567 if (problems.length) throw new Error(problems.join('\n'))
@@ -1755,6 +1815,8 @@ catch (error) {
17551815 })
17561816 }
17571817
1818 runPostGenerateHook(config.postGenerate, output)
1819
17581820 console.log('')
17591821}
17601822