@fnet/cli 0.132.0 → 0.133.1
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.
- package/dist/fbin/index.js +14 -1
- package/dist/fnet/index.0jcm9pn5.js +1 -0
- package/dist/fnet/index.2084z2ed.js +2 -0
- package/dist/fnet/index.33f1ggpr.js +1 -0
- package/dist/fnet/index.3exge2js.js +1 -0
- package/dist/fnet/index.3kfx538h.js +1 -0
- package/dist/fnet/index.490y87nc.js +1 -0
- package/dist/fnet/index.4g9yezkq.js +1 -0
- package/dist/fnet/index.4jkat7r4.js +1 -0
- package/dist/fnet/index.7crx8ky1.js +1 -0
- package/dist/fnet/index.7vw06nrn.js +1 -0
- package/dist/fnet/index.9567fa9x.js +1 -0
- package/dist/fnet/index.gh75wt1m.js +1 -0
- package/dist/fnet/index.hzsfswvp.js +1 -0
- package/dist/fnet/index.jgpc3grc.js +1 -0
- package/dist/fnet/index.js +19 -1
- package/dist/fnet/index.p0zb7e1b.js +1 -0
- package/dist/fnet/index.r19p3bpa.js +2 -0
- package/dist/fnet/index.r82rtnmz.js +1 -0
- package/dist/fnet/index.s662t98v.js +1 -0
- package/dist/fnet/index.w74dpnpn.js +1 -0
- package/dist/fnet/index.xeaw5xa9.js +1 -0
- package/dist/fnet/index.zm4kesg6.js +1 -0
- package/dist/fnode/index.05n3mvs9.js +2 -0
- package/dist/fnode/index.2hc9tbyx.js +1 -0
- package/dist/fnode/index.2pnjg6dc.js +1 -0
- package/dist/fnode/index.9qgtmxq3.js +2 -0
- package/dist/fnode/index.b1q7y05p.js +1 -0
- package/dist/fnode/index.bhapgrs7.js +1 -0
- package/dist/fnode/index.cvxrf34y.js +2 -0
- package/dist/fnode/index.dp9wyahp.js +1 -0
- package/dist/fnode/index.eqxmcpdc.js +1 -0
- package/dist/fnode/index.f2tb0x3t.js +1 -0
- package/dist/fnode/index.fbzv6wwf.js +1 -0
- package/dist/fnode/index.gazd9raq.js +1 -0
- package/dist/fnode/index.hv4s25f0.js +3 -0
- package/dist/fnode/index.j5z7dtsx.js +1 -0
- package/dist/fnode/index.js +9 -1
- package/dist/fnode/index.kb4e4bxf.js +1 -0
- package/dist/fnode/index.qn0schqp.js +1 -0
- package/dist/fnode/index.rht29phd.js +1 -0
- package/dist/fnode/index.rzsfmek6.js +3 -0
- package/dist/fnode/index.s0nk6cv8.js +4 -0
- package/dist/fnode/index.s66v6wt4.js +1 -0
- package/dist/fnode/index.sv7v0y60.js +1 -0
- package/dist/fnode/index.tgkhgnrp.js +1 -0
- package/dist/fnode/index.vq706f75.js +1 -0
- package/dist/fnode/index.y8pvdcny.js +1 -0
- package/dist/fnode/index.z4vz93ww.js +1 -0
- package/dist/frun/index.js +1 -1
- package/dist/fservice/index.js +18 -1
- package/dist/fservice/index.q01yvaz0.js +2 -0
- package/package.json +21 -18
- package/readme.md +62 -15
- package/template/fnet/core/object.js +10 -10
- package/template/fnet/node/package.json.njk +6 -3
- package/template/fnet/node/src/cli/index.js.njk +5 -315
- package/template/fnet/node/src/cli/index.js.v1.njk +318 -0
- package/template/fnet/node/src/cli/v2/core/args-parser.njk +10 -0
- package/template/fnet/node/src/cli/v2/core/imports.njk +31 -0
- package/template/fnet/node/src/cli/v2/core/run-wrapper.njk +25 -0
- package/template/fnet/node/src/cli/v2/index.js.njk +184 -0
- package/template/fnet/node/src/cli/v2/modes/default/extend.njk +11 -0
- package/template/fnet/node/src/cli/v2/modes/default/standard.njk +20 -0
- package/template/fnet/node/src/cli/v2/modes/http/builtin.njk +66 -0
- package/template/fnet/node/src/cli/v2/modes/http/imports.njk +9 -0
- package/template/fnet/node/src/cli/v2/modes/http/index.njk +12 -0
- package/template/fnet/node/src/cli/v2/modes/mcp/imports.njk +33 -0
- package/template/fnet/node/src/cli/v2/modes/mcp/index.njk +30 -0
- package/template/fnet/node/src/cli/v2/modes/mcp/server-setup.njk +15 -0
- package/template/fnet/node/src/cli/v2/modes/mcp/tool-handlers.njk +46 -0
- package/template/fnet/node/src/cli/v2/modes/mcp/transport-http.njk +222 -0
- package/template/fnet/node/src/cli/v2/modes/mcp/transport-stdio.njk +9 -0
- package/template/fnet/node/src/cli/v2/modes/pipeline/imports.njk +9 -0
- package/template/fnet/node/src/cli/v2/modes/pipeline/index.njk +113 -0
- package/template/fnet/node/src/cli/v2/modes/webhook/imports.njk +9 -0
- package/template/fnet/node/src/cli/v2/modes/webhook/index.njk +127 -0
- package/template/fnet/node/src/cli/v2/modes/websocket/imports.njk +15 -0
- package/template/fnet/node/src/cli/v2/modes/websocket/index.njk +104 -0
- package/template/fnet/node/src/default/blocks/assign.js.njk +10 -48
- package/template/fnet/node/src/default/blocks/call.js.njk +110 -156
- package/template/fnet/node/src/default/blocks/for.js.njk +58 -74
- package/template/fnet/node/src/default/blocks/form.js.njk +21 -59
- package/template/fnet/node/src/default/blocks/http.js.njk +135 -0
- package/template/fnet/node/src/default/blocks/modules.js.njk +10 -52
- package/template/fnet/node/src/default/blocks/new.js.njk +40 -85
- package/template/fnet/node/src/default/blocks/next.js.njk +10 -32
- package/template/fnet/node/src/default/blocks/output.js.njk +10 -48
- package/template/fnet/node/src/default/blocks/parallel.js.njk +64 -0
- package/template/fnet/node/src/default/blocks/pipeline.js.njk +109 -0
- package/template/fnet/node/src/default/blocks/raise.js.njk +9 -25
- package/template/fnet/node/src/default/blocks/retry.js.njk +70 -0
- package/template/fnet/node/src/default/blocks/return.js.njk +13 -25
- package/template/fnet/node/src/default/blocks/schedule.js.njk +66 -0
- package/template/fnet/node/src/default/blocks/signal.js.njk +10 -32
- package/template/fnet/node/src/default/blocks/steps.js.njk +32 -48
- package/template/fnet/node/src/default/blocks/switch.js.njk +37 -67
- package/template/fnet/node/src/default/blocks/tryexcept.js.njk +58 -52
- package/template/fnet/node/src/default/blocks/wait.js.njk +10 -30
- package/template/fnet/node/src/default/input.args.js.njk +5 -2
- package/template/fnet/node/src/default/macros/block-body-header.js.njk +1 -1
- package/template/fnet/node/src/default/macros/block-header.js.njk +0 -3
- package/template/fnet/node/src/default/macros/block-next.js.njk +1 -1
- package/template/fnet/node/src/default/macros/block-run-footer.js.njk +1 -1
- package/template/fnet/node/src/default/macros/block-run-header.js.njk +14 -2
- package/template/fnet/node/src/default/macros/page.js.njk +1 -1
- package/template/fnet/node/src/default/types/block.js.njk +133 -0
- package/template/fnet/node/src/default/workflow.js.njk +8 -6
- package/template/fnode/node/package.json.njk +5 -4
- package/template/fnode/node/src/cli/index.js.njk +3 -397
- package/template/fnode/node/src/cli/index.js.v1.njk +464 -0
- package/template/fnode/node/src/cli/v2/core/args-parser.njk +10 -0
- package/template/fnode/node/src/cli/v2/core/imports.njk +29 -0
- package/template/fnode/node/src/cli/v2/core/run-wrapper.njk +25 -0
- package/template/fnode/node/src/cli/v2/index.js.njk +184 -0
- package/template/fnode/node/src/cli/v2/modes/default/extend.njk +11 -0
- package/template/fnode/node/src/cli/v2/modes/default/standard.njk +19 -0
- package/template/fnode/node/src/cli/v2/modes/http/builtin.njk +61 -0
- package/template/fnode/node/src/cli/v2/modes/http/imports.njk +9 -0
- package/template/fnode/node/src/cli/v2/modes/http/index.njk +12 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/imports.njk +33 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/index.njk +30 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/server-setup.njk +15 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/tool-handlers.njk +41 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/transport-http.njk +212 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/transport-stdio.njk +9 -0
- package/template/fnode/node/src/cli/v2/modes/pipeline/imports.njk +9 -0
- package/template/fnode/node/src/cli/v2/modes/pipeline/index.njk +103 -0
- package/template/fnode/node/src/cli/v2/modes/webhook/imports.njk +9 -0
- package/template/fnode/node/src/cli/v2/modes/webhook/index.njk +122 -0
- package/template/fnode/node/src/cli/v2/modes/websocket/imports.njk +15 -0
- package/template/fnode/node/src/cli/v2/modes/websocket/index.njk +99 -0
- package/template/fnode/node/src/default/input.args.js.njk +6 -2
- package/dist/fnet/index.-SGbq2cI.js +0 -1
- package/dist/fnet/index.B5XE4ChJ.js +0 -1
- package/dist/fnet/index.Bft2w7m3.js +0 -1
- package/dist/fnet/index.BuYxdKtK.js +0 -1
- package/dist/fnet/index.C0YpfQ5j.js +0 -1
- package/dist/fnet/index.C2S9JYhS.js +0 -1
- package/dist/fnet/index.C7saWH6d.js +0 -1
- package/dist/fnet/index.CDct_kkF.js +0 -1
- package/dist/fnet/index.CMC8mlye.js +0 -1
- package/dist/fnet/index.CmMM-Ek9.js +0 -1
- package/dist/fnet/index.CuMyez3E.js +0 -1
- package/dist/fnet/index.CzAV0S36.js +0 -1
- package/dist/fnet/index.D2N9YZmA.js +0 -1
- package/dist/fnet/index.D3p7pncT.js +0 -1
- package/dist/fnet/index.DG8TqL-1.js +0 -1
- package/dist/fnet/index.DI3yyTtl.js +0 -1
- package/dist/fnet/index.DOYkqsYT.js +0 -1
- package/dist/fnet/index.DWpw12No.js +0 -1
- package/dist/fnet/index.DrwlOzAe.js +0 -1
- package/dist/fnet/index.Q-CYRcna.js +0 -1
- package/dist/fnet/index.W6RYgypK.js +0 -1
- package/dist/fnet/index.xd8c7XMr.js +0 -1
- package/dist/fnode/index.-SGbq2cI.js +0 -1
- package/dist/fnode/index.B5XE4ChJ.js +0 -1
- package/dist/fnode/index.BTXKZRR5.js +0 -1
- package/dist/fnode/index.Bft2w7m3.js +0 -1
- package/dist/fnode/index.BpWyDwfw.js +0 -1
- package/dist/fnode/index.BuYxdKtK.js +0 -1
- package/dist/fnode/index.C2S9JYhS.js +0 -1
- package/dist/fnode/index.C7saWH6d.js +0 -1
- package/dist/fnode/index.CDct_kkF.js +0 -1
- package/dist/fnode/index.CMC8mlye.js +0 -1
- package/dist/fnode/index.CmMM-Ek9.js +0 -1
- package/dist/fnode/index.CuMyez3E.js +0 -1
- package/dist/fnode/index.CzAV0S36.js +0 -1
- package/dist/fnode/index.D2N9YZmA.js +0 -1
- package/dist/fnode/index.D3p7pncT.js +0 -1
- package/dist/fnode/index.DG8TqL-1.js +0 -1
- package/dist/fnode/index.DI3yyTtl.js +0 -1
- package/dist/fnode/index.DWpw12No.js +0 -1
- package/dist/fnode/index.DrwlOzAe.js +0 -1
- package/dist/fnode/index.N_a5FdgA.js +0 -1
- package/dist/fnode/index.Q-CYRcna.js +0 -1
- package/dist/fnode/index.UNoFg95r.js +0 -1
- package/dist/fnode/index.W6RYgypK.js +0 -1
- package/dist/fnode/index.e2SSlEgE.js +0 -1
- package/dist/fnode/index.xd8c7XMr.js +0 -1
- package/template/fnet/core/print.js +0 -1
- package/template/fnet/node/src/default/macros/workflow-header.js.njk +0 -7
package/dist/fbin/index.js
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e from"chalk";import o from"yargs";import{hideBin as t}from"yargs/helpers";import s from"node:path";import n from"node:fs";import l from"node:os";import i from"@fnet/prompt";import{fileURLToPath as a}from"node:url";import r from"cli-table3";import{promisify as c}from"node:util";import d from"tree-kill";function m(){return s.join(l.homedir(),".fnet","bin")}function u(){return s.join(l.homedir(),".fnet","metadata")}function g(){return s.join(u(),"binaries.json")}function p(){try{if("win32"===process.platform)return process.env.PSModulePath&&process.env.PSModulePath.includes("PowerShell")?"powershell-core":process.env.PSModulePath?"powershell":"cmd";const e=process.env.SHELL||"";return e.includes("bash")?"bash":e.includes("zsh")?"zsh":e.includes("fish")?"fish":e.includes("ksh")?"ksh":e.includes("csh")||e.includes("tcsh")?"csh":n.existsSync(s.join(l.homedir(),".bashrc"))?"bash":n.existsSync(s.join(l.homedir(),".zshrc"))?"zsh":n.existsSync(s.join(l.homedir(),".config","fish","config.fish"))?"fish":"unknown"}catch(e){return"unknown"}}function f(e){const o=l.homedir(),t=[];switch(e){case"bash":t.push({name:".bashrc",path:s.join(o,".bashrc")}),t.push({name:".bash_profile",path:s.join(o,".bash_profile")}),t.push({name:".profile",path:s.join(o,".profile")});break;case"zsh":t.push({name:".zshrc",path:s.join(o,".zshrc")}),t.push({name:".zprofile",path:s.join(o,".zprofile")});break;case"fish":t.push({name:"config.fish",path:s.join(o,".config","fish","config.fish")});break;case"ksh":t.push({name:".kshrc",path:s.join(o,".kshrc")}),t.push({name:".profile",path:s.join(o,".profile")});break;case"csh":t.push({name:".cshrc",path:s.join(o,".cshrc")}),t.push({name:".tcshrc",path:s.join(o,".tcshrc")});break;case"powershell":t.push({name:"Microsoft.PowerShell_profile.ps1",path:s.join(o,"Documents","WindowsPowerShell","Microsoft.PowerShell_profile.ps1")}),t.push({name:"profile.ps1",path:s.join(o,"Documents","WindowsPowerShell","profile.ps1")});break;case"powershell-core":t.push({name:"Microsoft.PowerShell_profile.ps1",path:s.join(o,"Documents","PowerShell","Microsoft.PowerShell_profile.ps1")}),t.push({name:"profile.ps1",path:s.join(o,"Documents","PowerShell","profile.ps1")});break;case"cmd":t.push({name:"fnet-path.bat",path:s.join(o,"fnet-path.bat")})}return t}function h(e,o){switch(e){case"bash":case"zsh":case"ksh":default:return`export PATH="${o}:$PATH"`;case"fish":return`set -gx PATH ${o} $PATH`;case"csh":return`setenv PATH ${o}:$PATH`;case"powershell":case"powershell-core":return`$env:PATH = "${o};" + $env:PATH`;case"cmd":return`@echo off\nSETX PATH "%PATH%;${o}"\necho Path updated successfully`}}function y(){return s.join(l.homedir(),".fnet","backups")}function b(){const e=(new Date).toISOString().replace(/:/g,"-").replace(/\..+/,""),o=s.join(y(),e);return n.existsSync(o)||n.mkdirSync(o,{recursive:!0}),o}function w(o,t,l=null){try{if(!n.existsSync(o))return!1;const e=l||s.basename(o),i=s.join(t,e),a=s.dirname(i);return n.existsSync(a)||n.mkdirSync(a,{recursive:!0}),n.copyFileSync(o,i),!0}catch(t){return console.error(e.red(`Failed to backup file ${o}: ${t.message}`)),!1}}function S(e,o={}){const t={timestamp:(new Date).toISOString(),type:o.type||"manual",message:o.message||"",command:o.command||"",files:o.files||[],...o},l=s.join(e,"metadata.json");n.writeFileSync(l,JSON.stringify(t,null,2))}function $(o){const t=s.join(y(),"latest");try{n.existsSync(t)&&n.unlinkSync(t),"win32"===process.platform?n.writeFileSync(t+".txt",o):n.symlinkSync(o,t)}catch(o){console.warn(e.yellow(`Could not create latest symlink: ${o.message}`))}}var k={getBinDirectory:m,getMetadataDirectory:u,getMetadataFilePath:g,checkIfInPath:function(e){return(process.env.PATH||"").split(s.delimiter).includes(e)},detectUserShell:p,getShellConfigPath:function(){const e=f(p());for(const o of e)if(n.existsSync(o.path))return o.path;return e.length>0?e[0].path:null},getAllShellConfigPaths:f,createBinDirectoryStructure:async function(){const e=m(),o=u(),t=g();n.existsSync(e)||n.mkdirSync(e,{recursive:!0}),n.existsSync(o)||n.mkdirSync(o,{recursive:!0}),n.existsSync(t)||n.writeFileSync(t,JSON.stringify({binaries:{},lastUpdated:(new Date).toISOString()},null,2))},getExportPathCommand:h,addBinToPath:async function(o,t,l,i={}){try{const{autoBackup:a=!0}=i,r=h(o,l);if("cmd"===o)return n.writeFileSync(t,r),console.log(e.yellow(`Created batch file at ${t}`)),console.log(e.yellow("Run this file to add the bin directory to your PATH")),!0;if("powershell"!==o&&"powershell-core"!==o||n.existsSync(s.dirname(t))||n.mkdirSync(s.dirname(t),{recursive:!0}),!n.existsSync(t)){const s="fish"===o?"# Fish shell configuration\n\n":"powershell"===o||"powershell-core"===o?"# PowerShell profile\n\n":"# Shell configuration\n\n";n.writeFileSync(t,s),console.log(e.green(`Created config file at ${t}`))}const c=n.readFileSync(t,"utf8");if(c.includes(l))return!0;if(a&&n.existsSync(t)){const o=b(),n=s.basename(t);w(t,s.join(o,"configs"),n)&&(S(o,{type:"auto",command:"addBinToPath",message:`Automatic backup before modifying ${n}`,files:[t]}),$(o),console.log(e.green(`✓ Backed up ${n} to ${o}`)))}const d=`${c.trim()}\n\n# Added by @fnet/cli\n${r}\n`;return n.writeFileSync(t,d),"powershell"!==o&&"powershell-core"!==o||(console.log(e.yellow("You may need to set the PowerShell execution policy to run scripts:")),console.log(e.green("Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned"))),!0}catch(o){return console.error(e.red(`Failed to add bin directory to PATH: ${o.message}`)),!1}},getBackupDirectory:y,createBackupDirectory:b,backupFile:w,createBackupMetadata:S,listBackups:function(){const e=y();if(!n.existsSync(e))return[];const o=[],t=n.readdirSync(e);for(const l of t){const t=s.join(e,l),i=n.statSync(t);if(i.isDirectory()&&"latest"!==l){const e=s.join(t,"metadata.json");let a={};if(n.existsSync(e))try{a=JSON.parse(n.readFileSync(e,"utf8"))}catch(e){}o.push({timestamp:l,path:t,created:i.mtime,...a})}}return o.sort(((e,o)=>new Date(o.created)-new Date(e.created))),o},updateLatestSymlink:$};async function P(e){const o=function(){const e=l.homedir(),o=s.join(e,".fnet","bin");return n.existsSync(o)||n.mkdirSync(o,{recursive:!0}),o}(),t=function(){const e=l.homedir(),o=s.join(e,".fnet");return n.existsSync(o)||n.mkdirSync(o,{recursive:!0}),s.join(o,"bin-registry.json")}();let i={};if(n.existsSync(t))try{const e=n.readFileSync(t,"utf8");i=JSON.parse(e)}catch(e){console.warn(`Warning: Could not parse bin registry: ${e.message}`)}return{binDir:o,registryPath:t,registry:i,args:e}}s.dirname(a(import.meta.url));var v={command:"setup",describe:"Initialize the bin system",builder:{yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},handler:async o=>{try{await P(o);console.log(e.blue("Setting up the bin system...")),await k.createBinDirectoryStructure();const t=k.getBinDirectory();console.log(e.green(`Bin directory: ${t}`));if(k.checkIfInPath(t))console.log(e.green("Bin directory is already in PATH."));else{console.log(e.yellow("Bin directory is not in PATH."));let a=o.yes;if(o.yes)console.log(e.yellow("Auto-confirming to add bin directory to PATH due to --yes flag"));else{a=(await i({type:"confirm",name:"confirmAddToPath",message:`Would you like to add ${t} to your PATH?`,initial:!0})).confirmAddToPath}if(a){let a=k.detectUserShell();if("unknown"===a)if(o.yes)a="win32"===process.platform?"powershell":"bash",console.log(e.yellow(`Auto-selecting ${a} shell due to --yes flag`));else{const{selectedShell:e}=await i({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)"}]});a=e}else if(o.yes)console.log(e.yellow(`Auto-confirming detected shell: ${a} due to --yes flag`));else{const{confirmShell:e}=await i({type:"confirm",name:"confirmShell",message:`Detected shell: ${a}. Is this correct?`,initial:!0});if(!e){const{selectedShell:e}=await i({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)"}]});a=e}}const r=k.getAllShellConfigPaths(a);let c;if(r.length>1){const t=r.filter((e=>n.existsSync(e.path)));if(t.length>0)if(o.yes)c=t[0].path,console.log(e.yellow(`Auto-selecting config file: ${c} due to --yes flag`));else{const{selectedConfigPath:e}=await i({type:"select",name:"selectedConfigPath",message:"Select the configuration file to modify:",choices:t.map((e=>({name:e.path,message:`${e.name} (${e.path})`})))});c=e}else if(o.yes)c=r[0].path,console.log(e.yellow(`Auto-selecting config file to create: ${c} due to --yes flag`));else{const{selectedConfigPath:e}=await i({type:"select",name:"selectedConfigPath",message:"Select the configuration file to create:",choices:r.map((e=>({name:e.path,message:`${e.name} (${e.path})`})))});c=e}}else if(1===r.length)c=r[0].path;else if(o.yes)c=s.join(l.homedir(),"win32"===process.platform?"_profile":".bashrc"),console.log(e.yellow(`Auto-selecting default config file: ${c} due to --yes flag`));else{const{enteredConfigPath:e}=await i({type:"input",name:"enteredConfigPath",message:"Enter the path to your shell configuration file:",initial:s.join(l.homedir(),".bashrc")});c=e}await k.addBinToPath(a,c,t)?(console.log(e.green(`Added bin directory to PATH in ${c}`)),console.log(e.yellow("Please restart your terminal or run the following command:")),console.log(e.green(`source ${c}`))):(console.log(e.red(`Failed to add bin directory to PATH in ${c}`)),console.log(e.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(e.green(k.getExportPathCommand(a,t))))}else console.log(e.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(e.green(`export PATH="${t}:$PATH"`)),console.log(e.yellow("Or run:")),console.log(e.green("fbin path"))}console.log(e.green("Bin system setup completed successfully."))}catch(o){console.error(e.red(`Failed to set up bin system: ${o.message}`)),process.exit(1)}}};var x={command:"path",describe:"Add bin directory to PATH",builder:{yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},handler:async o=>{try{await P(o);const t=k.getBinDirectory();console.log(e.blue(`Adding ${t} to PATH...`)),k.createBinDirectoryStructure()||(console.log(e.yellow("Creating bin directory structure...")),await k.createBinDirectoryStructure());if(k.checkIfInPath(t))return void console.log(e.green("Bin directory is already in PATH."));let a=k.detectUserShell();if("unknown"===a)if(o.yes)a="win32"===process.platform?"powershell":"bash",console.log(e.yellow(`Auto-selecting ${a} shell due to --yes flag`));else{const{selectedShell:e}=await i({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)"}]});a=e}else if(o.yes)console.log(e.yellow(`Auto-confirming detected shell: ${a} due to --yes flag`));else{const{confirmShell:e}=await i({type:"confirm",name:"confirmShell",message:`Detected shell: ${a}. Is this correct?`,initial:!0});if(!e){const{selectedShell:e}=await i({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)"}]});a=e}}const r=k.getAllShellConfigPaths(a);let c;if(r.length>1){const t=r.filter((e=>n.existsSync(e.path)));if(t.length>0)if(o.yes)c=t[0].path,console.log(e.yellow(`Auto-selecting config file: ${c} due to --yes flag`));else{const{selectedConfigPath:e}=await i({type:"select",name:"selectedConfigPath",message:"Select the configuration file to modify:",choices:t.map((e=>({name:e.path,message:`${e.name} (${e.path})`})))});c=e}else if(o.yes)c=r[0].path,console.log(e.yellow(`Auto-selecting config file to create: ${c} due to --yes flag`));else{const{selectedConfigPath:e}=await i({type:"select",name:"selectedConfigPath",message:"Select the configuration file to create:",choices:r.map((e=>({name:e.path,message:`${e.name} (${e.path})`})))});c=e}}else if(1===r.length)c=r[0].path;else if(o.yes)c=s.join(l.homedir(),"win32"===process.platform?"_profile":".bashrc"),console.log(e.yellow(`Auto-selecting default config file: ${c} due to --yes flag`));else{const{enteredConfigPath:e}=await i({type:"input",name:"enteredConfigPath",message:"Enter the path to your shell configuration file:",initial:s.join(l.homedir(),".bashrc")});c=e}await k.addBinToPath(a,c,t)?(console.log(e.green(`Added bin directory to PATH in ${c}`)),console.log(e.yellow("Please restart your terminal or run the following command:")),console.log(e.green(`source ${c}`))):(console.log(e.red(`Failed to add bin directory to PATH in ${c}`)),console.log(e.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(e.green(k.getExportPathCommand(a,t))))}catch(o){console.error(e.red(`Failed to add bin directory to PATH: ${o.message}`)),process.exit(1)}}};var A={command:"compile [source] [options]",describe:"Compile a CLI project to a binary",builder:{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"}},handler:async o=>{try{await P(o);const t=process.cwd(),l=s.basename(t),a=o.name||l;let r;if(o.output)r=o.output;else{const e=s.join(t,".bin");n.existsSync(e)||n.mkdirSync(e,{recursive:!0}),r=s.join(e,a)}const c=s.resolve(process.cwd(),o.source);if(n.existsSync(c)||(console.error(e.red(`Source file not found: ${c}`)),console.error(e.yellow("Make sure to build your project first.")),process.exit(1)),n.existsSync(r)&&!o.force&&!o.yes){const{confirmOverwrite:o}=await i({type:"confirm",name:"confirmOverwrite",message:`Binary already exists at ${r}. Overwrite?`,initial:!1});if(!o)return void console.log(e.yellow("Compilation cancelled."))}const d=process.platform;console.log(e.blue(`Detected platform: ${d}`)),"win32"!==d||r.endsWith(".exe")||(r=`${r}.exe`,console.log(e.blue(`Adjusted output path for Windows: ${r}`))),console.log(e.blue(`Compiling ${c} to ${r}...`));const{spawn:m}=await import("child_process");try{const e=m("bun",["--version"],{stdio:"pipe"});await new Promise(((o,t)=>{e.on("close",(e=>{0===e?o():t(new Error("Bun is not available. Please install Bun first."))})),e.on("error",(e=>{t(new Error(`Bun is not available: ${e.message}`))}))}))}catch(o){console.error(e.red(`Bun is not available: ${o.message}`)),console.error(e.yellow("Please install Bun first: https://bun.sh/")),process.exit(1)}const u=["build",c,"--compile",`--outfile=${r}`];if(o.target&&"auto"!==o.target&&u.push(`--target=${o.target}`),!1===o.minify&&u.push("--no-minify"),o.external){o.external.split(",").map((e=>e.trim())).forEach((e=>{u.push(`--external:${e}`)}))}console.log(e.blue(`Running: bun ${u.join(" ")}`));const g=m("bun",u,{stdio:"inherit"});await new Promise(((e,o)=>{g.on("close",(t=>{0===t?e():o(new Error(`Compilation failed with code ${t}`))})),g.on("error",(e=>{o(e)}))})),"win32"!==d&&n.chmodSync(r,493),console.log(e.green(`Binary compiled successfully: ${r}`)),"win32"===d?console.log(e.yellow("Note: On Windows, you may need to run the binary from a command prompt or PowerShell.")):"darwin"===d&&console.log(e.yellow("Note: On macOS, you may need to allow the binary to run in System Preferences > Security & Privacy."))}catch(o){console.error(e.red(`Failed to compile binary: ${o.message}`)),process.exit(1)}}};var B={command:"install [source] [options]",describe:"Install a binary to the bin directory",builder:{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"}},handler:async o=>{try{await P(o);const t=s.resolve(process.cwd(),o.source);n.existsSync(t)||(console.error(e.red(`Source file not found: ${t}`)),process.exit(1)),await k.createBinDirectoryStructure();const l=k.getBinDirectory();let a;a=o.name?o.name:s.basename(t),"win32"!==process.platform||a.endsWith(".exe")||(a=`${a}.exe`);const r=s.join(l,a);if(n.existsSync(r)&&!o.force&&!o.yes){const{confirmOverwrite:o}=await i({type:"confirm",name:"confirmOverwrite",message:`Binary already exists at ${r}. Overwrite?`,initial:!1});if(!o)return void console.log(e.yellow("Installation cancelled."))}console.log(e.blue(`Installing ${t} to ${r}...`)),n.copyFileSync(t,r),"win32"!==process.platform&&n.chmodSync(r,493);const c=k.getMetadataFilePath();let d={binaries:{},lastUpdated:(new Date).toISOString()};if(n.existsSync(c))try{d=JSON.parse(n.readFileSync(c,"utf8"))}catch(o){console.warn(e.yellow(`Failed to parse metadata file: ${o.message}`)),console.warn(e.yellow("Creating new metadata file."))}let m="0.0.0";try{const{execSync:o}=require("child_process"),t=o(`"${r}" --version`,{timeout:5e3,stdio:["ignore","pipe","ignore"]}).toString().trim(),s=t.match(/v?(\d+\.\d+\.\d+)/);s?(m=s[1],console.log(e.blue(`Detected binary version: ${m}`))):(console.log(e.yellow(`Could not parse version from output: ${t}`)),console.log(e.yellow(`Using default version: ${m}`)))}catch(o){console.log(e.yellow(`Could not detect binary version, using default: ${m}`))}d.binaries[a]={path:r,source:t,created:(new Date).toISOString(),platform:process.platform,version:m,project:s.basename(process.cwd())},d.lastUpdated=(new Date).toISOString(),n.writeFileSync(c,JSON.stringify(d,null,2)),console.log(e.green(`Binary installed successfully: ${r}`));k.checkIfInPath(l)?console.log(e.green(`You can now run '${a}' from anywhere.`)):console.log(e.yellow("Bin directory is not in PATH. Run 'fbin path' to add it."))}catch(o){console.error(e.red(`Failed to install binary: ${o.message}`)),process.exit(1)}}};var F={promptForSelection:async function(o){const{items:t,message:s,nameField:n="name",valueField:l="name",initialValue:a=null,allowAbort:r=!0}=o;if(!t||0===t.length)return console.log(e.yellow("No items available for selection.")),null;if(1===t.length&&!r){const o=t[0],s="string"==typeof o?o:o[l];return console.log(e.blue(`Only one option available: ${"string"==typeof o?o:o[n]}`)),s}let c=t.map((e=>"string"==typeof e?{name:e,value:e,message:e}:{name:e[l],value:e[l],message:e[n]||e[l]}));r&&c.push({name:"cancel",value:null,message:e.yellow("Cancel")});let d=null;if(a){const e=c.findIndex((e=>e.name===a));-1!==e&&(d=e)}const m="selectedItem",{[m]:u}=await i({type:"select",name:m,message:s,choices:c,initial:d});return"cancel"===u?null:u},promptForMultipleSelection:async function(o){const{items:t,message:s,nameField:n="name",valueField:l="name",initialValues:a=[],allowAbort:r=!0}=o;if(!t||0===t.length)return console.log(e.yellow("No items available for selection.")),null;let c=t.map((e=>"string"==typeof e?{name:e,value:e,message:e}:{name:e[l],value:e[l],message:e[n]||e[l]})),d=[];a&&a.length>0&&(d=c.map(((e,o)=>a.includes(e.name)?o:-1)).filter((e=>-1!==e)));const m="selectedItems",u=await i({type:"multiselect",name:m,message:s,choices:c,initial:d,hint:"(Use space to select, enter to confirm)",validate:e=>!(0===e.length&&!r)||"Please select at least one item"});return r&&0===u[m].length?null:u[m]}};var j={command:"uninstall [name] [options]",describe:"Uninstall a binary from the bin directory",builder:{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"}},handler:async o=>{try{await P(o);const t=k.getBinDirectory(),s=k.getMetadataFilePath();let l;n.existsSync(t)||(console.error(e.red(`Bin directory not found: ${t}`)),console.error(e.yellow("Run fbin setup first.")),process.exit(1)),n.existsSync(s)||(console.error(e.red(`Metadata file not found: ${s}`)),console.error(e.yellow("Run fbin setup first.")),process.exit(1));try{l=JSON.parse(n.readFileSync(s,"utf8"))}catch(o){console.error(e.red(`Failed to parse metadata file: ${o.message}`)),process.exit(1)}if(!o.name&&!o.yes){const t=Object.keys(l.binaries);if(0===t.length)return void console.log(e.yellow("No binaries installed."));const s=await F.promptForSelection({items:t,message:"Select a binary to uninstall:",allowAbort:!0});if(null===s)return void console.log(e.yellow("Uninstallation cancelled."));o.name=s}const a=o.name;a||(console.error(e.red("Binary name is required.")),console.error(e.yellow("Use --name to specify a binary or run without --yes to select interactively.")),process.exit(1)),l.binaries[a]||(console.error(e.red(`Binary not found in metadata: ${a}`)),console.log(e.yellow("Use fbin list to see installed binaries.")),process.exit(1));const r=l.binaries[a].path;if(n.existsSync(r)||(console.warn(e.yellow(`Binary file not found: ${r}`)),console.warn(e.yellow("Metadata will be updated anyway."))),!o.force&&!o.yes){const{confirmUninstall:o}=await i({type:"confirm",name:"confirmUninstall",message:`Are you sure you want to uninstall ${a}?`,initial:!1});if(!o)return void console.log(e.yellow("Uninstallation cancelled."))}if(n.existsSync(r))try{n.unlinkSync(r),console.log(e.green(`Binary file removed: ${r}`))}catch(o){console.error(e.red(`Failed to remove binary file: ${o.message}`))}delete l.binaries[a],l.lastUpdated=(new Date).toISOString(),n.writeFileSync(s,JSON.stringify(l,null,2)),console.log(e.green(`Binary uninstalled successfully: ${a}`))}catch(o){console.error(e.red(`Failed to uninstall binary: ${o.message}`)),process.exit(1)}}};function C(o,t={}){const s={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,...t,head:o.map((o=>e.bold(o)))};return new r(s)}var T={createTable:C,createTableWithData:function(e,o,t={}){const s=C(e,t);return Array.isArray(o)&&o.forEach((e=>{s.push(e)})),s.toString()},getStatusColor:function(o){switch(o){case"running":return e.green;case"stopped":return e.yellow;case"failed":return e.red;case"registered":return e.blue;default:return e.gray}}};var D={command:"list [options]",describe:"List installed binaries",builder:{json:{describe:"Output in JSON format",type:"boolean",default:!1,alias:"j"},filter:{describe:"Filter binaries by name",type:"string",alias:"f"}},handler:async o=>{try{await P(o);const t=k.getBinDirectory(),s=k.getMetadataFilePath();let l;n.existsSync(t)||(console.error(e.red(`Bin directory not found: ${t}`)),console.error(e.yellow("Run fbin setup first.")),process.exit(1)),n.existsSync(s)||(console.error(e.red(`Metadata file not found: ${s}`)),console.error(e.yellow("Run fbin setup first.")),process.exit(1));try{l=JSON.parse(n.readFileSync(s,"utf8"))}catch(o){console.error(e.red(`Failed to parse metadata file: ${o.message}`)),process.exit(1)}let i=l.binaries;if(o.filter){const e=o.filter.toLowerCase();i=Object.entries(i).filter((([o])=>o.toLowerCase().includes(e))).reduce(((e,[o,t])=>(e[o]=t,e)),{})}if(o.json)return void console.log(JSON.stringify(i,null,2));const a=Object.keys(i).length;if(0===a)return void console.log(e.yellow("No binaries installed."));console.log(e.blue(`Found ${a} installed binaries:`)),console.log();const r=["NAME","VERSION","PLATFORM","CREATED"],c=T.createTable(r,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});Object.entries(i).forEach((([o,t])=>{const s=new Date(t.created).toLocaleString();c.push([e.white(o),t.version||"N/A",t.platform||"N/A",s])})),console.log(c.toString()),console.log(),console.log(e.blue(`Bin directory: ${t}`));k.checkIfInPath(t)||console.log(e.yellow("Bin directory is not in PATH. Run 'fbin path' to add it."))}catch(o){console.error(e.red(`Failed to list binaries: ${o.message}`)),process.exit(1)}}};var O={command:"backup [options]",describe:"Backup shell configs and binaries",builder:{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"}},handler:async o=>{try{await P(o);const t=o.all||!o.config&&!o.binaries,l=o.config||t,i=o.binaries||t;console.log(e.blue("Creating backup..."));const a=k.createBackupDirectory(),r=[];if(l){console.log(e.blue("Backing up shell configurations..."));const o=s.join(a,"configs");n.mkdirSync(o,{recursive:!0});const t=k.detectUserShell(),l=k.getAllShellConfigPaths(t);let i=0;for(const t of l)if(n.existsSync(t.path)){k.backupFile(t.path,o,t.name)&&(r.push(t.path),i++,console.log(e.green(` ✓ ${t.name}`)))}0===i?console.log(e.yellow(" No configuration files found to backup")):console.log(e.green(` Backed up ${i} configuration file(s)`))}if(i){console.log(e.blue("Backing up binaries..."));const o=s.join(a,"binaries");n.mkdirSync(o,{recursive:!0});const t=k.getBinDirectory(),l=k.getMetadataFilePath();if(n.existsSync(l)&&(k.backupFile(l,o,"metadata.json"),r.push(l)),n.existsSync(t)){const l=n.readdirSync(t);let i=0;for(const a of l){const l=s.join(t,a);if(n.statSync(l).isFile()){k.backupFile(l,o,a)&&(r.push(l),i++,console.log(e.green(` ✓ ${a}`)))}}0===i?console.log(e.yellow(" No binaries found to backup")):console.log(e.green(` Backed up ${i} binary(ies)`))}else console.log(e.yellow(" Bin directory not found"))}k.createBackupMetadata(a,{type:"manual",command:"fbin backup",message:o.message||"Manual backup",files:r,config:l,binaries:i}),k.updateLatestSymlink(a),console.log(),console.log(e.green("✓ Backup created successfully!")),console.log(e.blue(` Location: ${a}`)),console.log(e.blue(` Files backed up: ${r.length}`)),o.message&&console.log(e.blue(` Message: ${o.message}`))}catch(o){console.error(e.red(`Failed to create backup: ${o.message}`)),process.exit(1)}}};var M={command:"restore [options]",describe:"Restore from backup",builder:{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"}},handler:async o=>{try{await P(o);if(o.list){const o=k.listBackups();if(0===o.length)return void console.log(e.yellow("No backups found."));console.log(e.blue(`Found ${o.length} backup(s):\n`));const t=["TIMESTAMP","TYPE","MESSAGE","FILES"],s=T.createTable(t,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});for(const t of o){const o=t.timestamp||"unknown",n=t.type||"manual",l=t.message||"",i=t.files?t.files.length:0;s.push([e.white(o),n,l.substring(0,40)+(l.length>40?"...":""),i.toString()])}return console.log(s.toString()),console.log(),void console.log(e.blue(`Backup directory: ${k.getBackupDirectory()}`))}const t=k.listBackups();if(0===t.length)return console.log(e.yellow("No backups found.")),void console.log(e.blue("Create a backup first with: fbin backup"));let l;if(o.timestamp)l=t.find((e=>e.timestamp===o.timestamp)),l||(console.error(e.red(`Backup not found: ${o.timestamp}`)),console.log(e.yellow("Use --list to see available backups")),process.exit(1));else if(o.yes)l=t[0],console.log(e.yellow(`Auto-selecting latest backup: ${l.timestamp}`));else{const o=t.map((e=>({name:e.timestamp,message:`${e.timestamp} - ${e.message||"No message"} (${e.files?.length||0} files)`}))),s=await F.promptForSelection({items:o.map((e=>e.name)),message:"Select a backup to restore:",allowAbort:!0});if(null===s)return void console.log(e.yellow("Restore cancelled."));l=t.find((e=>e.timestamp===s))}console.log(e.blue(`Restoring from backup: ${l.timestamp}`));const a=o.all||!o.config&&!o.binaries,r=o.config||a,c=o.binaries||a;if(!o.yes){const{confirmRestore:o}=await i({type:"confirm",name:"confirmRestore",message:"This will overwrite current files. Continue?",initial:!1});if(!o)return void console.log(e.yellow("Restore cancelled."))}let d=0;if(r){const o=s.join(l.path,"configs");if(n.existsSync(o)){console.log(e.blue("Restoring shell configurations..."));const t=n.readdirSync(o);for(const l of t){const t=s.join(o,l),i=k.detectUserShell(),a=k.getAllShellConfigPaths(i).find((e=>e.name===l));if(a){const o=a.path,i=s.dirname(o);n.existsSync(i)||n.mkdirSync(i,{recursive:!0}),n.copyFileSync(t,o),console.log(e.green(` ✓ ${l}`)),d++}}}}if(c){const o=s.join(l.path,"binaries");if(n.existsSync(o)){console.log(e.blue("Restoring binaries..."));const t=k.getBinDirectory();n.existsSync(t)||n.mkdirSync(t,{recursive:!0});const l=n.readdirSync(o);for(const i of l){const l=s.join(o,i),a=s.join(t,i);if("metadata.json"!==i)n.copyFileSync(l,a),"win32"!==process.platform&&n.chmodSync(a,493),console.log(e.green(` ✓ ${i}`)),d++;else{const o=k.getMetadataFilePath(),t=s.dirname(o);n.existsSync(t)||n.mkdirSync(t,{recursive:!0}),n.copyFileSync(l,o),console.log(e.green(" ✓ metadata.json")),d++}}}}console.log(),console.log(e.green("✓ Restore completed successfully!")),console.log(e.blue(` Files restored: ${d}`))}catch(o){console.error(e.red(`Failed to restore backup: ${o.message}`)),process.exit(1)}}};var N={command:"cleanup [options]",describe:"Clean up old backups",builder:{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"}},handler:async o=>{try{await P(o);const t=k.listBackups();if(0===t.length)return void console.log(e.yellow("No backups found."));console.log(e.blue(`Found ${t.length} backup(s)`));let l=[];if(o.all)l=t;else if(o.older){const s=new Date;s.setDate(s.getDate()-o.older),l=t.filter((e=>new Date(e.created)<s)),console.log(e.blue(`Removing backups older than ${o.older} days (before ${s.toLocaleDateString()})`))}else{if(!(t.length>o.keep))return void console.log(e.green(`Only ${t.length} backup(s) found, keeping all (limit: ${o.keep})`));l=t.slice(o.keep),console.log(e.blue(`Keeping ${o.keep} most recent backup(s), removing ${l.length} old backup(s)`))}if(0===l.length)return void console.log(e.green("No backups to delete."));console.log(),console.log(e.yellow(`Backups to be deleted (${l.length}):`)),console.log();const a=["TIMESTAMP","TYPE","MESSAGE","FILES","SIZE"],r=T.createTable(a,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});let c=0;for(const o of l){const t=o.timestamp||"unknown",l=o.type||"manual",i=o.message||"",a=o.files?o.files.length:0;let d=0;try{const e=o=>{let t=0;const l=n.readdirSync(o);for(const i of l){const l=s.join(o,i),a=n.statSync(l);a.isDirectory()?t+=e(l):t+=a.size}return t};d=e(o.path),c+=d}catch(e){}const m=d>0?`${(d/1024/1024).toFixed(2)} MB`:"N/A";r.push([e.white(t),l,i.substring(0,30)+(i.length>30?"...":""),a.toString(),m])}if(console.log(r.toString()),console.log(),console.log(e.blue(`Total size to free: ${(c/1024/1024).toFixed(2)} MB`)),o["dry-run"])return console.log(),console.log(e.yellow("DRY RUN: No backups were deleted.")),void console.log(e.blue("Run without --dry-run to actually delete these backups."));if(!o.yes){console.log();const{confirmDelete:o}=await i({type:"confirm",name:"confirmDelete",message:`Delete ${l.length} backup(s)?`,initial:!1});if(!o)return void console.log(e.yellow("Cleanup cancelled."))}console.log(),console.log(e.blue("Deleting backups..."));let d=0,m=0;for(const o of l)try{n.rmSync(o.path,{recursive:!0,force:!0}),console.log(e.green(` ✓ ${o.timestamp}`)),d++}catch(t){console.log(e.red(` ✗ ${o.timestamp}: ${t.message}`)),m++}console.log(),console.log(e.green("✓ Cleanup completed!")),console.log(e.blue(` Deleted: ${d}`)),m>0&&console.log(e.yellow(` Failed: ${m}`)),console.log(e.blue(` Space freed: ${(c/1024/1024).toFixed(2)} MB`));const u=k.listBackups();console.log(e.blue(` Remaining backups: ${u.length}`))}catch(o){console.error(e.red(`Failed to cleanup backups: ${o.message}`)),process.exit(1)}}};c(d);let I=!1;process.on("uncaughtException",(e=>{I||(I=!0,setTimeout((()=>process.exit(1)),500))})),process.on("unhandledRejection",(e=>{I||(I=!0,setTimeout((()=>process.exit(1)),500))})),async function(){try{o(t(process.argv)).usage("Usage: $0 <command> [options]").command(v).command(x).command(A).command(B).command(j).command(D).command(O).command(M).command(N).demandCommand(1,"You need to specify a command").help().version().argv}catch(o){console.error(e.red(`Fatal error: ${o.message}`)),process.exit(1)}}().catch((o=>{console.error(e.red(`Fatal error: ${o.message}`)),process.exit(1)}));
|
|
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
|
|
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
|
|
5
|
+
|
|
6
|
+
`:$==="powershell"||$==="powershell-core"?`# PowerShell profile
|
|
7
|
+
|
|
8
|
+
`:`# Shell configuration
|
|
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()}
|
|
11
|
+
|
|
12
|
+
# Added by @fnet/cli
|
|
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)});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import C from"fs";import H from"path";import K from"@fnet/yaml";import L from"@fnet/shell-flow";async function U({projectType:B,group:A,tags:q,args:x,argv:I}){try{let z=await M(B),{parsed:J}=await K({file:z.path,tags:q}),D=J.commands;if(!D)throw Error(`Commands section not found in ${z.name}`);let E=D[A];if(!E)throw Error(`Command group '${A}' not found in ${z.name}`);await L({commands:E,context:{args:x,argv:I,projectType:z.type}})}catch(z){console.error(`Error: ${z.message}`),process.exit(1)}}async function M(B){let A=process.cwd(),q=H.resolve(A,"fnode.yaml"),x=H.resolve(A,"fnet.yaml");if(B==="fnode"){if(C.existsSync(q))return{path:q,name:"fnode.yaml",type:"fnode"};throw Error("fnode.yaml file not found in current directory")}if(B==="fnet"){if(C.existsSync(x))return{path:x,name:"fnet.yaml",type:"fnet"};throw Error("fnet.yaml file not found in current directory")}if(C.existsSync(q))return{path:q,name:"fnode.yaml",type:"fnode"};if(C.existsSync(x))return{path:x,name:"fnet.yaml",type:"fnet"};throw Error("No project file (fnode.yaml or fnet.yaml) found in current directory")}export{U as runCommandGroup,M as detectProjectFile};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import i from"node:path";import c from"node:fs";import{fileURLToPath as u}from"node:url";var v=i.dirname(u(import.meta.url)),A=process.cwd();function T(s){let r=i.resolve(A,s);if(c.existsSync(r))return r;let o=i.resolve(v,"../..",s);if(c.existsSync(o))return o;throw Error(`Template path not found: ${s}`)}import{existsSync as p}from"node:fs";import{delimiter as C,join as H}from"node:path";var O=(s)=>{let r=process.env.PATH||"",o=process.platform==="win32"?(process.env.PATHEXT||".EXE;.CMD;.BAT;.COM").split(";"):[""],f=r.split(C);for(let E of f)for(let x of o){let n=H(E,process.platform==="win32"?s+x:s);if(p(n))return n}return null};
|
|
2
|
+
export{T as a,O as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import l from"@fnet/config";import d from"@fnet/to-pyip";import a from"lodash.clonedeep";import y from"semver";async function u({atom:p,target:e,onProgress:s,projectDir:n,dependencies:r,context:t,yamlTarget:f}){if(s)await s({message:"Deploying it as pypi package."});let c=e?.config?await l({name:e.config,dir:n,optional:!0,transferEnv:!1,tags:t.tags}):void 0,o=y.inc(e.version||"0.1.0","patch");e.params.version=o,e.version=o,f.set("version",o);let i=a(e.params);i.dependencies=a(r);let m={atom:p,params:i,config:c?.config,src:n,dest:n};return{deployer:await d(m)}}export{u as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import w from"semver";import d from"@fnet/config";async function T({setProgress:f,context:t,deploymentProject:p,deploymentProjectTarget:o,yamlTarget:A}){await f({message:"Deploying it as fnet form."});let{file:n,data:e}=await d({name:o.config||"fnet-form",dir:t.projectDir,tags:t.tags});if(!e.env.ATOM_API_URL)throw Error(`ATOM_API_URL is required in ${n}`);if(!e.env.ATOM_API_USERNAME)throw Error(`ATOM_API_USERNAME is required in ${n}`);if(!e.env.ATOM_API_PASSWORD)throw Error(`ATOM_API_PASSWORD is required in ${n}`);let a=`${e.env.ATOM_API_URL}/v1/auth/token`,m=e.env.ATOM_API_USERNAME,h=e.env.ATOM_API_PASSWORD,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:m,password:h})});if(!r.ok)throw Error(`Failed to fetch token: ${r.statusText}`);let c=(await r.json())?.access_token;if(!c)throw Error(`Invalid access_token from ${a}`);p.isDirty=!0;let s=w.inc(o.version,"patch");o.params.version=s,o.version=s,A.set("version",s);let _=`${e.env.ATOM_API_URL}/v1/service/fnet-form/publish`,i=await fetch(_,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify({name:o.params.name,version:o.params.version,docs:o.params.docs,configs:o.params.configs})});if(!i.ok)throw Error(`Error publishing fnet form: ${i.statusText}`);if((await i.json())?.error)throw Error("Error publishing fnet form.")}export{T as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import l from"@fnet/config";import d from"@fnet/to-rust";import a from"lodash.clonedeep";import u from"semver";async function y({atom:t,target:e,onProgress:s,projectDir:n,dependencies:r,context:f,yamlTarget:c}){if(s)await s({message:"Deploying it as Rust package."});let p=e?.config?await l({name:e.config,dir:n,optional:!0,transferEnv:!1,tags:f.tags}):void 0,o=u.inc(e.version||"0.1.0","patch");e.params.version=o,e.version=o,c.set("version",o);let i=a(e.params);i.dependencies=a(r);let m={atom:t,params:i,config:p?.config,src:n,dest:n};return{deployer:await d(m)}}export{y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import a from"node:fs";import r from"node:path";import m from"node:os";import I from"nunjucks";import i from"@node-red/util";import T from"@fnet/config";async function D({atom:d,setProgress:h,context:o,deploymentProject:w,deploymentProjectTarget:e,buildId:F,packageDependencies:c,njEnv:j}){await h({message:"Deploying it as node-red flow."});let{projectDir:s,templateDir:$}=o,u=d.type==="workflow"?"WF":"LIB",p;if(e.deploy.template==="simple")p={atom:d,packageDependencies:c,red:{tab:{id:e.deploy.id||i.util.generateId(),label:`${u}/${d.id?d.id:m.hostname()}/${d.name}/${e.deploy.name||e.deploy.template}`},function:{id:i.util.generateId(),name:d.doc.name,initialize:{content:a.readFileSync(r.resolve(s,"dist/default/iife/index.js"),{encoding:"utf8",flag:"r"}),var:d.doc.bundleName}},inject:{id:i.util.generateId(),...e.params?.inject,payload:e.params?.inject?.payloadType==="json"?`'${JSON.stringify(e.params?.inject?.payload)}'`:e.params?.inject?.payload},debug:{id:i.util.generateId()}}};else if(e.deploy.template==="cronjob"){let l=e.params?.schedules?cloneDeep(e.params?.schedules):void 0;l?.forEach((t)=>{if(t.payloadType==="json")t.payload=`'${JSON.stringify(t.payload)}'`}),p={atom:d,packageDependencies:c,red:{tab:{id:e.deploy.id||i.util.generateId(),label:`${u}/${d.id?d.id:m.hostname()}/${e.deploy.name||e.deploy.template}`},function:{id:i.util.generateId(),name:d.doc.name,initialize:{content:a.readFileSync(r.resolve(s,"dist/default/iife/index.js"),{encoding:"utf8",flag:"r"}),var:d.doc.bundleName}},cronjob:{id:i.util.generateId(),schedules:l},debug:{id:i.util.generateId()}}}}else if(e.deploy.template==="http")p={atom:d,packageDependencies:c,red:{tab:{id:e.deploy.id||i.util.generateId(),label:`${u}/${d.id?d.id:m.hostname()}/${e.deploy.name||e.deploy.template}`},function:{id:i.util.generateId(),name:d.doc.name,initialize:{content:a.readFileSync(r.resolve(s,"dist/default/iife/index.js"),{encoding:"utf8",flag:"r"}),var:d.doc.bundleName}},httpin:{id:i.util.generateId(),method:e.params.method||"get",url:e.params.url},httpout:{id:i.util.generateId()},debug:{id:i.util.generateId()}}};else return;let n=I.compile(a.readFileSync(r.resolve($,`deploy/node-red/${e.deploy.template}.yaml.njk`),"utf8"),j).render(p);if(a.writeFileSync(r.resolve(s,"node-red.yaml"),n),n=yaml.load(n),e.dryRun===!0)return;w.isDirty=!0;let b=(await T({name:o.redConfig||"red",dir:o.projectDir,tags:o.tags}))?.data,y=e.deploy.url||b.env.RED_URL,f={};if(e.deploy.auth!==!1)f.Authorization="Bearer "+atomAccessToken;if(!e.deploy.id){let l=await fetch(`${y}/flow`,{method:"POST",headers:{...f,"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok)throw Error(`Failed to create flow: ${l.statusText}`);let t=await l.json();e.deploy.id=t.id}else if(e.actions?.delete===!0){let l=await fetch(`${y}/flow/${e.deploy.id}`,{method:"DELETE",headers:f});if(!l.ok)throw Error(`Failed to delete flow: ${l.statusText}`);delete e.actions.delete,delete e.deploy.id,e.enabled=!1}else{let l=await fetch(`${y}/flow/${e.deploy.id}`,{method:"PUT",headers:{...f,"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok)throw Error(`Failed to update flow: ${l.statusText}`)}}export{D as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import E from"cli-table3";import j from"chalk";function B(q,x={}){let y={...{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},...x,head:q.map((z)=>j.bold(z))};return new E(y)}function H(q,x,A={}){let y=B(q,A);if(Array.isArray(x))x.forEach((z)=>{y.push(z)});return y.toString()}function I(q){switch(q){case"running":return j.green;case"stopped":return j.yellow;case"failed":return j.red;case"registered":return j.blue;default:return j.gray}}var L={createTable:B,createTableWithData:H,getStatusColor:I};export{I as getStatusColor,L as default,H as createTableWithData,B as createTable};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import O from"semver";import P from"@fnet/config";import R from"node:fs";import S from"@fnet/shelljs";import D from"form-data";async function M({setProgress:u,context:n,deploymentProject:m,deploymentProjectTarget:e,yamlTarget:w}){await u({message:"Deploying it as fnet node."});let{file:t,data:o}=await P({name:e.config||"fnet-node",dir:n.project.projectDir,tags:n.tags});if(!o.env.ATOM_API_URL)throw Error(`ATOM_API_URL is required in ${t}`);if(!o.env.ATOM_API_USERNAME)throw Error(`ATOM_API_USERNAME is required in ${t}`);if(!o.env.ATOM_API_PASSWORD)throw Error(`ATOM_API_PASSWORD is required in ${t}`);let l=`${o.env.ATOM_API_URL}/v1/auth/token`,A=o.env.ATOM_API_USERNAME,_=o.env.ATOM_API_PASSWORD,s=await fetch(l,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:A,password:_})});if(!s.ok)throw Error(`Failed to fetch token: ${s.statusText}`);let i=(await s.json())?.access_token;if(!i)throw Error(`Invalid access_token from ${l}`);m.isDirty=!0;let a=O.inc(e.version,"patch");e.params.version=a,e.version=a,w.set("version",a);let T=`${o.env.ATOM_API_URL}/v1/service/fnet-node/publish`,p=await fetch(T,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({name:e.params.name,version:e.params.version,docs:e.params.docs,configs:e.params.configs})});if(!p.ok)throw Error(`Error publishing fnet node: ${p.statusText}`);let h=await p.json();if(h?.error)throw Error("Error publishing fnet node.");let v=h?.upload.id,r="fnet-dir-zipper";r+=` --sourceDir='${n.project.projectDir}'`,r+=" --pattern=**/*",r+=" --stdout_format=json";let c=await S(r);if(c.code!==0)throw Error(c.stderr);let E=JSON.parse(c.stdout).path,d=new D;d.append("file",R.createReadStream(E));let f=await fetch(`${o.env.ATOM_API_URL}/v1/service/upload/single/${v}`,{method:"POST",headers:{...d.getHeaders(),Authorization:`Bearer ${i}`},body:d});if(!f.ok)throw Error(`Error uploading fnet node: ${f.statusText}`);if((await f.json())?.error)throw Error("Error uploading fnet node.")}export{M as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import d from"@fnet/config";import l from"@flownet/lib-to-ios-app";import a from"lodash.clonedeep";import u from"semver";async function g({atom:p,target:e,onProgress:s,projectDir:n,dependencies:r,context:t,yamlTarget:f}){if(s)await s({message:"Deploying it as ios-app package."});let c=e?.config?await d({name:e.config,dir:n,optional:!0,transferEnv:!1,tags:t.tags}):void 0,o=u.inc(e.version||"0.1.0","patch");e.params.version=o,e.version=o,f.set("version",o);let i=a(e.params);i.dependencies=a(r);let m={atom:p,params:i,config:c?.config,src:n,dest:n};return{deployer:await l(m)}}export{g as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import d from"@fnet/config";import l from"@flownet/lib-to-nextjs";import a from"lodash.clonedeep";import u from"semver";async function g({atom:t,target:e,onProgress:s,projectDir:n,dependencies:r,context:f,yamlTarget:c}){if(s)await s({message:"Deploying it as nextjs package."});let m=e?.config?await d({name:e.config,dir:n,optional:!0,transferEnv:!1,tags:f.tags}):void 0,o=u.inc(e.version||"0.1.0","patch");e.params.version=o,e.version=o,c.set("version",o);let i=a(e.params);i.dependencies=a(r);let p={atom:t,params:i,config:m?.config,src:n,dest:n};return{deployer:await l(p)}}export{g as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import l from"@fnet/config";import d from"@flownet/lib-to-electron";import t from"lodash.clonedeep";import g from"semver";async function u({atom:a,target:e,onProgress:o,projectDir:n,dependencies:r,context:c,yamlTarget:f}){if(o)await o({message:"Deploying it as electron package."});let m=e?.config?await l({name:e.config,dir:n,optional:!0,transferEnv:!1,tags:c.tags}):void 0,s=g.inc(e.version||"0.1.0","patch");e.version=s,f.set("version",s);let i=t(e.params);i.dependencies=t(r);let p={atom:a,params:i,config:m?.config,src:n,dest:n};return{deployer:await d(p)}}export{u as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as Z,b as _}from"./index.2084z2ed.js";import"./index.r19p3bpa.js";import A from"node:fs";import E from"node:path";import u from"semver";import Y from"@fnet/shelljs";import v from"@fnet/config";import w from"@fnet/object-from-schema";import b from"yaml";import{fileURLToPath as F}from"node:url";var h=E.dirname(F(import.meta.url)),m=process.cwd();async function T({atom:y,setProgress:$,context:B,deploymentProject:L,deploymentProjectTarget:z,yamlTarget:R}){await $({message:"Deploying it as npm package."});let G=B.projectDir,H=E.resolve(G,"package.json"),V=A.readFileSync(H),q=JSON.parse(V);q.name=z.params.name,q.version=u.inc(z.version,"patch");let I=z.params.bin?.name||z.params.bin;if(z.params.bin?.enabled!==!1&&I&&typeof I==="string")q.bin={[I]:"dist/cli/esm/index.js"};delete q.scripts,delete q.devDependencies,q.scripts={serve:"npx serve ."},A.writeFileSync(H,JSON.stringify(q,null,"\t"));let W=z.config||"npm",K=(await v({name:W,dir:B.projectDir,tags:B.tags,optional:!0}))?.data;if(!K){let M=Z("./template/schemas/to-npm.yaml"),X=await w({schema:M,tags:B.tags}),U=B.project.projectDir,Q=E.resolve(U,".fnet");if(!A.existsSync(Q))A.mkdirSync(Q);A.writeFileSync(E.resolve(Q,`${W}.fnet`),b.stringify(X)),K=X}if(A.writeFileSync(E.resolve(G,".npmrc"),`//registry.npmjs.org/:_authToken=${K.env.NPM_TOKEN}`),z.dryRun===!0)return;if(_("bun")){if((await Y("bun publish --access public",{cwd:G})).code!==0)throw Error("Couldnt publish to npm")}else if((await Y("npm publish --access public",{cwd:G})).code!==0)throw Error("Couldnt publish to npm");A.writeFileSync(H,V),L.isDirty=!0,z.version=q.version,R.set("version",q.version)}export{T as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import o from"node:fs";import s from"node:path";import u from"semver";import y from"@fnet/shelljs";import g from"@fnet/config";async function S({setProgress:p,context:t,deploymentProject:l,deploymentProjectTarget:i,registerToPackageManager:d,yamlTarget:f}){await p({message:"Deploying it as gcs package."});let c=t.projectDir,a=s.resolve(c,"package.json"),m=o.readFileSync(a),n=JSON.parse(m);n.name=i.params.name,n.version=u.inc(i.version,"patch"),delete n.scripts,delete n.devDependencies,o.writeFileSync(a,JSON.stringify(n,null,"\t"));let{file:v,data:r}=await g({name:i.config||"gcs",dir:t.projectDir,tags:t.tags}),e="fnet-files-to-gcs";if(e+=` --projectId='${r.env.GCS_PROJECT_ID}'`,e+=` --bucketName='${r.env.GCS_BUCKET_NAME}'`,e+=` --keyFilename='${s.resolve(s.dirname(v),r.env.GCS_UPLOADER_KEY_FILE)}'`,e+=` --dir='${c}'`,e+=" --pattern='dist/**/**'",e+=" --pattern='bin/**/**'",e+=" --pattern='test/**/**'",e+=" --pattern='*.html'",e+=` --destDir='${n.name}/${n.version}'`,e+=" --metadata.cacheControl='public, max-age=31536000, immutable'",console.log(e),r.env.DOMAIN)e+=` --domain='${r.env.DOMAIN}'`;if(i.dry_run===!0||i.params.dry_run===!0)e+=" --dryRun";if(await y(e),o.writeFileSync(a,m),i.dryRun===!0)return;l.isDirty=!0,i.version=n.version,f.set("version",n.version),await d({target:i,packageJSON:n})}export{S as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./index.r19p3bpa.js";import c from"@fnet/shelljs";import g from"@fnet/config";async function p({setProgress:e,context:r,deploymentProject:s,deploymentProjectTarget:i,buildId:m}){await e({message:"Deploying it as gitlab project."});let l=r.projectDir,a="fnet-to-gitlab",o=i.params.config||"gitlab",n=await g({name:o,dir:r.projectDir,tags:r.tags});if(!n)throw Error(`Couldnt load config ${o}`);let{data:t}=n.data;if(a+=` --projectGroupId=${t.projectGroupId}`,a+=` --projectPath='${l}'`,a+=` --projectName='${i.params.name}'`,a+=` --projectBranch='${i.params.branch||"main"}'`,a+=` --gitlabHost='${t.gitlabHost}'`,a+=` --gitlabToken='${t.gitlabToken}'`,a+=` --gitlabUsername='${t.gitlabUsername}'`,a+=` --gitlabUserEmail='${t.gitlabUserEmail}'`,i.dryRun===!0)return;await c(a),s.isDirty=!0}export{p as default};
|