@fnet/cli 1.0.17 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as l1}from"node:module";var f1=Object.create;var{getPrototypeOf:b1,defineProperty:X1,getOwnPropertyNames:g1}=Object;var h1=Object.prototype.hasOwnProperty;var o1=($,Y,q)=>{q=$!=null?f1(b1($)):{};let G=Y||!$||!$.__esModule?X1(q,"default",{value:$,enumerable:!0}):q;for(let Z of g1($))if(!h1.call(G,Z))X1(G,Z,{get:()=>$[Z],enumerable:!0});return G};var Z1=l1(import.meta.url);import u1 from"chalk";import r$ from"yargs";import{hideBin as i$}from"yargs/helpers";import w1 from"node:path";import e1 from"node:fs";import T1 from"node:os";import O from"chalk";import v from"@fnet/prompt";import I from"node:fs";import E from"node:path";import y from"node:os";import D from"chalk";function G1(){return E.join(y.homedir(),".fnet","bin")}function e(){return E.join(y.homedir(),".fnet","metadata")}function _1(){return E.join(e(),"binaries.json")}function n1($){return(process.env.PATH||"").split(E.delimiter).includes($)}function K1(){try{if(process.platform==="win32"){if(process.env.PSModulePath&&process.env.PSModulePath.includes("PowerShell"))return"powershell-core";if(process.env.PSModulePath)return"powershell";return"cmd"}let $=process.env.SHELL||"";if($.includes("bash"))return"bash";if($.includes("zsh"))return"zsh";if($.includes("fish"))return"fish";if($.includes("ksh"))return"ksh";if($.includes("csh")||$.includes("tcsh"))return"csh";if(I.existsSync(E.join(y.homedir(),".bashrc")))return"bash";if(I.existsSync(E.join(y.homedir(),".zshrc")))return"zsh";if(I.existsSync(E.join(y.homedir(),".config","fish","config.fish")))return"fish";return"unknown"}catch($){return"unknown"}}function H1($){let Y=y.homedir(),q=[];switch($){case"bash":q.push({name:".bashrc",path:E.join(Y,".bashrc")}),q.push({name:".bash_profile",path:E.join(Y,".bash_profile")}),q.push({name:".profile",path:E.join(Y,".profile")});break;case"zsh":q.push({name:".zshrc",path:E.join(Y,".zshrc")}),q.push({name:".zprofile",path:E.join(Y,".zprofile")});break;case"fish":q.push({name:"config.fish",path:E.join(Y,".config","fish","config.fish")});break;case"ksh":q.push({name:".kshrc",path:E.join(Y,".kshrc")}),q.push({name:".profile",path:E.join(Y,".profile")});break;case"csh":q.push({name:".cshrc",path:E.join(Y,".cshrc")}),q.push({name:".tcshrc",path:E.join(Y,".tcshrc")});break;case"powershell":q.push({name:"Microsoft.PowerShell_profile.ps1",path:E.join(Y,"Documents","WindowsPowerShell","Microsoft.PowerShell_profile.ps1")}),q.push({name:"profile.ps1",path:E.join(Y,"Documents","WindowsPowerShell","profile.ps1")});break;case"powershell-core":q.push({name:"Microsoft.PowerShell_profile.ps1",path:E.join(Y,"Documents","PowerShell","Microsoft.PowerShell_profile.ps1")}),q.push({name:"profile.ps1",path:E.join(Y,"Documents","PowerShell","profile.ps1")});break;case"cmd":q.push({name:"fnet-path.bat",path:E.join(Y,"fnet-path.bat")});break;default:break}return q}function c1(){let $=K1(),Y=H1($);for(let q of Y)if(I.existsSync(q.path))return q.path;return Y.length>0?Y[0].path:null}async function s1(){let $=G1(),Y=e(),q=_1();if(!I.existsSync($))I.mkdirSync($,{recursive:!0});if(!I.existsSync(Y))I.mkdirSync(Y,{recursive:!0});if(!I.existsSync(q))I.writeFileSync(q,JSON.stringify({binaries:{},lastUpdated:new Date().toISOString()},null,2))}function W1($,Y){switch($){case"bash":case"zsh":case"ksh":return`export PATH="${Y}:$PATH"`;case"fish":return`set -gx PATH ${Y} $PATH`;case"csh":return`setenv PATH ${Y}:$PATH`;case"powershell":case"powershell-core":return`$env:PATH = "${Y};" + $env:PATH`;case"cmd":return`@echo off
2
+ import{createRequire as p1}from"node:module";var X1=p1(import.meta.url);import m1 from"chalk";import h$ from"yargs";import{hideBin as o$}from"yargs/helpers";import z1 from"node:path";import n1 from"node:fs";import w1 from"node:os";import O from"chalk";import v from"@fnet/prompt";import I from"node:fs";import E from"node:path";import y from"node:os";import D from"chalk";function Z1(){return E.join(y.homedir(),".fnet","bin")}function e(){return E.join(y.homedir(),".fnet","metadata")}function G1(){return E.join(e(),"binaries.json")}function f1($){return(process.env.PATH||"").split(E.delimiter).includes($)}function _1(){try{if(process.platform==="win32"){if(process.env.PSModulePath&&process.env.PSModulePath.includes("PowerShell"))return"powershell-core";if(process.env.PSModulePath)return"powershell";return"cmd"}let $=process.env.SHELL||"";if($.includes("bash"))return"bash";if($.includes("zsh"))return"zsh";if($.includes("fish"))return"fish";if($.includes("ksh"))return"ksh";if($.includes("csh")||$.includes("tcsh"))return"csh";if(I.existsSync(E.join(y.homedir(),".bashrc")))return"bash";if(I.existsSync(E.join(y.homedir(),".zshrc")))return"zsh";if(I.existsSync(E.join(y.homedir(),".config","fish","config.fish")))return"fish";return"unknown"}catch($){return"unknown"}}function K1($){let Y=y.homedir(),J=[];switch($){case"bash":J.push({name:".bashrc",path:E.join(Y,".bashrc")}),J.push({name:".bash_profile",path:E.join(Y,".bash_profile")}),J.push({name:".profile",path:E.join(Y,".profile")});break;case"zsh":J.push({name:".zshrc",path:E.join(Y,".zshrc")}),J.push({name:".zprofile",path:E.join(Y,".zprofile")});break;case"fish":J.push({name:"config.fish",path:E.join(Y,".config","fish","config.fish")});break;case"ksh":J.push({name:".kshrc",path:E.join(Y,".kshrc")}),J.push({name:".profile",path:E.join(Y,".profile")});break;case"csh":J.push({name:".cshrc",path:E.join(Y,".cshrc")}),J.push({name:".tcshrc",path:E.join(Y,".tcshrc")});break;case"powershell":J.push({name:"Microsoft.PowerShell_profile.ps1",path:E.join(Y,"Documents","WindowsPowerShell","Microsoft.PowerShell_profile.ps1")}),J.push({name:"profile.ps1",path:E.join(Y,"Documents","WindowsPowerShell","profile.ps1")});break;case"powershell-core":J.push({name:"Microsoft.PowerShell_profile.ps1",path:E.join(Y,"Documents","PowerShell","Microsoft.PowerShell_profile.ps1")}),J.push({name:"profile.ps1",path:E.join(Y,"Documents","PowerShell","profile.ps1")});break;case"cmd":J.push({name:"fnet-path.bat",path:E.join(Y,"fnet-path.bat")});break;default:break}return J}function b1(){let $=_1(),Y=K1($);for(let J of Y)if(I.existsSync(J.path))return J.path;return Y.length>0?Y[0].path:null}async function g1(){let $=Z1(),Y=e(),J=G1();if(!I.existsSync($))I.mkdirSync($,{recursive:!0});if(!I.existsSync(Y))I.mkdirSync(Y,{recursive:!0});if(!I.existsSync(J))I.writeFileSync(J,JSON.stringify({binaries:{},lastUpdated:new Date().toISOString()},null,2))}function H1($,Y){switch($){case"bash":case"zsh":case"ksh":return`export PATH="${Y}:$PATH"`;case"fish":return`set -gx PATH ${Y} $PATH`;case"csh":return`setenv PATH ${Y}:$PATH`;case"powershell":case"powershell-core":return`$env:PATH = "${Y};" + $env:PATH`;case"cmd":return`@echo off
3
3
  SETX PATH "%PATH%;${Y}"
4
- echo Path updated successfully`;default:return`export PATH="${Y}:$PATH"`}}async function r1($,Y,q,G={}){try{let{autoBackup:Z=!0}=G,Q=W1($,q);if($==="cmd")return I.writeFileSync(Y,Q),console.log(D.yellow(`Created batch file at ${Y}`)),console.log(D.yellow("Run this file to add the bin directory to your PATH")),!0;if(($==="powershell"||$==="powershell-core")&&!I.existsSync(E.dirname(Y)))I.mkdirSync(E.dirname(Y),{recursive:!0});if(!I.existsSync(Y)){let _=$==="fish"?`# Fish shell configuration
4
+ echo Path updated successfully`;default:return`export PATH="${Y}:$PATH"`}}async function h1($,Y,J,_={}){try{let{autoBackup:Z=!0}=_,Q=H1($,J);if($==="cmd")return I.writeFileSync(Y,Q),console.log(D.yellow(`Created batch file at ${Y}`)),console.log(D.yellow("Run this file to add the bin directory to your PATH")),!0;if(($==="powershell"||$==="powershell-core")&&!I.existsSync(E.dirname(Y)))I.mkdirSync(E.dirname(Y),{recursive:!0});if(!I.existsSync(Y)){let G=$==="fish"?`# Fish shell configuration
5
5
 
6
6
  `:$==="powershell"||$==="powershell-core"?`# PowerShell profile
7
7
 
8
8
  `:`# Shell configuration
9
9
 
10
- `;I.writeFileSync(Y,_),console.log(D.green(`Created config file at ${Y}`))}let H=I.readFileSync(Y,"utf8");if(H.includes(q))return!0;if(Z&&I.existsSync(Y)){let _=L1(),W=E.basename(Y);if(R1(Y,E.join(_,"configs"),W))E1(_,{type:"auto",command:"addBinToPath",message:`Automatic backup before modifying ${W}`,files:[Y]}),I1(_),console.log(D.green(`✓ Backed up ${W} to ${_}`))}let K=`${H.trim()}
10
+ `;I.writeFileSync(Y,G),console.log(D.green(`Created config file at ${Y}`))}let H=I.readFileSync(Y,"utf8");if(H.includes(J))return!0;if(Z&&I.existsSync(Y)){let G=W1(),W=E.basename(Y);if(L1(Y,E.join(G,"configs"),W))R1(G,{type:"auto",command:"addBinToPath",message:`Automatic backup before modifying ${W}`,files:[Y]}),E1(G),console.log(D.green(`✓ Backed up ${W} to ${G}`))}let K=`${H.trim()}
11
11
 
12
12
  # Added by @fnet/cli
13
13
  ${Q}
14
- `;if(I.writeFileSync(Y,K),$==="powershell"||$==="powershell-core")console.log(D.yellow("You may need to set the PowerShell execution policy to run scripts:")),console.log(D.green("Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned"));return!0}catch(Z){return console.error(D.red(`Failed to add bin directory to PATH: ${Z.message}`)),!1}}function g(){return E.join(y.homedir(),".fnet","backups")}function L1(){let $=new Date().toISOString().replace(/:/g,"-").replace(/\..+/,""),Y=E.join(g(),$);if(!I.existsSync(Y))I.mkdirSync(Y,{recursive:!0});return Y}function R1($,Y,q=null){try{if(!I.existsSync($))return!1;let G=q||E.basename($),Z=E.join(Y,G),Q=E.dirname(Z);if(!I.existsSync(Q))I.mkdirSync(Q,{recursive:!0});return I.copyFileSync($,Z),!0}catch(G){return console.error(D.red(`Failed to backup file ${$}: ${G.message}`)),!1}}function E1($,Y={}){let q={timestamp:new Date().toISOString(),type:Y.type||"manual",message:Y.message||"",command:Y.command||"",files:Y.files||[],...Y},G=E.join($,"metadata.json");I.writeFileSync(G,JSON.stringify(q,null,2))}function i1(){let $=g();if(!I.existsSync($))return[];let Y=[],q=I.readdirSync($);for(let G of q){let Z=E.join($,G),Q=I.statSync(Z);if(Q.isDirectory()&&G!=="latest"){let H=E.join(Z,"metadata.json"),K={};if(I.existsSync(H))try{K=JSON.parse(I.readFileSync(H,"utf8"))}catch(_){}Y.push({timestamp:G,path:Z,created:Q.mtime,...K})}}return Y.sort((G,Z)=>new Date(Z.created)-new Date(G.created)),Y}function I1($){let Y=E.join(g(),"latest");try{if(I.existsSync(Y))I.unlinkSync(Y);if(process.platform==="win32")I.writeFileSync(Y+".txt",$);else I.symlinkSync($,Y)}catch(q){console.warn(D.yellow(`Could not create latest symlink: ${q.message}`))}}var L={getBinDirectory:G1,getMetadataDirectory:e,getMetadataFilePath:_1,checkIfInPath:n1,detectUserShell:K1,getShellConfigPath:c1,getAllShellConfigPaths:H1,createBinDirectoryStructure:s1,getExportPathCommand:W1,addBinToPath:r1,getBackupDirectory:g,createBackupDirectory:L1,backupFile:R1,createBackupMetadata:E1,listBackups:i1,updateLatestSymlink:I1};import h from"node:path";import{fileURLToPath as t1}from"node:url";import M1 from"node:os";import o from"node:fs";var KY=h.dirname(t1(import.meta.url));function O1(){}function U1(){let $=M1.homedir(),Y=h.join($,".fnet","bin");if(!o.existsSync(Y))o.mkdirSync(Y,{recursive:!0});return Y}function V1(){let $=M1.homedir(),Y=h.join($,".fnet");if(!o.existsSync(Y))o.mkdirSync(Y,{recursive:!0});return h.join(Y,"bin-registry.json")}import z1 from"node:fs";async function z($){let Y=U1(),q=V1(),G={};if(z1.existsSync(q))try{let Z=z1.readFileSync(q,"utf8");G=JSON.parse(Z)}catch(Z){console.warn(`Warning: Could not parse bin registry: ${Z.message}`)}return{binDir:Y,registryPath:q,registry:G,args:$}}var a1="setup",$$="Initialize the bin system",Y$={yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},q$=async($)=>{try{let Y=await z($);console.log(O.blue("Setting up the bin system...")),await L.createBinDirectoryStructure();let q=L.getBinDirectory();if(console.log(O.green(`Bin directory: ${q}`)),!L.checkIfInPath(q)){console.log(O.yellow("Bin directory is not in PATH."));let Z=$.yes;if(!$.yes)Z=(await v({type:"confirm",name:"confirmAddToPath",message:`Would you like to add ${q} to your PATH?`,initial:!0})).confirmAddToPath;else console.log(O.yellow("Auto-confirming to add bin directory to PATH due to --yes flag"));if(Z){let Q=L.detectUserShell();if(Q==="unknown")if($.yes)Q=process.platform==="win32"?"powershell":"bash",console.log(O.yellow(`Auto-selecting ${Q} shell due to --yes flag`));else{let{selectedShell:W}=await v({type:"select",name:"selectedShell",message:"Select your shell:",choices:[{name:"bash",message:"Bash"},{name:"zsh",message:"Zsh"},{name:"fish",message:"Fish"},{name:"powershell",message:"PowerShell"},{name:"powershell-core",message:"PowerShell Core"},{name:"cmd",message:"Windows Command Prompt"},{name:"ksh",message:"Korn Shell (ksh)"},{name:"csh",message:"C Shell (csh/tcsh)"}]});Q=W}else if($.yes)console.log(O.yellow(`Auto-confirming detected shell: ${Q} due to --yes flag`));else{let{confirmShell:W}=await v({type:"confirm",name:"confirmShell",message:`Detected shell: ${Q}. Is this correct?`,initial:!0});if(!W){let{selectedShell:X}=await v({type:"select",name:"selectedShell",message:"Select your shell:",choices:[{name:"bash",message:"Bash"},{name:"zsh",message:"Zsh"},{name:"fish",message:"Fish"},{name:"powershell",message:"PowerShell"},{name:"powershell-core",message:"PowerShell Core"},{name:"cmd",message:"Windows Command Prompt"},{name:"ksh",message:"Korn Shell (ksh)"},{name:"csh",message:"C Shell (csh/tcsh)"}]});Q=X}}let H=L.getAllShellConfigPaths(Q),K;if(H.length>1){let W=H.filter((X)=>e1.existsSync(X.path));if(W.length>0)if($.yes)K=W[0].path,console.log(O.yellow(`Auto-selecting config file: ${K} due to --yes flag`));else{let{selectedConfigPath:X}=await v({type:"select",name:"selectedConfigPath",message:"Select the configuration file to modify:",choices:W.map((J)=>({name:J.path,message:`${J.name} (${J.path})`}))});K=X}else if($.yes)K=H[0].path,console.log(O.yellow(`Auto-selecting config file to create: ${K} due to --yes flag`));else{let{selectedConfigPath:X}=await v({type:"select",name:"selectedConfigPath",message:"Select the configuration file to create:",choices:H.map((J)=>({name:J.path,message:`${J.name} (${J.path})`}))});K=X}}else if(H.length===1)K=H[0].path;else if($.yes)K=w1.join(T1.homedir(),process.platform==="win32"?"_profile":".bashrc"),console.log(O.yellow(`Auto-selecting default config file: ${K} due to --yes flag`));else{let{enteredConfigPath:W}=await v({type:"input",name:"enteredConfigPath",message:"Enter the path to your shell configuration file:",initial:w1.join(T1.homedir(),".bashrc")});K=W}if(await L.addBinToPath(Q,K,q))console.log(O.green(`Added bin directory to PATH in ${K}`)),console.log(O.yellow("Please restart your terminal or run the following command:")),console.log(O.green(`source ${K}`));else console.log(O.red(`Failed to add bin directory to PATH in ${K}`)),console.log(O.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(O.green(L.getExportPathCommand(Q,q)))}else console.log(O.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(O.green(`export PATH="${q}:$PATH"`)),console.log(O.yellow("Or run:")),console.log(O.green("fbin path"))}else console.log(O.green("Bin directory is already in PATH."));console.log(O.green("Bin system setup completed successfully."))}catch(Y){console.error(O.red(`Failed to set up bin system: ${Y.message}`)),process.exit(1)}},N1={command:a1,describe:$$,builder:Y$,handler:q$};import A1 from"node:path";import J$ from"node:fs";import B1 from"node:os";import A from"chalk";import u from"@fnet/prompt";var Q$="path",X$="Add bin directory to PATH",Z$={yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},G$=async($)=>{try{let Y=await z($),q=L.getBinDirectory();if(console.log(A.blue(`Adding ${q} to PATH...`)),!L.createBinDirectoryStructure())console.log(A.yellow("Creating bin directory structure...")),await L.createBinDirectoryStructure();if(L.checkIfInPath(q)){console.log(A.green("Bin directory is already in PATH."));return}let Z=L.detectUserShell();if(Z==="unknown")if($.yes)Z=process.platform==="win32"?"powershell":"bash",console.log(A.yellow(`Auto-selecting ${Z} shell due to --yes flag`));else{let{selectedShell:_}=await u({type:"select",name:"selectedShell",message:"Select your shell:",choices:[{name:"bash",message:"Bash"},{name:"zsh",message:"Zsh"},{name:"fish",message:"Fish"},{name:"powershell",message:"PowerShell"},{name:"powershell-core",message:"PowerShell Core"},{name:"cmd",message:"Windows Command Prompt"},{name:"ksh",message:"Korn Shell (ksh)"},{name:"csh",message:"C Shell (csh/tcsh)"}]});Z=_}else if($.yes)console.log(A.yellow(`Auto-confirming detected shell: ${Z} due to --yes flag`));else{let{confirmShell:_}=await u({type:"confirm",name:"confirmShell",message:`Detected shell: ${Z}. Is this correct?`,initial:!0});if(!_){let{selectedShell:W}=await u({type:"select",name:"selectedShell",message:"Select your shell:",choices:[{name:"bash",message:"Bash"},{name:"zsh",message:"Zsh"},{name:"fish",message:"Fish"},{name:"powershell",message:"PowerShell"},{name:"powershell-core",message:"PowerShell Core"},{name:"cmd",message:"Windows Command Prompt"},{name:"ksh",message:"Korn Shell (ksh)"},{name:"csh",message:"C Shell (csh/tcsh)"}]});Z=W}}let Q=L.getAllShellConfigPaths(Z),H;if(Q.length>1){let _=Q.filter((W)=>J$.existsSync(W.path));if(_.length>0)if($.yes)H=_[0].path,console.log(A.yellow(`Auto-selecting config file: ${H} due to --yes flag`));else{let{selectedConfigPath:W}=await u({type:"select",name:"selectedConfigPath",message:"Select the configuration file to modify:",choices:_.map((X)=>({name:X.path,message:`${X.name} (${X.path})`}))});H=W}else if($.yes)H=Q[0].path,console.log(A.yellow(`Auto-selecting config file to create: ${H} due to --yes flag`));else{let{selectedConfigPath:W}=await u({type:"select",name:"selectedConfigPath",message:"Select the configuration file to create:",choices:Q.map((X)=>({name:X.path,message:`${X.name} (${X.path})`}))});H=W}}else if(Q.length===1)H=Q[0].path;else if($.yes)H=A1.join(B1.homedir(),process.platform==="win32"?"_profile":".bashrc"),console.log(A.yellow(`Auto-selecting default config file: ${H} due to --yes flag`));else{let{enteredConfigPath:_}=await u({type:"input",name:"enteredConfigPath",message:"Enter the path to your shell configuration file:",initial:A1.join(B1.homedir(),".bashrc")});H=_}if(await L.addBinToPath(Z,H,q))console.log(A.green(`Added bin directory to PATH in ${H}`)),console.log(A.yellow("Please restart your terminal or run the following command:")),console.log(A.green(`source ${H}`));else console.log(A.red(`Failed to add bin directory to PATH in ${H}`)),console.log(A.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(A.green(L.getExportPathCommand(Z,q)))}catch(Y){console.error(A.red(`Failed to add bin directory to PATH: ${Y.message}`)),process.exit(1)}},j1={command:Q$,describe:X$,builder:Z$,handler:G$};import l from"node:path";import f from"node:fs";import x from"chalk";import _$ from"@fnet/prompt";var K$="compile [source] [options]",H$="Compile a CLI project to a binary",W$={source:{describe:"Source file to compile",type:"string",default:"./dist/cli/esm/index.js"},output:{describe:"Output file name",type:"string",alias:"o"},name:{describe:"Binary name",type:"string",alias:"n"},force:{describe:"Force overwrite if binary already exists",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},target:{describe:"Target platform (auto, linux, macos, windows)",type:"string",choices:["auto","linux","macos","windows"],default:"auto"},minify:{describe:"Minify the output binary",type:"boolean",default:!0},external:{describe:"External packages to exclude from the bundle (comma-separated)",type:"string"}},L$=async($)=>{try{let Y=await z($),q=process.cwd(),G=l.basename(q),Z=$.name||G,Q;if($.output)Q=$.output;else{let J=l.join(q,".bin");if(!f.existsSync(J))f.mkdirSync(J,{recursive:!0});Q=l.join(J,Z)}let H=l.resolve(process.cwd(),$.source);if(!f.existsSync(H))console.error(x.red(`Source file not found: ${H}`)),console.error(x.yellow("Make sure to build your project first.")),process.exit(1);if(f.existsSync(Q)&&!$.force&&!$.yes){let{confirmOverwrite:J}=await _$({type:"confirm",name:"confirmOverwrite",message:`Binary already exists at ${Q}. Overwrite?`,initial:!1});if(!J){console.log(x.yellow("Compilation cancelled."));return}}let K=process.platform;if(console.log(x.blue(`Detected platform: ${K}`)),K==="win32"&&!Q.endsWith(".exe"))Q=`${Q}.exe`,console.log(x.blue(`Adjusted output path for Windows: ${Q}`));console.log(x.blue(`Compiling ${H} to ${Q}...`));let{spawn:_}=await import("child_process");try{let J=_("bun",["--version"],{stdio:"pipe"});await new Promise((R,M)=>{J.on("close",(T)=>{if(T===0)R();else M(Error("Bun is not available. Please install Bun first."))}),J.on("error",(T)=>{M(Error(`Bun is not available: ${T.message}`))})})}catch(J){console.error(x.red(`Bun is not available: ${J.message}`)),console.error(x.yellow("Please install Bun first: https://bun.sh/")),process.exit(1)}let W=["build",H,"--compile",`--outfile=${Q}`];if($.target&&$.target!=="auto")W.push(`--target=${$.target}`);if($.minify===!1)W.push("--no-minify");if($.external)$.external.split(",").map((R)=>R.trim()).forEach((R)=>{W.push(`--external:${R}`)});console.log(x.blue(`Running: bun ${W.join(" ")}`));let X=_("bun",W,{stdio:"inherit"});if(await new Promise((J,R)=>{X.on("close",(M)=>{if(M===0)J();else R(Error(`Compilation failed with code ${M}`))}),X.on("error",(M)=>{R(M)})}),K!=="win32")f.chmodSync(Q,493);if(console.log(x.green(`Binary compiled successfully: ${Q}`)),K==="win32")console.log(x.yellow("Note: On Windows, you may need to run the binary from a command prompt or PowerShell."));else if(K==="darwin")console.log(x.yellow("Note: On macOS, you may need to allow the binary to run in System Preferences > Security & Privacy."))}catch(Y){console.error(x.red(`Failed to compile binary: ${Y.message}`)),process.exit(1)}},F1={command:K$,describe:H$,builder:W$,handler:L$};import n from"node:path";import C from"node:fs";import B from"chalk";import R$ from"@fnet/prompt";var E$="install [source] [options]",I$="Install a binary to the bin directory",M$={source:{describe:"Source binary to install",type:"string",demandOption:!0},name:{describe:"Name to use for the installed binary",type:"string",alias:"n"},force:{describe:"Force overwrite if binary already exists",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},symlink:{describe:"Create a symlink instead of copying the binary",type:"boolean",default:!1,alias:"s"}},O$=async($)=>{try{let Y=await z($),q=n.resolve(process.cwd(),$.source);if(!C.existsSync(q))console.error(B.red(`Source file not found: ${q}`)),process.exit(1);await L.createBinDirectoryStructure();let G=L.getBinDirectory(),Z;if($.name)Z=$.name;else Z=n.basename(q);if(process.platform==="win32"&&!Z.endsWith(".exe"))Z=`${Z}.exe`;let Q=n.join(G,Z);if(C.existsSync(Q)&&!$.force&&!$.yes){let{confirmOverwrite:X}=await R$({type:"confirm",name:"confirmOverwrite",message:`Binary already exists at ${Q}. Overwrite?`,initial:!1});if(!X){console.log(B.yellow("Installation cancelled."));return}}if($.symlink){if(console.log(B.blue(`Creating symlink from ${q} to ${Q}...`)),C.existsSync(Q))C.unlinkSync(Q);if(process.platform==="win32")C.symlinkSync(q,Q,"file");else C.symlinkSync(q,Q);console.log(B.green("Symlink created successfully."))}else if(console.log(B.blue(`Installing ${q} to ${Q}...`)),C.copyFileSync(q,Q),process.platform!=="win32")C.chmodSync(Q,493);let H=L.getMetadataFilePath(),K={binaries:{},lastUpdated:new Date().toISOString()};if(C.existsSync(H))try{K=JSON.parse(C.readFileSync(H,"utf8"))}catch(X){console.warn(B.yellow(`Failed to parse metadata file: ${X.message}`)),console.warn(B.yellow("Creating new metadata file."))}let _="0.0.0";try{let{execSync:X}=Z1("child_process"),J=X(`"${Q}" --version`,{timeout:5000,stdio:["ignore","pipe","ignore"]}).toString().trim(),R=J.match(/v?(\d+\.\d+\.\d+)/);if(R)_=R[1],console.log(B.blue(`Detected binary version: ${_}`));else console.log(B.yellow(`Could not parse version from output: ${J}`)),console.log(B.yellow(`Using default version: ${_}`))}catch(X){console.log(B.yellow(`Could not detect binary version, using default: ${_}`))}if(K.binaries[Z]={path:Q,source:q,created:new Date().toISOString(),platform:process.platform,version:_,project:n.basename(process.cwd()),isSymlink:$.symlink||!1},K.lastUpdated=new Date().toISOString(),C.writeFileSync(H,JSON.stringify(K,null,2)),console.log(B.green(`Binary installed successfully: ${Q}`)),!L.checkIfInPath(G))console.log(B.yellow("Bin directory is not in PATH. Run 'fbin path' to add it."));else console.log(B.green(`You can now run '${Z}' from anywhere.`))}catch(Y){console.error(B.red(`Failed to install binary: ${Y.message}`)),process.exit(1)}},x1={command:E$,describe:I$,builder:M$,handler:O$};import P from"node:fs";import w from"chalk";import z$ from"@fnet/prompt";import c from"chalk";import C1 from"@fnet/prompt";async function U$($){let{items:Y,message:q,nameField:G="name",valueField:Z="name",initialValue:Q=null,allowAbort:H=!0}=$;if(!Y||Y.length===0)return console.log(c.yellow("No items available for selection.")),null;if(Y.length===1&&!H){let J=Y[0],R=typeof J==="string"?J:J[Z];return console.log(c.blue(`Only one option available: ${typeof J==="string"?J:J[G]}`)),R}let K=Y.map((J)=>{if(typeof J==="string")return{name:J,value:J,message:J};else return{name:J[Z],value:J[Z],message:J[G]||J[Z]}});if(H)K.push({name:"cancel",value:null,message:c.yellow("Cancel")});let _=null;if(Q){let J=K.findIndex((R)=>R.name===Q);if(J!==-1)_=J}let W="selectedItem",{[W]:X}=await C1({type:"select",name:W,message:q,choices:K,initial:_});if(X==="cancel")return null;return X}async function V$($){let{items:Y,message:q,nameField:G="name",valueField:Z="name",initialValues:Q=[],allowAbort:H=!0}=$;if(!Y||Y.length===0)return console.log(c.yellow("No items available for selection.")),null;let K=Y.map((J)=>{if(typeof J==="string")return{name:J,value:J,message:J};else return{name:J[Z],value:J[Z],message:J[G]||J[Z]}}),_=[];if(Q&&Q.length>0)_=K.map((J,R)=>Q.includes(J.name)?R:-1).filter((J)=>J!==-1);let W="selectedItems",X=await C1({type:"multiselect",name:W,message:q,choices:K,initial:_,hint:"(Use space to select, enter to confirm)",validate:(J)=>{if(J.length===0&&!H)return"Please select at least one item";return!0}});if(H&&X[W].length===0)return null;return X[W]}var s={promptForSelection:U$,promptForMultipleSelection:V$};var w$="uninstall [name] [options]",T$="Uninstall a binary from the bin directory",N$={name:{describe:"Name of the binary to uninstall",type:"string",demandOption:!1},force:{describe:"Skip confirmation prompt",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},A$=async($)=>{try{let Y=await z($),q=L.getBinDirectory(),G=L.getMetadataFilePath();if(!P.existsSync(q))console.error(w.red(`Bin directory not found: ${q}`)),console.error(w.yellow("Run fbin setup first.")),process.exit(1);if(!P.existsSync(G))console.error(w.red(`Metadata file not found: ${G}`)),console.error(w.yellow("Run fbin setup first.")),process.exit(1);let Z;try{Z=JSON.parse(P.readFileSync(G,"utf8"))}catch(K){console.error(w.red(`Failed to parse metadata file: ${K.message}`)),process.exit(1)}if(!$.name&&!$.yes){let K=Object.keys(Z.binaries);if(K.length===0){console.log(w.yellow("No binaries installed."));return}let _=await s.promptForSelection({items:K,message:"Select a binary to uninstall:",allowAbort:!0});if(_===null){console.log(w.yellow("Uninstallation cancelled."));return}$.name=_}let Q=$.name;if(!Q)console.error(w.red("Binary name is required.")),console.error(w.yellow("Use --name to specify a binary or run without --yes to select interactively.")),process.exit(1);if(!Z.binaries[Q])console.error(w.red(`Binary not found in metadata: ${Q}`)),console.log(w.yellow("Use fbin list to see installed binaries.")),process.exit(1);let H=Z.binaries[Q].path;if(!P.existsSync(H))console.warn(w.yellow(`Binary file not found: ${H}`)),console.warn(w.yellow("Metadata will be updated anyway."));if(!$.force&&!$.yes){let{confirmUninstall:K}=await z$({type:"confirm",name:"confirmUninstall",message:`Are you sure you want to uninstall ${Q}?`,initial:!1});if(!K){console.log(w.yellow("Uninstallation cancelled."));return}}if(P.existsSync(H))try{P.unlinkSync(H),console.log(w.green(`Binary file removed: ${H}`))}catch(K){console.error(w.red(`Failed to remove binary file: ${K.message}`))}delete Z.binaries[Q],Z.lastUpdated=new Date().toISOString(),P.writeFileSync(G,JSON.stringify(Z,null,2)),console.log(w.green(`Binary uninstalled successfully: ${Q}`))}catch(Y){console.error(w.red(`Failed to uninstall binary: ${Y.message}`)),process.exit(1)}},S1={command:w$,describe:T$,builder:N$,handler:A$};import a from"node:fs";import S from"chalk";import B$ from"cli-table3";import k from"chalk";function D1($,Y={}){let G={...{chars:{top:"─","top-mid":"─","top-left":" ","top-right":" ",bottom:"─","bottom-mid":"─","bottom-left":" ","bottom-right":" ",left:" ","left-mid":" ",mid:"─","mid-mid":"─",right:" ","right-mid":" ",middle:" "},style:{head:[],border:[],compact:!0},wordWrap:!0},...Y,head:$.map((Z)=>k.bold(Z))};return new B$(G)}function j$($,Y,q={}){let G=D1($,q);if(Array.isArray(Y))Y.forEach((Z)=>{G.push(Z)});return G.toString()}function F$($){switch($){case"running":return k.green;case"stopped":return k.yellow;case"failed":return k.red;case"registered":return k.blue;default:return k.gray}}var p={createTable:D1,createTableWithData:j$,getStatusColor:F$};var x$="list [options]",C$="List installed binaries",S$={json:{describe:"Output in JSON format",type:"boolean",default:!1,alias:"j"},filter:{describe:"Filter binaries by name",type:"string",alias:"f"}},D$=async($)=>{try{let Y=await z($),q=L.getBinDirectory(),G=L.getMetadataFilePath();if(!a.existsSync(q))console.error(S.red(`Bin directory not found: ${q}`)),console.error(S.yellow("Run fbin setup first.")),process.exit(1);if(!a.existsSync(G))console.error(S.red(`Metadata file not found: ${G}`)),console.error(S.yellow("Run fbin setup first.")),process.exit(1);let Z;try{Z=JSON.parse(a.readFileSync(G,"utf8"))}catch(X){console.error(S.red(`Failed to parse metadata file: ${X.message}`)),process.exit(1)}let Q=Z.binaries;if($.filter){let X=$.filter.toLowerCase();Q=Object.entries(Q).filter(([J])=>J.toLowerCase().includes(X)).reduce((J,[R,M])=>{return J[R]=M,J},{})}if($.json){console.log(JSON.stringify(Q,null,2));return}let H=Object.keys(Q).length;if(H===0){console.log(S.yellow("No binaries installed."));return}console.log(S.blue(`Found ${H} installed binaries:`)),console.log();let K=["NAME","VERSION","PLATFORM","CREATED"],_=p.createTable(K,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});if(Object.entries(Q).forEach(([X,J])=>{let R=new Date(J.created).toLocaleString();_.push([S.white(X),J.version||"N/A",J.platform||"N/A",R])}),console.log(_.toString()),console.log(),console.log(S.blue(`Bin directory: ${q}`)),!L.checkIfInPath(q))console.log(S.yellow("Bin directory is not in PATH. Run 'fbin path' to add it."))}catch(Y){console.error(S.red(`Failed to list binaries: ${Y.message}`)),process.exit(1)}},y1={command:x$,describe:C$,builder:S$,handler:D$};import $1 from"node:path";import d from"node:fs";import j from"chalk";var y$="backup [options]",v$="Backup shell configs and binaries",P$={config:{describe:"Backup shell configuration files",type:"boolean",default:!1,alias:"c"},binaries:{describe:"Backup installed binaries",type:"boolean",default:!1,alias:"b"},all:{describe:"Backup everything (configs + binaries)",type:"boolean",default:!1,alias:"a"},message:{describe:"Backup description message",type:"string",alias:"m"}},d$=async($)=>{try{let Y=await z($),q=$.all||!$.config&&!$.binaries,G=$.config||q,Z=$.binaries||q;console.log(j.blue("Creating backup..."));let Q=L.createBackupDirectory(),H=[];if(G){console.log(j.blue("Backing up shell configurations..."));let K=$1.join(Q,"configs");d.mkdirSync(K,{recursive:!0});let _=L.detectUserShell(),W=L.getAllShellConfigPaths(_),X=0;for(let J of W)if(d.existsSync(J.path)){if(L.backupFile(J.path,K,J.name))H.push(J.path),X++,console.log(j.green(` ✓ ${J.name}`))}if(X===0)console.log(j.yellow(" No configuration files found to backup"));else console.log(j.green(` Backed up ${X} configuration file(s)`))}if(Z){console.log(j.blue("Backing up binaries..."));let K=$1.join(Q,"binaries");d.mkdirSync(K,{recursive:!0});let _=L.getBinDirectory(),W=L.getMetadataFilePath();if(d.existsSync(W))L.backupFile(W,K,"metadata.json"),H.push(W);if(d.existsSync(_)){let X=d.readdirSync(_),J=0;for(let R of X){let M=$1.join(_,R);if(d.statSync(M).isFile()){if(L.backupFile(M,K,R))H.push(M),J++,console.log(j.green(` ✓ ${R}`))}}if(J===0)console.log(j.yellow(" No binaries found to backup"));else console.log(j.green(` Backed up ${J} binary(ies)`))}else console.log(j.yellow(" Bin directory not found"))}if(L.createBackupMetadata(Q,{type:"manual",command:"fbin backup",message:$.message||"Manual backup",files:H,config:G,binaries:Z}),L.updateLatestSymlink(Q),console.log(),console.log(j.green("✓ Backup created successfully!")),console.log(j.blue(` Location: ${Q}`)),console.log(j.blue(` Files backed up: ${H.length}`)),$.message)console.log(j.blue(` Message: ${$.message}`))}catch(Y){console.error(j.red(`Failed to create backup: ${Y.message}`)),process.exit(1)}},v1={command:y$,describe:v$,builder:P$,handler:d$};import m from"node:path";import F from"node:fs";import V from"chalk";import m$ from"@fnet/prompt";var u$="restore [options]",k$="Restore from backup",p$={config:{describe:"Restore shell configuration files",type:"boolean",default:!1,alias:"c"},binaries:{describe:"Restore installed binaries",type:"boolean",default:!1,alias:"b"},all:{describe:"Restore everything (configs + binaries)",type:"boolean",default:!1,alias:"a"},list:{describe:"List available backups",type:"boolean",default:!1,alias:"l"},timestamp:{describe:"Backup timestamp to restore (defaults to latest)",type:"string",alias:"t"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},f$=async($)=>{try{let Y=await z($);if($.list){let _=L.listBackups();if(_.length===0){console.log(V.yellow("No backups found."));return}console.log(V.blue(`Found ${_.length} backup(s):
15
- `));let W=["TIMESTAMP","TYPE","MESSAGE","FILES"],X=p.createTable(W,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});for(let J of _){let R=J.timestamp||"unknown",M=J.type||"manual",T=J.message||"",N=J.files?J.files.length:0;X.push([V.white(R),M,T.substring(0,40)+(T.length>40?"...":""),N.toString()])}console.log(X.toString()),console.log(),console.log(V.blue(`Backup directory: ${L.getBackupDirectory()}`));return}let q=L.listBackups();if(q.length===0){console.log(V.yellow("No backups found.")),console.log(V.blue("Create a backup first with: fbin backup"));return}let G;if($.timestamp){if(G=q.find((_)=>_.timestamp===$.timestamp),!G)console.error(V.red(`Backup not found: ${$.timestamp}`)),console.log(V.yellow("Use --list to see available backups")),process.exit(1)}else if($.yes)G=q[0],console.log(V.yellow(`Auto-selecting latest backup: ${G.timestamp}`));else{let _=q.map((X)=>({name:X.timestamp,message:`${X.timestamp} - ${X.message||"No message"} (${X.files?.length||0} files)`})),W=await s.promptForSelection({items:_.map((X)=>X.name),message:"Select a backup to restore:",allowAbort:!0});if(W===null){console.log(V.yellow("Restore cancelled."));return}G=q.find((X)=>X.timestamp===W)}console.log(V.blue(`Restoring from backup: ${G.timestamp}`));let Z=$.all||!$.config&&!$.binaries,Q=$.config||Z,H=$.binaries||Z;if(!$.yes){let{confirmRestore:_}=await m$({type:"confirm",name:"confirmRestore",message:"This will overwrite current files. Continue?",initial:!1});if(!_){console.log(V.yellow("Restore cancelled."));return}}let K=0;if(Q){let _=m.join(G.path,"configs");if(F.existsSync(_)){console.log(V.blue("Restoring shell configurations..."));let W=F.readdirSync(_);for(let X of W){let J=m.join(_,X),R=L.detectUserShell(),T=L.getAllShellConfigPaths(R).find((N)=>N.name===X);if(T){let N=T.path,b=m.dirname(N);if(!F.existsSync(b))F.mkdirSync(b,{recursive:!0});F.copyFileSync(J,N),console.log(V.green(` ✓ ${X}`)),K++}}}}if(H){let _=m.join(G.path,"binaries");if(F.existsSync(_)){console.log(V.blue("Restoring binaries..."));let W=L.getBinDirectory();if(!F.existsSync(W))F.mkdirSync(W,{recursive:!0});let X=F.readdirSync(_);for(let J of X){let R=m.join(_,J),M=m.join(W,J);if(J==="metadata.json"){let T=L.getMetadataFilePath(),N=m.dirname(T);if(!F.existsSync(N))F.mkdirSync(N,{recursive:!0});F.copyFileSync(R,T),console.log(V.green(" ✓ metadata.json")),K++;continue}if(F.copyFileSync(R,M),process.platform!=="win32")F.chmodSync(M,493);console.log(V.green(` ✓ ${J}`)),K++}}}console.log(),console.log(V.green("✓ Restore completed successfully!")),console.log(V.blue(` Files restored: ${K}`))}catch(Y){console.error(V.red(`Failed to restore backup: ${Y.message}`)),process.exit(1)}},P1={command:u$,describe:k$,builder:p$,handler:f$};import b$ from"node:path";import Y1 from"node:fs";import U from"chalk";import g$ from"@fnet/prompt";var h$="cleanup [options]",o$="Clean up old backups",l$={keep:{describe:"Number of recent backups to keep",type:"number",default:10,alias:"k"},older:{describe:"Remove backups older than N days",type:"number",alias:"o"},all:{describe:"Remove all backups",type:"boolean",default:!1,alias:"a"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},"dry-run":{describe:"Show what would be deleted without actually deleting",type:"boolean",default:!1,alias:"d"}},n$=async($)=>{try{let Y=await z($),q=L.listBackups();if(q.length===0){console.log(U.yellow("No backups found."));return}console.log(U.blue(`Found ${q.length} backup(s)`));let G=[];if($.all)G=q;else if($.older){let X=new Date;X.setDate(X.getDate()-$.older),G=q.filter((J)=>{return new Date(J.created)<X}),console.log(U.blue(`Removing backups older than ${$.older} days (before ${X.toLocaleDateString()})`))}else if(q.length>$.keep)G=q.slice($.keep),console.log(U.blue(`Keeping ${$.keep} most recent backup(s), removing ${G.length} old backup(s)`));else{console.log(U.green(`Only ${q.length} backup(s) found, keeping all (limit: ${$.keep})`));return}if(G.length===0){console.log(U.green("No backups to delete."));return}console.log(),console.log(U.yellow(`Backups to be deleted (${G.length}):`)),console.log();let Z=["TIMESTAMP","TYPE","MESSAGE","FILES","SIZE"],Q=p.createTable(Z,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}}),H=0;for(let X of G){let J=X.timestamp||"unknown",R=X.type||"manual",M=X.message||"",T=X.files?X.files.length:0,N=0;try{let i=(q1)=>{let t=0,k1=Y1.readdirSync(q1);for(let p1 of k1){let J1=b$.join(q1,p1),Q1=Y1.statSync(J1);if(Q1.isDirectory())t+=i(J1);else t+=Q1.size}return t};N=i(X.path),H+=N}catch(i){}let b=N>0?`${(N/1024/1024).toFixed(2)} MB`:"N/A";Q.push([U.white(J),R,M.substring(0,30)+(M.length>30?"...":""),T.toString(),b])}if(console.log(Q.toString()),console.log(),console.log(U.blue(`Total size to free: ${(H/1024/1024).toFixed(2)} MB`)),$["dry-run"]){console.log(),console.log(U.yellow("DRY RUN: No backups were deleted.")),console.log(U.blue("Run without --dry-run to actually delete these backups."));return}if(!$.yes){console.log();let{confirmDelete:X}=await g$({type:"confirm",name:"confirmDelete",message:`Delete ${G.length} backup(s)?`,initial:!1});if(!X){console.log(U.yellow("Cleanup cancelled."));return}}console.log(),console.log(U.blue("Deleting backups..."));let K=0,_=0;for(let X of G)try{Y1.rmSync(X.path,{recursive:!0,force:!0}),console.log(U.green(` ✓ ${X.timestamp}`)),K++}catch(J){console.log(U.red(` ✗ ${X.timestamp}: ${J.message}`)),_++}if(console.log(),console.log(U.green("✓ Cleanup completed!")),console.log(U.blue(` Deleted: ${K}`)),_>0)console.log(U.yellow(` Failed: ${_}`));console.log(U.blue(` Space freed: ${(H/1024/1024).toFixed(2)} MB`));let W=L.listBackups();console.log(U.blue(` Remaining backups: ${W.length}`))}catch(Y){console.error(U.red(`Failed to cleanup backups: ${Y.message}`)),process.exit(1)}},d1={command:h$,describe:o$,builder:l$,handler:n$};import{promisify as c$}from"node:util";import s$ from"tree-kill";var v0=c$(s$),r=!1;function m1(){process.on("uncaughtException",($)=>{if(!r)r=!0,setTimeout(()=>process.exit(1),500)}),process.on("unhandledRejection",($)=>{if(!r)r=!0,setTimeout(()=>process.exit(1),500)})}m1();O1();async function t$(){try{let $=r$(i$(process.argv)).usage("Usage: $0 <command> [options]").command(N1).command(j1).command(F1).command(x1).command(S1).command(y1).command(v1).command(P1).command(d1).demandCommand(1,"You need to specify a command").help().version().argv}catch($){console.error(u1.red(`Fatal error: ${$.message}`)),process.exit(1)}}t$().catch(($)=>{console.error(u1.red(`Fatal error: ${$.message}`)),process.exit(1)});
14
+ `;if(I.writeFileSync(Y,K),$==="powershell"||$==="powershell-core")console.log(D.yellow("You may need to set the PowerShell execution policy to run scripts:")),console.log(D.green("Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned"));return!0}catch(Z){return console.error(D.red(`Failed to add bin directory to PATH: ${Z.message}`)),!1}}function g(){return E.join(y.homedir(),".fnet","backups")}function W1(){let $=new Date().toISOString().replace(/:/g,"-").replace(/\..+/,""),Y=E.join(g(),$);if(!I.existsSync(Y))I.mkdirSync(Y,{recursive:!0});return Y}function L1($,Y,J=null){try{if(!I.existsSync($))return!1;let _=J||E.basename($),Z=E.join(Y,_),Q=E.dirname(Z);if(!I.existsSync(Q))I.mkdirSync(Q,{recursive:!0});return I.copyFileSync($,Z),!0}catch(_){return console.error(D.red(`Failed to backup file ${$}: ${_.message}`)),!1}}function R1($,Y={}){let J={timestamp:new Date().toISOString(),type:Y.type||"manual",message:Y.message||"",command:Y.command||"",files:Y.files||[],...Y},_=E.join($,"metadata.json");I.writeFileSync(_,JSON.stringify(J,null,2))}function o1(){let $=g();if(!I.existsSync($))return[];let Y=[],J=I.readdirSync($);for(let _ of J){let Z=E.join($,_),Q=I.statSync(Z);if(Q.isDirectory()&&_!=="latest"){let H=E.join(Z,"metadata.json"),K={};if(I.existsSync(H))try{K=JSON.parse(I.readFileSync(H,"utf8"))}catch(G){}Y.push({timestamp:_,path:Z,created:Q.mtime,...K})}}return Y.sort((_,Z)=>new Date(Z.created)-new Date(_.created)),Y}function E1($){let Y=E.join(g(),"latest");try{if(I.existsSync(Y))I.unlinkSync(Y);if(process.platform==="win32")I.writeFileSync(Y+".txt",$);else I.symlinkSync($,Y)}catch(J){console.warn(D.yellow(`Could not create latest symlink: ${J.message}`))}}var L={getBinDirectory:Z1,getMetadataDirectory:e,getMetadataFilePath:G1,checkIfInPath:f1,detectUserShell:_1,getShellConfigPath:b1,getAllShellConfigPaths:K1,createBinDirectoryStructure:g1,getExportPathCommand:H1,addBinToPath:h1,getBackupDirectory:g,createBackupDirectory:W1,backupFile:L1,createBackupMetadata:R1,listBackups:o1,updateLatestSymlink:E1};import h from"node:path";import{fileURLToPath as l1}from"node:url";import I1 from"node:os";import o from"node:fs";var JY=h.dirname(l1(import.meta.url));function M1(){}function O1(){let $=I1.homedir(),Y=h.join($,".fnet","bin");if(!o.existsSync(Y))o.mkdirSync(Y,{recursive:!0});return Y}function U1(){let $=I1.homedir(),Y=h.join($,".fnet");if(!o.existsSync(Y))o.mkdirSync(Y,{recursive:!0});return h.join(Y,"bin-registry.json")}import V1 from"node:fs";async function z($){let Y=O1(),J=U1(),_={};if(V1.existsSync(J))try{let Z=V1.readFileSync(J,"utf8");_=JSON.parse(Z)}catch(Z){console.warn(`Warning: Could not parse bin registry: ${Z.message}`)}return{binDir:Y,registryPath:J,registry:_,args:$}}var c1="setup",s1="Initialize the bin system",r1={yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},i1=async($)=>{try{let Y=await z($);console.log(O.blue("Setting up the bin system...")),await L.createBinDirectoryStructure();let J=L.getBinDirectory();if(console.log(O.green(`Bin directory: ${J}`)),!L.checkIfInPath(J)){console.log(O.yellow("Bin directory is not in PATH."));let Z=$.yes;if(!$.yes)Z=(await v({type:"confirm",name:"confirmAddToPath",message:`Would you like to add ${J} to your PATH?`,initial:!0})).confirmAddToPath;else console.log(O.yellow("Auto-confirming to add bin directory to PATH due to --yes flag"));if(Z){let Q=L.detectUserShell();if(Q==="unknown")if($.yes)Q=process.platform==="win32"?"powershell":"bash",console.log(O.yellow(`Auto-selecting ${Q} shell due to --yes flag`));else{let{selectedShell:W}=await v({type:"select",name:"selectedShell",message:"Select your shell:",choices:[{name:"bash",message:"Bash"},{name:"zsh",message:"Zsh"},{name:"fish",message:"Fish"},{name:"powershell",message:"PowerShell"},{name:"powershell-core",message:"PowerShell Core"},{name:"cmd",message:"Windows Command Prompt"},{name:"ksh",message:"Korn Shell (ksh)"},{name:"csh",message:"C Shell (csh/tcsh)"}]});Q=W}else if($.yes)console.log(O.yellow(`Auto-confirming detected shell: ${Q} due to --yes flag`));else{let{confirmShell:W}=await v({type:"confirm",name:"confirmShell",message:`Detected shell: ${Q}. Is this correct?`,initial:!0});if(!W){let{selectedShell:X}=await v({type:"select",name:"selectedShell",message:"Select your shell:",choices:[{name:"bash",message:"Bash"},{name:"zsh",message:"Zsh"},{name:"fish",message:"Fish"},{name:"powershell",message:"PowerShell"},{name:"powershell-core",message:"PowerShell Core"},{name:"cmd",message:"Windows Command Prompt"},{name:"ksh",message:"Korn Shell (ksh)"},{name:"csh",message:"C Shell (csh/tcsh)"}]});Q=X}}let H=L.getAllShellConfigPaths(Q),K;if(H.length>1){let W=H.filter((X)=>n1.existsSync(X.path));if(W.length>0)if($.yes)K=W[0].path,console.log(O.yellow(`Auto-selecting config file: ${K} due to --yes flag`));else{let{selectedConfigPath:X}=await v({type:"select",name:"selectedConfigPath",message:"Select the configuration file to modify:",choices:W.map((q)=>({name:q.path,message:`${q.name} (${q.path})`}))});K=X}else if($.yes)K=H[0].path,console.log(O.yellow(`Auto-selecting config file to create: ${K} due to --yes flag`));else{let{selectedConfigPath:X}=await v({type:"select",name:"selectedConfigPath",message:"Select the configuration file to create:",choices:H.map((q)=>({name:q.path,message:`${q.name} (${q.path})`}))});K=X}}else if(H.length===1)K=H[0].path;else if($.yes)K=z1.join(w1.homedir(),process.platform==="win32"?"_profile":".bashrc"),console.log(O.yellow(`Auto-selecting default config file: ${K} due to --yes flag`));else{let{enteredConfigPath:W}=await v({type:"input",name:"enteredConfigPath",message:"Enter the path to your shell configuration file:",initial:z1.join(w1.homedir(),".bashrc")});K=W}if(await L.addBinToPath(Q,K,J))console.log(O.green(`Added bin directory to PATH in ${K}`)),console.log(O.yellow("Please restart your terminal or run the following command:")),console.log(O.green(`source ${K}`));else console.log(O.red(`Failed to add bin directory to PATH in ${K}`)),console.log(O.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(O.green(L.getExportPathCommand(Q,J)))}else console.log(O.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(O.green(`export PATH="${J}:$PATH"`)),console.log(O.yellow("Or run:")),console.log(O.green("fbin path"))}else console.log(O.green("Bin directory is already in PATH."));console.log(O.green("Bin system setup completed successfully."))}catch(Y){console.error(O.red(`Failed to set up bin system: ${Y.message}`)),process.exit(1)}},T1={command:c1,describe:s1,builder:r1,handler:i1};import N1 from"node:path";import t1 from"node:fs";import A1 from"node:os";import A from"chalk";import u from"@fnet/prompt";var e1="path",a1="Add bin directory to PATH",$$={yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},Y$=async($)=>{try{let Y=await z($),J=L.getBinDirectory();if(console.log(A.blue(`Adding ${J} to PATH...`)),!L.createBinDirectoryStructure())console.log(A.yellow("Creating bin directory structure...")),await L.createBinDirectoryStructure();if(L.checkIfInPath(J)){console.log(A.green("Bin directory is already in PATH."));return}let Z=L.detectUserShell();if(Z==="unknown")if($.yes)Z=process.platform==="win32"?"powershell":"bash",console.log(A.yellow(`Auto-selecting ${Z} shell due to --yes flag`));else{let{selectedShell:G}=await u({type:"select",name:"selectedShell",message:"Select your shell:",choices:[{name:"bash",message:"Bash"},{name:"zsh",message:"Zsh"},{name:"fish",message:"Fish"},{name:"powershell",message:"PowerShell"},{name:"powershell-core",message:"PowerShell Core"},{name:"cmd",message:"Windows Command Prompt"},{name:"ksh",message:"Korn Shell (ksh)"},{name:"csh",message:"C Shell (csh/tcsh)"}]});Z=G}else if($.yes)console.log(A.yellow(`Auto-confirming detected shell: ${Z} due to --yes flag`));else{let{confirmShell:G}=await u({type:"confirm",name:"confirmShell",message:`Detected shell: ${Z}. Is this correct?`,initial:!0});if(!G){let{selectedShell:W}=await u({type:"select",name:"selectedShell",message:"Select your shell:",choices:[{name:"bash",message:"Bash"},{name:"zsh",message:"Zsh"},{name:"fish",message:"Fish"},{name:"powershell",message:"PowerShell"},{name:"powershell-core",message:"PowerShell Core"},{name:"cmd",message:"Windows Command Prompt"},{name:"ksh",message:"Korn Shell (ksh)"},{name:"csh",message:"C Shell (csh/tcsh)"}]});Z=W}}let Q=L.getAllShellConfigPaths(Z),H;if(Q.length>1){let G=Q.filter((W)=>t1.existsSync(W.path));if(G.length>0)if($.yes)H=G[0].path,console.log(A.yellow(`Auto-selecting config file: ${H} due to --yes flag`));else{let{selectedConfigPath:W}=await u({type:"select",name:"selectedConfigPath",message:"Select the configuration file to modify:",choices:G.map((X)=>({name:X.path,message:`${X.name} (${X.path})`}))});H=W}else if($.yes)H=Q[0].path,console.log(A.yellow(`Auto-selecting config file to create: ${H} due to --yes flag`));else{let{selectedConfigPath:W}=await u({type:"select",name:"selectedConfigPath",message:"Select the configuration file to create:",choices:Q.map((X)=>({name:X.path,message:`${X.name} (${X.path})`}))});H=W}}else if(Q.length===1)H=Q[0].path;else if($.yes)H=N1.join(A1.homedir(),process.platform==="win32"?"_profile":".bashrc"),console.log(A.yellow(`Auto-selecting default config file: ${H} due to --yes flag`));else{let{enteredConfigPath:G}=await u({type:"input",name:"enteredConfigPath",message:"Enter the path to your shell configuration file:",initial:N1.join(A1.homedir(),".bashrc")});H=G}if(await L.addBinToPath(Z,H,J))console.log(A.green(`Added bin directory to PATH in ${H}`)),console.log(A.yellow("Please restart your terminal or run the following command:")),console.log(A.green(`source ${H}`));else console.log(A.red(`Failed to add bin directory to PATH in ${H}`)),console.log(A.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(A.green(L.getExportPathCommand(Z,J)))}catch(Y){console.error(A.red(`Failed to add bin directory to PATH: ${Y.message}`)),process.exit(1)}},B1={command:e1,describe:a1,builder:$$,handler:Y$};import l from"node:path";import f from"node:fs";import x from"chalk";import q$ from"@fnet/prompt";var J$="compile [source] [options]",Q$="Compile a CLI project to a binary",X$={source:{describe:"Source file to compile",type:"string",default:"./dist/cli/esm/index.js"},output:{describe:"Output file name",type:"string",alias:"o"},name:{describe:"Binary name",type:"string",alias:"n"},force:{describe:"Force overwrite if binary already exists",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},target:{describe:"Target platform (auto, linux, macos, windows)",type:"string",choices:["auto","linux","macos","windows"],default:"auto"},minify:{describe:"Minify the output binary",type:"boolean",default:!0},external:{describe:"External packages to exclude from the bundle (comma-separated)",type:"string"}},Z$=async($)=>{try{let Y=await z($),J=process.cwd(),_=l.basename(J),Z=$.name||_,Q;if($.output)Q=$.output;else{let q=l.join(J,".bin");if(!f.existsSync(q))f.mkdirSync(q,{recursive:!0});Q=l.join(q,Z)}let H=l.resolve(process.cwd(),$.source);if(!f.existsSync(H))console.error(x.red(`Source file not found: ${H}`)),console.error(x.yellow("Make sure to build your project first.")),process.exit(1);if(f.existsSync(Q)&&!$.force&&!$.yes){let{confirmOverwrite:q}=await q$({type:"confirm",name:"confirmOverwrite",message:`Binary already exists at ${Q}. Overwrite?`,initial:!1});if(!q){console.log(x.yellow("Compilation cancelled."));return}}let K=process.platform;if(console.log(x.blue(`Detected platform: ${K}`)),K==="win32"&&!Q.endsWith(".exe"))Q=`${Q}.exe`,console.log(x.blue(`Adjusted output path for Windows: ${Q}`));console.log(x.blue(`Compiling ${H} to ${Q}...`));let{spawn:G}=await import("child_process");try{let q=G("bun",["--version"],{stdio:"pipe"});await new Promise((R,M)=>{q.on("close",(T)=>{if(T===0)R();else M(Error("Bun is not available. Please install Bun first."))}),q.on("error",(T)=>{M(Error(`Bun is not available: ${T.message}`))})})}catch(q){console.error(x.red(`Bun is not available: ${q.message}`)),console.error(x.yellow("Please install Bun first: https://bun.sh/")),process.exit(1)}let W=["build",H,"--compile",`--outfile=${Q}`];if($.target&&$.target!=="auto")W.push(`--target=${$.target}`);if($.minify===!1)W.push("--no-minify");if($.external)$.external.split(",").map((R)=>R.trim()).forEach((R)=>{W.push(`--external:${R}`)});console.log(x.blue(`Running: bun ${W.join(" ")}`));let X=G("bun",W,{stdio:"inherit"});if(await new Promise((q,R)=>{X.on("close",(M)=>{if(M===0)q();else R(Error(`Compilation failed with code ${M}`))}),X.on("error",(M)=>{R(M)})}),K!=="win32")f.chmodSync(Q,493);if(console.log(x.green(`Binary compiled successfully: ${Q}`)),K==="win32")console.log(x.yellow("Note: On Windows, you may need to run the binary from a command prompt or PowerShell."));else if(K==="darwin")console.log(x.yellow("Note: On macOS, you may need to allow the binary to run in System Preferences > Security & Privacy."))}catch(Y){console.error(x.red(`Failed to compile binary: ${Y.message}`)),process.exit(1)}},j1={command:J$,describe:Q$,builder:X$,handler:Z$};import n from"node:path";import C from"node:fs";import B from"chalk";import G$ from"@fnet/prompt";var _$="install [source] [options]",K$="Install a binary to the bin directory",H$={source:{describe:"Source binary to install",type:"string",demandOption:!0},name:{describe:"Name to use for the installed binary",type:"string",alias:"n"},force:{describe:"Force overwrite if binary already exists",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},symlink:{describe:"Create a symlink instead of copying the binary",type:"boolean",default:!1,alias:"s"}},W$=async($)=>{try{let Y=await z($),J=n.resolve(process.cwd(),$.source);if(!C.existsSync(J))console.error(B.red(`Source file not found: ${J}`)),process.exit(1);await L.createBinDirectoryStructure();let _=L.getBinDirectory(),Z;if($.name)Z=$.name;else Z=n.basename(J);if(process.platform==="win32"&&!Z.endsWith(".exe"))Z=`${Z}.exe`;let Q=n.join(_,Z);if(C.existsSync(Q)&&!$.force&&!$.yes){let{confirmOverwrite:X}=await G$({type:"confirm",name:"confirmOverwrite",message:`Binary already exists at ${Q}. Overwrite?`,initial:!1});if(!X){console.log(B.yellow("Installation cancelled."));return}}if($.symlink){if(console.log(B.blue(`Creating symlink from ${J} to ${Q}...`)),C.existsSync(Q))C.unlinkSync(Q);if(process.platform==="win32")C.symlinkSync(J,Q,"file");else C.symlinkSync(J,Q);console.log(B.green("Symlink created successfully."))}else if(console.log(B.blue(`Installing ${J} to ${Q}...`)),C.copyFileSync(J,Q),process.platform!=="win32")C.chmodSync(Q,493);let H=L.getMetadataFilePath(),K={binaries:{},lastUpdated:new Date().toISOString()};if(C.existsSync(H))try{K=JSON.parse(C.readFileSync(H,"utf8"))}catch(X){console.warn(B.yellow(`Failed to parse metadata file: ${X.message}`)),console.warn(B.yellow("Creating new metadata file."))}let G="0.0.0";try{let{execSync:X}=X1("child_process"),q=X(`"${Q}" --version`,{timeout:5000,stdio:["ignore","pipe","ignore"]}).toString().trim(),R=q.match(/v?(\d+\.\d+\.\d+)/);if(R)G=R[1],console.log(B.blue(`Detected binary version: ${G}`));else console.log(B.yellow(`Could not parse version from output: ${q}`)),console.log(B.yellow(`Using default version: ${G}`))}catch(X){console.log(B.yellow(`Could not detect binary version, using default: ${G}`))}if(K.binaries[Z]={path:Q,source:J,created:new Date().toISOString(),platform:process.platform,version:G,project:n.basename(process.cwd()),isSymlink:$.symlink||!1},K.lastUpdated=new Date().toISOString(),C.writeFileSync(H,JSON.stringify(K,null,2)),console.log(B.green(`Binary installed successfully: ${Q}`)),!L.checkIfInPath(_))console.log(B.yellow("Bin directory is not in PATH. Run 'fbin path' to add it."));else console.log(B.green(`You can now run '${Z}' from anywhere.`))}catch(Y){console.error(B.red(`Failed to install binary: ${Y.message}`)),process.exit(1)}},F1={command:_$,describe:K$,builder:H$,handler:W$};import P from"node:fs";import w from"chalk";import E$ from"@fnet/prompt";import c from"chalk";import x1 from"@fnet/prompt";async function L$($){let{items:Y,message:J,nameField:_="name",valueField:Z="name",initialValue:Q=null,allowAbort:H=!0}=$;if(!Y||Y.length===0)return console.log(c.yellow("No items available for selection.")),null;if(Y.length===1&&!H){let q=Y[0],R=typeof q==="string"?q:q[Z];return console.log(c.blue(`Only one option available: ${typeof q==="string"?q:q[_]}`)),R}let K=Y.map((q)=>{if(typeof q==="string")return{name:q,value:q,message:q};else return{name:q[Z],value:q[Z],message:q[_]||q[Z]}});if(H)K.push({name:"cancel",value:null,message:c.yellow("Cancel")});let G=null;if(Q){let q=K.findIndex((R)=>R.name===Q);if(q!==-1)G=q}let W="selectedItem",{[W]:X}=await x1({type:"select",name:W,message:J,choices:K,initial:G});if(X==="cancel")return null;return X}async function R$($){let{items:Y,message:J,nameField:_="name",valueField:Z="name",initialValues:Q=[],allowAbort:H=!0}=$;if(!Y||Y.length===0)return console.log(c.yellow("No items available for selection.")),null;let K=Y.map((q)=>{if(typeof q==="string")return{name:q,value:q,message:q};else return{name:q[Z],value:q[Z],message:q[_]||q[Z]}}),G=[];if(Q&&Q.length>0)G=K.map((q,R)=>Q.includes(q.name)?R:-1).filter((q)=>q!==-1);let W="selectedItems",X=await x1({type:"multiselect",name:W,message:J,choices:K,initial:G,hint:"(Use space to select, enter to confirm)",validate:(q)=>{if(q.length===0&&!H)return"Please select at least one item";return!0}});if(H&&X[W].length===0)return null;return X[W]}var s={promptForSelection:L$,promptForMultipleSelection:R$};var I$="uninstall [name] [options]",M$="Uninstall a binary from the bin directory",O$={name:{describe:"Name of the binary to uninstall",type:"string",demandOption:!1},force:{describe:"Skip confirmation prompt",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},U$=async($)=>{try{let Y=await z($),J=L.getBinDirectory(),_=L.getMetadataFilePath();if(!P.existsSync(J))console.error(w.red(`Bin directory not found: ${J}`)),console.error(w.yellow("Run fbin setup first.")),process.exit(1);if(!P.existsSync(_))console.error(w.red(`Metadata file not found: ${_}`)),console.error(w.yellow("Run fbin setup first.")),process.exit(1);let Z;try{Z=JSON.parse(P.readFileSync(_,"utf8"))}catch(K){console.error(w.red(`Failed to parse metadata file: ${K.message}`)),process.exit(1)}if(!$.name&&!$.yes){let K=Object.keys(Z.binaries);if(K.length===0){console.log(w.yellow("No binaries installed."));return}let G=await s.promptForSelection({items:K,message:"Select a binary to uninstall:",allowAbort:!0});if(G===null){console.log(w.yellow("Uninstallation cancelled."));return}$.name=G}let Q=$.name;if(!Q)console.error(w.red("Binary name is required.")),console.error(w.yellow("Use --name to specify a binary or run without --yes to select interactively.")),process.exit(1);if(!Z.binaries[Q])console.error(w.red(`Binary not found in metadata: ${Q}`)),console.log(w.yellow("Use fbin list to see installed binaries.")),process.exit(1);let H=Z.binaries[Q].path;if(!P.existsSync(H))console.warn(w.yellow(`Binary file not found: ${H}`)),console.warn(w.yellow("Metadata will be updated anyway."));if(!$.force&&!$.yes){let{confirmUninstall:K}=await E$({type:"confirm",name:"confirmUninstall",message:`Are you sure you want to uninstall ${Q}?`,initial:!1});if(!K){console.log(w.yellow("Uninstallation cancelled."));return}}if(P.existsSync(H))try{P.unlinkSync(H),console.log(w.green(`Binary file removed: ${H}`))}catch(K){console.error(w.red(`Failed to remove binary file: ${K.message}`))}delete Z.binaries[Q],Z.lastUpdated=new Date().toISOString(),P.writeFileSync(_,JSON.stringify(Z,null,2)),console.log(w.green(`Binary uninstalled successfully: ${Q}`))}catch(Y){console.error(w.red(`Failed to uninstall binary: ${Y.message}`)),process.exit(1)}},C1={command:I$,describe:M$,builder:O$,handler:U$};import a from"node:fs";import S from"chalk";import V$ from"cli-table3";import k from"chalk";function S1($,Y={}){let _={...{chars:{top:"─","top-mid":"─","top-left":" ","top-right":" ",bottom:"─","bottom-mid":"─","bottom-left":" ","bottom-right":" ",left:" ","left-mid":" ",mid:"─","mid-mid":"─",right:" ","right-mid":" ",middle:" "},style:{head:[],border:[],compact:!0},wordWrap:!0},...Y,head:$.map((Z)=>k.bold(Z))};return new V$(_)}function z$($,Y,J={}){let _=S1($,J);if(Array.isArray(Y))Y.forEach((Z)=>{_.push(Z)});return _.toString()}function w$($){switch($){case"running":return k.green;case"stopped":return k.yellow;case"failed":return k.red;case"registered":return k.blue;default:return k.gray}}var p={createTable:S1,createTableWithData:z$,getStatusColor:w$};var T$="list [options]",N$="List installed binaries",A$={json:{describe:"Output in JSON format",type:"boolean",default:!1,alias:"j"},filter:{describe:"Filter binaries by name",type:"string",alias:"f"}},B$=async($)=>{try{let Y=await z($),J=L.getBinDirectory(),_=L.getMetadataFilePath();if(!a.existsSync(J))console.error(S.red(`Bin directory not found: ${J}`)),console.error(S.yellow("Run fbin setup first.")),process.exit(1);if(!a.existsSync(_))console.error(S.red(`Metadata file not found: ${_}`)),console.error(S.yellow("Run fbin setup first.")),process.exit(1);let Z;try{Z=JSON.parse(a.readFileSync(_,"utf8"))}catch(X){console.error(S.red(`Failed to parse metadata file: ${X.message}`)),process.exit(1)}let Q=Z.binaries;if($.filter){let X=$.filter.toLowerCase();Q=Object.entries(Q).filter(([q])=>q.toLowerCase().includes(X)).reduce((q,[R,M])=>{return q[R]=M,q},{})}if($.json){console.log(JSON.stringify(Q,null,2));return}let H=Object.keys(Q).length;if(H===0){console.log(S.yellow("No binaries installed."));return}console.log(S.blue(`Found ${H} installed binaries:`)),console.log();let K=["NAME","VERSION","PLATFORM","CREATED"],G=p.createTable(K,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});if(Object.entries(Q).forEach(([X,q])=>{let R=new Date(q.created).toLocaleString();G.push([S.white(X),q.version||"N/A",q.platform||"N/A",R])}),console.log(G.toString()),console.log(),console.log(S.blue(`Bin directory: ${J}`)),!L.checkIfInPath(J))console.log(S.yellow("Bin directory is not in PATH. Run 'fbin path' to add it."))}catch(Y){console.error(S.red(`Failed to list binaries: ${Y.message}`)),process.exit(1)}},D1={command:T$,describe:N$,builder:A$,handler:B$};import $1 from"node:path";import d from"node:fs";import j from"chalk";var j$="backup [options]",F$="Backup shell configs and binaries",x$={config:{describe:"Backup shell configuration files",type:"boolean",default:!1,alias:"c"},binaries:{describe:"Backup installed binaries",type:"boolean",default:!1,alias:"b"},all:{describe:"Backup everything (configs + binaries)",type:"boolean",default:!1,alias:"a"},message:{describe:"Backup description message",type:"string",alias:"m"}},C$=async($)=>{try{let Y=await z($),J=$.all||!$.config&&!$.binaries,_=$.config||J,Z=$.binaries||J;console.log(j.blue("Creating backup..."));let Q=L.createBackupDirectory(),H=[];if(_){console.log(j.blue("Backing up shell configurations..."));let K=$1.join(Q,"configs");d.mkdirSync(K,{recursive:!0});let G=L.detectUserShell(),W=L.getAllShellConfigPaths(G),X=0;for(let q of W)if(d.existsSync(q.path)){if(L.backupFile(q.path,K,q.name))H.push(q.path),X++,console.log(j.green(` ✓ ${q.name}`))}if(X===0)console.log(j.yellow(" No configuration files found to backup"));else console.log(j.green(` Backed up ${X} configuration file(s)`))}if(Z){console.log(j.blue("Backing up binaries..."));let K=$1.join(Q,"binaries");d.mkdirSync(K,{recursive:!0});let G=L.getBinDirectory(),W=L.getMetadataFilePath();if(d.existsSync(W))L.backupFile(W,K,"metadata.json"),H.push(W);if(d.existsSync(G)){let X=d.readdirSync(G),q=0;for(let R of X){let M=$1.join(G,R);if(d.statSync(M).isFile()){if(L.backupFile(M,K,R))H.push(M),q++,console.log(j.green(` ✓ ${R}`))}}if(q===0)console.log(j.yellow(" No binaries found to backup"));else console.log(j.green(` Backed up ${q} binary(ies)`))}else console.log(j.yellow(" Bin directory not found"))}if(L.createBackupMetadata(Q,{type:"manual",command:"fbin backup",message:$.message||"Manual backup",files:H,config:_,binaries:Z}),L.updateLatestSymlink(Q),console.log(),console.log(j.green("✓ Backup created successfully!")),console.log(j.blue(` Location: ${Q}`)),console.log(j.blue(` Files backed up: ${H.length}`)),$.message)console.log(j.blue(` Message: ${$.message}`))}catch(Y){console.error(j.red(`Failed to create backup: ${Y.message}`)),process.exit(1)}},y1={command:j$,describe:F$,builder:x$,handler:C$};import m from"node:path";import F from"node:fs";import V from"chalk";import S$ from"@fnet/prompt";var D$="restore [options]",y$="Restore from backup",v$={config:{describe:"Restore shell configuration files",type:"boolean",default:!1,alias:"c"},binaries:{describe:"Restore installed binaries",type:"boolean",default:!1,alias:"b"},all:{describe:"Restore everything (configs + binaries)",type:"boolean",default:!1,alias:"a"},list:{describe:"List available backups",type:"boolean",default:!1,alias:"l"},timestamp:{describe:"Backup timestamp to restore (defaults to latest)",type:"string",alias:"t"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},P$=async($)=>{try{let Y=await z($);if($.list){let G=L.listBackups();if(G.length===0){console.log(V.yellow("No backups found."));return}console.log(V.blue(`Found ${G.length} backup(s):
15
+ `));let W=["TIMESTAMP","TYPE","MESSAGE","FILES"],X=p.createTable(W,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});for(let q of G){let R=q.timestamp||"unknown",M=q.type||"manual",T=q.message||"",N=q.files?q.files.length:0;X.push([V.white(R),M,T.substring(0,40)+(T.length>40?"...":""),N.toString()])}console.log(X.toString()),console.log(),console.log(V.blue(`Backup directory: ${L.getBackupDirectory()}`));return}let J=L.listBackups();if(J.length===0){console.log(V.yellow("No backups found.")),console.log(V.blue("Create a backup first with: fbin backup"));return}let _;if($.timestamp){if(_=J.find((G)=>G.timestamp===$.timestamp),!_)console.error(V.red(`Backup not found: ${$.timestamp}`)),console.log(V.yellow("Use --list to see available backups")),process.exit(1)}else if($.yes)_=J[0],console.log(V.yellow(`Auto-selecting latest backup: ${_.timestamp}`));else{let G=J.map((X)=>({name:X.timestamp,message:`${X.timestamp} - ${X.message||"No message"} (${X.files?.length||0} files)`})),W=await s.promptForSelection({items:G.map((X)=>X.name),message:"Select a backup to restore:",allowAbort:!0});if(W===null){console.log(V.yellow("Restore cancelled."));return}_=J.find((X)=>X.timestamp===W)}console.log(V.blue(`Restoring from backup: ${_.timestamp}`));let Z=$.all||!$.config&&!$.binaries,Q=$.config||Z,H=$.binaries||Z;if(!$.yes){let{confirmRestore:G}=await S$({type:"confirm",name:"confirmRestore",message:"This will overwrite current files. Continue?",initial:!1});if(!G){console.log(V.yellow("Restore cancelled."));return}}let K=0;if(Q){let G=m.join(_.path,"configs");if(F.existsSync(G)){console.log(V.blue("Restoring shell configurations..."));let W=F.readdirSync(G);for(let X of W){let q=m.join(G,X),R=L.detectUserShell(),T=L.getAllShellConfigPaths(R).find((N)=>N.name===X);if(T){let N=T.path,b=m.dirname(N);if(!F.existsSync(b))F.mkdirSync(b,{recursive:!0});F.copyFileSync(q,N),console.log(V.green(` ✓ ${X}`)),K++}}}}if(H){let G=m.join(_.path,"binaries");if(F.existsSync(G)){console.log(V.blue("Restoring binaries..."));let W=L.getBinDirectory();if(!F.existsSync(W))F.mkdirSync(W,{recursive:!0});let X=F.readdirSync(G);for(let q of X){let R=m.join(G,q),M=m.join(W,q);if(q==="metadata.json"){let T=L.getMetadataFilePath(),N=m.dirname(T);if(!F.existsSync(N))F.mkdirSync(N,{recursive:!0});F.copyFileSync(R,T),console.log(V.green(" ✓ metadata.json")),K++;continue}if(F.copyFileSync(R,M),process.platform!=="win32")F.chmodSync(M,493);console.log(V.green(` ✓ ${q}`)),K++}}}console.log(),console.log(V.green("✓ Restore completed successfully!")),console.log(V.blue(` Files restored: ${K}`))}catch(Y){console.error(V.red(`Failed to restore backup: ${Y.message}`)),process.exit(1)}},v1={command:D$,describe:y$,builder:v$,handler:P$};import d$ from"node:path";import Y1 from"node:fs";import U from"chalk";import m$ from"@fnet/prompt";var u$="cleanup [options]",k$="Clean up old backups",p$={keep:{describe:"Number of recent backups to keep",type:"number",default:10,alias:"k"},older:{describe:"Remove backups older than N days",type:"number",alias:"o"},all:{describe:"Remove all backups",type:"boolean",default:!1,alias:"a"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},"dry-run":{describe:"Show what would be deleted without actually deleting",type:"boolean",default:!1,alias:"d"}},f$=async($)=>{try{let Y=await z($),J=L.listBackups();if(J.length===0){console.log(U.yellow("No backups found."));return}console.log(U.blue(`Found ${J.length} backup(s)`));let _=[];if($.all)_=J;else if($.older){let X=new Date;X.setDate(X.getDate()-$.older),_=J.filter((q)=>{return new Date(q.created)<X}),console.log(U.blue(`Removing backups older than ${$.older} days (before ${X.toLocaleDateString()})`))}else if(J.length>$.keep)_=J.slice($.keep),console.log(U.blue(`Keeping ${$.keep} most recent backup(s), removing ${_.length} old backup(s)`));else{console.log(U.green(`Only ${J.length} backup(s) found, keeping all (limit: ${$.keep})`));return}if(_.length===0){console.log(U.green("No backups to delete."));return}console.log(),console.log(U.yellow(`Backups to be deleted (${_.length}):`)),console.log();let Z=["TIMESTAMP","TYPE","MESSAGE","FILES","SIZE"],Q=p.createTable(Z,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}}),H=0;for(let X of _){let q=X.timestamp||"unknown",R=X.type||"manual",M=X.message||"",T=X.files?X.files.length:0,N=0;try{let i=(q1)=>{let t=0,u1=Y1.readdirSync(q1);for(let k1 of u1){let J1=d$.join(q1,k1),Q1=Y1.statSync(J1);if(Q1.isDirectory())t+=i(J1);else t+=Q1.size}return t};N=i(X.path),H+=N}catch(i){}let b=N>0?`${(N/1024/1024).toFixed(2)} MB`:"N/A";Q.push([U.white(q),R,M.substring(0,30)+(M.length>30?"...":""),T.toString(),b])}if(console.log(Q.toString()),console.log(),console.log(U.blue(`Total size to free: ${(H/1024/1024).toFixed(2)} MB`)),$["dry-run"]){console.log(),console.log(U.yellow("DRY RUN: No backups were deleted.")),console.log(U.blue("Run without --dry-run to actually delete these backups."));return}if(!$.yes){console.log();let{confirmDelete:X}=await m$({type:"confirm",name:"confirmDelete",message:`Delete ${_.length} backup(s)?`,initial:!1});if(!X){console.log(U.yellow("Cleanup cancelled."));return}}console.log(),console.log(U.blue("Deleting backups..."));let K=0,G=0;for(let X of _)try{Y1.rmSync(X.path,{recursive:!0,force:!0}),console.log(U.green(` ✓ ${X.timestamp}`)),K++}catch(q){console.log(U.red(` ✗ ${X.timestamp}: ${q.message}`)),G++}if(console.log(),console.log(U.green("✓ Cleanup completed!")),console.log(U.blue(` Deleted: ${K}`)),G>0)console.log(U.yellow(` Failed: ${G}`));console.log(U.blue(` Space freed: ${(H/1024/1024).toFixed(2)} MB`));let W=L.listBackups();console.log(U.blue(` Remaining backups: ${W.length}`))}catch(Y){console.error(U.red(`Failed to cleanup backups: ${Y.message}`)),process.exit(1)}},P1={command:u$,describe:k$,builder:p$,handler:f$};import{promisify as b$}from"node:util";import g$ from"tree-kill";var F0=b$(g$),r=!1;function d1(){process.on("uncaughtException",($)=>{if(!r)r=!0,setTimeout(()=>process.exit(1),500)}),process.on("unhandledRejection",($)=>{if(!r)r=!0,setTimeout(()=>process.exit(1),500)})}d1();M1();async function l$(){try{let $=h$(o$(process.argv)).usage("Usage: $0 <command> [options]").command(T1).command(B1).command(j1).command(F1).command(C1).command(D1).command(y1).command(v1).command(P1).demandCommand(1,"You need to specify a command").help().version().argv}catch($){console.error(m1.red(`Fatal error: ${$.message}`)),process.exit(1)}}l$().catch(($)=>{console.error(m1.red(`Fatal error: ${$.message}`)),process.exit(1)});