Skip to content

Commit a781257

Browse files
committed
fix: setup-cli-symlinks working
1 parent 83bf039 commit a781257

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

cli/scripts/setup-cli-symlinks.ts

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/usr/bin/env bun
22

3-
import { existsSync, mkdirSync, symlinkSync, rmSync } from 'fs'
3+
import { existsSync, mkdirSync, symlinkSync, rmSync, readdirSync } from 'fs'
44
import { join } from 'path'
55
import { execSync } from 'child_process'
66

77
const ROOT_DIR = process.cwd()
88
const CLI_DIR = join(ROOT_DIR, 'cli')
99
const 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

1113
console.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')
1516
if (!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
2425
const coreDistPath = join(corePackagePath, 'dist')
2526
if (!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

3774
function createSymlink(target: string, linkPath: string) {
@@ -59,7 +96,7 @@ const opentuiReactNodeModules = join(
5996
mkdirSync(opentunCoreNodeModules, { recursive: true })
6097
mkdirSync(opentuiReactNodeModules, { recursive: true })
6198

62-
const corePackage = join(ROOT_NODE_MODULES, '@opentui/core/packages/core')
99+
const corePackage = corePackagePath
63100
const reactPackage = join(ROOT_NODE_MODULES, '@opentui/react/packages/react')
64101

65102
createSymlink(corePackage, join(opentunCoreNodeModules, 'core'))

0 commit comments

Comments
 (0)