11#!/usr/bin/env node
22
3- const { Binary } = require ( "binary-install" ) ;
3+ const { spawn } = require ( "child_process" ) ;
4+ const fs = require ( "fs" ) ;
45const os = require ( "os" ) ;
56const path = require ( "path" ) ;
67
@@ -17,17 +18,6 @@ function getPlatform() {
1718 return mappings [ platform ] || platform ;
1819}
1920
20- function getArch ( ) {
21- const arch = os . arch ( ) ;
22- const mappings = {
23- x64 : "amd64" ,
24- ia32 : "386" ,
25- arm : "arm" ,
26- arm64 : "arm64" ,
27- } ;
28- return mappings [ arch ] || arch ;
29- }
30-
3121function getBinaryPath ( ) {
3222 const platform = getPlatform ( ) ;
3323 let extension = "" ;
@@ -36,20 +26,82 @@ function getBinaryPath() {
3626 extension = ".exe" ;
3727 }
3828
39- return path . join (
40- __dirname ,
41- ".." ,
42- "node_modules" ,
43- ".bin" ,
44- `tuido${ extension } ` ,
45- ) ;
29+ // binary-install stores binaries in: node_modules/<package>/binary/<name>
30+ return path . join ( __dirname , ".." , "binary" , `tuido${ extension } ` ) ;
31+ }
32+
33+ function findBinaryPath ( ) {
34+ // Try the standard binary-install location first
35+ let binaryPath = getBinaryPath ( ) ;
36+
37+ if ( fs . existsSync ( binaryPath ) ) {
38+ return binaryPath ;
39+ }
40+
41+ // Fallback: check if binary-install used a different location
42+ const alternativePaths = [
43+ path . join ( __dirname , ".." , "node_modules" , ".bin" , "tuido" ) ,
44+ path . join ( __dirname , ".." , "tuido" ) ,
45+ path . join ( __dirname , ".." , "bin" , "tuido" ) ,
46+ ] ;
47+
48+ for ( const altPath of alternativePaths ) {
49+ const platform = getPlatform ( ) ;
50+ const withExt = platform === "windows" ? `${ altPath } .exe` : altPath ;
51+ if ( fs . existsSync ( withExt ) ) {
52+ return withExt ;
53+ }
54+ if ( fs . existsSync ( altPath ) ) {
55+ return altPath ;
56+ }
57+ }
58+
59+ return null ;
4660}
4761
4862try {
49- const binaryPath = getBinaryPath ( ) ;
50- const binary = new Binary ( "tuido" , null , { installDirectory : path . dirname ( binaryPath ) } ) ;
51- binary . run ( process . argv . slice ( 2 ) ) ;
63+ const binaryPath = findBinaryPath ( ) ;
64+
65+ if ( ! binaryPath ) {
66+ console . error ( "Error: tuido binary not found. Please try reinstalling the package." ) ;
67+ console . error ( "Expected location:" , getBinaryPath ( ) ) ;
68+ process . exit ( 1 ) ;
69+ }
70+
71+ // Check if binary is executable
72+ try {
73+ fs . accessSync ( binaryPath , fs . constants . F_OK | fs . constants . X_OK ) ;
74+ } catch ( err ) {
75+ console . error ( `Error: tuido binary found but not executable: ${ binaryPath } ` ) ;
76+ console . error ( "Try reinstalling the package or check file permissions." ) ;
77+ process . exit ( 1 ) ;
78+ }
79+
80+ // Execute the binary
81+ const child = spawn ( binaryPath , process . argv . slice ( 2 ) , {
82+ stdio : "inherit" ,
83+ windowsHide : false ,
84+ } ) ;
85+
86+ child . on ( "error" , ( err ) => {
87+ console . error ( "Error executing tuido:" , err . message ) ;
88+ process . exit ( 1 ) ;
89+ } ) ;
90+
91+ child . on ( "close" , ( code ) => {
92+ process . exit ( code || 0 ) ;
93+ } ) ;
94+
95+ // Handle signals
96+ process . on ( "SIGINT" , ( ) => {
97+ child . kill ( "SIGINT" ) ;
98+ } ) ;
99+
100+ process . on ( "SIGTERM" , ( ) => {
101+ child . kill ( "SIGTERM" ) ;
102+ } ) ;
103+
52104} catch ( e ) {
53- console . error ( "Error running tuido:" , e ) ;
105+ console . error ( "Error running tuido:" , e . message ) ;
54106 process . exit ( 1 ) ;
55- }
107+ }
0 commit comments