11#!/usr/bin/env bun
22
3- import { existsSync , mkdirSync , symlinkSync , rmSync } from 'fs'
3+ import { existsSync , mkdirSync , symlinkSync , rmSync , readdirSync } from 'fs'
44import { join } from 'path'
55import { execSync } from 'child_process'
66
77const ROOT_DIR = process . cwd ( )
88const CLI_DIR = join ( ROOT_DIR , 'cli' )
99const ROOT_NODE_MODULES = join ( ROOT_DIR , 'node_modules' )
10+ const coreWorkspacePath = join ( ROOT_NODE_MODULES , '@opentui/core' )
11+ const corePackagePath = join ( coreWorkspacePath , 'packages/core' )
1012
1113console . log ( 'Setting up OpenTUI symlinks for CLI workspace...' )
1214
1315// Check if source packages exist (they're in packages/ subdirectories)
14- const corePackagePath = join ( ROOT_NODE_MODULES , '@opentui/core/packages/core' )
1516if ( ! existsSync ( corePackagePath ) ) {
1617 console . error ( '⚠️ Warning: OpenTUI packages not found in root node_modules' )
1718 console . error (
@@ -23,15 +24,51 @@ if (!existsSync(corePackagePath)) {
2324// Build OpenTUI packages if not already built
2425const coreDistPath = join ( corePackagePath , 'dist' )
2526if ( ! existsSync ( coreDistPath ) ) {
27+ const corePackageNodeModules = join ( corePackagePath , 'node_modules' )
28+ if ( ! existsSync ( corePackageNodeModules ) ) {
29+ console . log ( 'Installing OpenTUI dependencies needed for CLI build...' )
30+ try {
31+ execSync ( 'bun install' , {
32+ cwd : coreWorkspacePath ,
33+ stdio : 'inherit' ,
34+ } )
35+ } catch ( error ) {
36+ console . error ( 'Failed to install OpenTUI dependencies. CLI symlink setup cannot continue.' )
37+ throw error
38+ }
39+ }
40+
2641 console . log ( 'Building OpenTUI packages (this may take a moment)...' )
2742 try {
28- execSync ( 'bun run build' , {
29- cwd : join ( ROOT_NODE_MODULES , '@opentui/core' ) ,
30- stdio : 'ignore' ,
43+ execSync ( 'bun run build:native' , {
44+ cwd : corePackagePath ,
45+ stdio : 'inherit' ,
46+ } )
47+ execSync ( 'bun run build:lib' , {
48+ cwd : corePackagePath ,
49+ stdio : 'inherit' ,
3150 } )
3251 } catch ( error ) {
3352 console . warn ( 'Build failed, but continuing anyway...' )
3453 }
54+
55+ const nativePackagesRoot = join ( corePackagePath , 'node_modules/@opentui' )
56+ if ( existsSync ( nativePackagesRoot ) ) {
57+ const rootOpentuiDir = join ( ROOT_NODE_MODULES , '@opentui' )
58+ mkdirSync ( rootOpentuiDir , { recursive : true } )
59+
60+ for ( const entry of readdirSync ( nativePackagesRoot , { withFileTypes : true } ) ) {
61+ if ( ! entry . isDirectory ( ) ) {
62+ continue
63+ }
64+
65+ const nativePackageSource = join ( nativePackagesRoot , entry . name )
66+ const nativePackageLink = join ( rootOpentuiDir , entry . name )
67+ createSymlink ( nativePackageSource , nativePackageLink )
68+ }
69+ } else {
70+ console . warn ( 'Native OpenTUI packages not found after build. CLI runtime may fail to load native bindings.' )
71+ }
3572}
3673
3774function createSymlink ( target : string , linkPath : string ) {
@@ -59,7 +96,7 @@ const opentuiReactNodeModules = join(
5996mkdirSync ( opentunCoreNodeModules , { recursive : true } )
6097mkdirSync ( opentuiReactNodeModules , { recursive : true } )
6198
62- const corePackage = join ( ROOT_NODE_MODULES , '@opentui/core/packages/core' )
99+ const corePackage = corePackagePath
63100const reactPackage = join ( ROOT_NODE_MODULES , '@opentui/react/packages/react' )
64101
65102createSymlink ( corePackage , join ( opentunCoreNodeModules , 'core' ) )
0 commit comments