@fnet/cli 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fbin/index.js +1 -1
- package/dist/fnet/index.js +1 -1
- package/dist/fnode/index.js +1 -1
- package/dist/frun/index.js +1 -1
- package/dist/fservice/index.js +1 -1
- package/package.json +3 -3
package/dist/fbin/index.js
CHANGED
|
@@ -12,4 +12,4 @@ echo Path updated successfully`;default:return`export PATH="${Y}:$PATH"`}}async
|
|
|
12
12
|
# Added by @fnet/cli
|
|
13
13
|
${Q}
|
|
14
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,J=null){try{if(!I.existsSync($))return!1;let G=J||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 W1($,Y={}){let J={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(J,null,2))}function o1(){let $=g();if(!I.existsSync($))return[];let Y=[],J=I.readdirSync($);for(let G of J){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 E1($){let Y=E.join(g(),"latest");try{if(I.existsSync(Y))I.unlinkSync(Y);if(process.platform==="win32")I.writeFileSync(Y+".txt",$);else I.symlinkSync($,Y)}catch(J){console.warn(D.yellow(`Could not create latest symlink: ${J.message}`))}}var R={getBinDirectory:Z1,getMetadataDirectory:e,getMetadataFilePath:_1,checkIfInPath:f1,detectUserShell:G1,getShellConfigPath:b1,getAllShellConfigPaths:K1,createBinDirectoryStructure:g1,getExportPathCommand:H1,addBinToPath:h1,getBackupDirectory:g,createBackupDirectory:L1,backupFile:R1,createBackupMetadata:W1,listBackups:o1,updateLatestSymlink:E1};import h from"node:path";import{fileURLToPath as l1}from"node:url";import I1 from"node:os";import o from"node:fs";var JY=h.dirname(l1(import.meta.url));function M1(){}function O1(){let $=I1.homedir(),Y=h.join($,".fnet","bin");if(!o.existsSync(Y))o.mkdirSync(Y,{recursive:!0});return Y}function V1(){let $=I1.homedir(),Y=h.join($,".fnet");if(!o.existsSync(Y))o.mkdirSync(Y,{recursive:!0});return h.join(Y,"bin-registry.json")}import U1 from"node:fs";async function z($){let Y=O1(),J=V1(),G={};if(U1.existsSync(J))try{let Z=U1.readFileSync(J,"utf8");G=JSON.parse(Z)}catch(Z){console.warn(`Warning: Could not parse bin registry: ${Z.message}`)}return{binDir:Y,registryPath:J,registry:G,args:$}}var c1="setup",s1="Initialize the bin system",r1={yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},i1=async($)=>{try{let Y=await z($);console.log(O.blue("Setting up the bin system...")),await R.createBinDirectoryStructure();let J=R.getBinDirectory();if(console.log(O.green(`Bin directory: ${J}`)),!R.checkIfInPath(J)){console.log(O.yellow("Bin directory is not in PATH."));let Z=$.yes;if(!$.yes)Z=(await v({type:"confirm",name:"confirmAddToPath",message:`Would you like to add ${J} to your PATH?`,initial:!0})).confirmAddToPath;else console.log(O.yellow("Auto-confirming to add bin directory to PATH due to --yes flag"));if(Z){let Q=R.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:L}=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=L}else if($.yes)console.log(O.yellow(`Auto-confirming detected shell: ${Q} due to --yes flag`));else{let{confirmShell:L}=await v({type:"confirm",name:"confirmShell",message:`Detected shell: ${Q}. Is this correct?`,initial:!0});if(!L){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=R.getAllShellConfigPaths(Q),K;if(H.length>1){let L=H.filter((X)=>n1.existsSync(X.path));if(L.length>0)if($.yes)K=L[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:L.map((q)=>({name:q.path,message:`${q.name} (${q.path})`}))});K=X}else if($.yes)K=H[0].path,console.log(O.yellow(`Auto-selecting config file to create: ${K} due to --yes flag`));else{let{selectedConfigPath:X}=await v({type:"select",name:"selectedConfigPath",message:"Select the configuration file to create:",choices:H.map((q)=>({name:q.path,message:`${q.name} (${q.path})`}))});K=X}}else if(H.length===1)K=H[0].path;else if($.yes)K=z1.join(w1.homedir(),process.platform==="win32"?"_profile":".bashrc"),console.log(O.yellow(`Auto-selecting default config file: ${K} due to --yes flag`));else{let{enteredConfigPath:L}=await v({type:"input",name:"enteredConfigPath",message:"Enter the path to your shell configuration file:",initial:z1.join(w1.homedir(),".bashrc")});K=L}if(await R.addBinToPath(Q,K,J))console.log(O.green(`Added bin directory to PATH in ${K}`)),console.log(O.yellow("Please restart your terminal or run the following command:")),console.log(O.green(`source ${K}`));else console.log(O.red(`Failed to add bin directory to PATH in ${K}`)),console.log(O.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(O.green(R.getExportPathCommand(Q,J)))}else console.log(O.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(O.green(`export PATH="${J}:$PATH"`)),console.log(O.yellow("Or run:")),console.log(O.green("fbin path"))}else console.log(O.green("Bin directory is already in PATH."));console.log(O.green("Bin system setup completed successfully."))}catch(Y){console.error(O.red(`Failed to set up bin system: ${Y.message}`)),process.exit(1)}},T1={command:c1,describe:s1,builder:r1,handler:i1};import N1 from"node:path";import t1 from"node:fs";import A1 from"node:os";import A from"chalk";import u from"@fnet/prompt";var e1="path",a1="Add bin directory to PATH",$$={yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},Y$=async($)=>{try{let Y=await z($),J=R.getBinDirectory();if(console.log(A.blue(`Adding ${J} to PATH...`)),!R.createBinDirectoryStructure())console.log(A.yellow("Creating bin directory structure...")),await R.createBinDirectoryStructure();if(R.checkIfInPath(J)){console.log(A.green("Bin directory is already in PATH."));return}let Z=R.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:L}=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=L}}let Q=R.getAllShellConfigPaths(Z),H;if(Q.length>1){let _=Q.filter((L)=>t1.existsSync(L.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:L}=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=L}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:L}=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=L}}else if(Q.length===1)H=Q[0].path;else if($.yes)H=N1.join(A1.homedir(),process.platform==="win32"?"_profile":".bashrc"),console.log(A.yellow(`Auto-selecting default config file: ${H} due to --yes flag`));else{let{enteredConfigPath:_}=await u({type:"input",name:"enteredConfigPath",message:"Enter the path to your shell configuration file:",initial:N1.join(A1.homedir(),".bashrc")});H=_}if(await R.addBinToPath(Z,H,J))console.log(A.green(`Added bin directory to PATH in ${H}`)),console.log(A.yellow("Please restart your terminal or run the following command:")),console.log(A.green(`source ${H}`));else console.log(A.red(`Failed to add bin directory to PATH in ${H}`)),console.log(A.yellow("You can add it manually by adding the following line to your shell configuration:")),console.log(A.green(R.getExportPathCommand(Z,J)))}catch(Y){console.error(A.red(`Failed to add bin directory to PATH: ${Y.message}`)),process.exit(1)}},B1={command:e1,describe:a1,builder:$$,handler:Y$};import l from"node:path";import f from"node:fs";import x from"chalk";import q$ from"@fnet/prompt";var J$="compile [source] [options]",Q$="Compile a CLI project to a binary",X$={source:{describe:"Source file to compile",type:"string",default:"./dist/cli/esm/index.js"},output:{describe:"Output file name",type:"string",alias:"o"},name:{describe:"Binary name",type:"string",alias:"n"},force:{describe:"Force overwrite if binary already exists",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},target:{describe:"Target platform (auto, linux, macos, windows)",type:"string",choices:["auto","linux","macos","windows"],default:"auto"},minify:{describe:"Minify the output binary",type:"boolean",default:!0},external:{describe:"External packages to exclude from the bundle (comma-separated)",type:"string"}},Z$=async($)=>{try{let Y=await z($),J=process.cwd(),G=l.basename(J),Z=$.name||G,Q;if($.output)Q=$.output;else{let q=l.join(J,".bin");if(!f.existsSync(q))f.mkdirSync(q,{recursive:!0});Q=l.join(q,Z)}let H=l.resolve(process.cwd(),$.source);if(!f.existsSync(H))console.error(x.red(`Source file not found: ${H}`)),console.error(x.yellow("Make sure to build your project first.")),process.exit(1);if(f.existsSync(Q)&&!$.force&&!$.yes){let{confirmOverwrite:q}=await q$({type:"confirm",name:"confirmOverwrite",message:`Binary already exists at ${Q}. Overwrite?`,initial:!1});if(!q){console.log(x.yellow("Compilation cancelled."));return}}let K=process.platform;if(console.log(x.blue(`Detected platform: ${K}`)),K==="win32"&&!Q.endsWith(".exe"))Q=`${Q}.exe`,console.log(x.blue(`Adjusted output path for Windows: ${Q}`));console.log(x.blue(`Compiling ${H} to ${Q}...`));let{spawn:_}=await import("child_process");try{let q=_("bun",["--version"],{stdio:"pipe"});await new Promise((W,M)=>{q.on("close",(T)=>{if(T===0)W();else M(Error("Bun is not available. Please install Bun first."))}),q.on("error",(T)=>{M(Error(`Bun is not available: ${T.message}`))})})}catch(q){console.error(x.red(`Bun is not available: ${q.message}`)),console.error(x.yellow("Please install Bun first: https://bun.sh/")),process.exit(1)}let L=["build",H,"--compile",`--outfile=${Q}`];if($.target&&$.target!=="auto")L.push(`--target=${$.target}`);if($.minify===!1)L.push("--no-minify");if($.external)$.external.split(",").map((W)=>W.trim()).forEach((W)=>{L.push(`--external:${W}`)});console.log(x.blue(`Running: bun ${L.join(" ")}`));let X=_("bun",L,{stdio:"inherit"});if(await new Promise((q,W)=>{X.on("close",(M)=>{if(M===0)q();else W(Error(`Compilation failed with code ${M}`))}),X.on("error",(M)=>{W(M)})}),K!=="win32")f.chmodSync(Q,493);if(console.log(x.green(`Binary compiled successfully: ${Q}`)),K==="win32")console.log(x.yellow("Note: On Windows, you may need to run the binary from a command prompt or PowerShell."));else if(K==="darwin")console.log(x.yellow("Note: On macOS, you may need to allow the binary to run in System Preferences > Security & Privacy."))}catch(Y){console.error(x.red(`Failed to compile binary: ${Y.message}`)),process.exit(1)}},j1={command:J$,describe:Q$,builder:X$,handler:Z$};import n from"node:path";import C from"node:fs";import B from"chalk";import _$ from"@fnet/prompt";var G$="install [source] [options]",K$="Install a binary to the bin directory",H$={source:{describe:"Source binary to install",type:"string",demandOption:!0},name:{describe:"Name to use for the installed binary",type:"string",alias:"n"},force:{describe:"Force overwrite if binary already exists",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},symlink:{describe:"Create a symlink instead of copying the binary",type:"boolean",default:!1,alias:"s"}},L$=async($)=>{try{let Y=await z($),J=n.resolve(process.cwd(),$.source);if(!C.existsSync(J))console.error(B.red(`Source file not found: ${J}`)),process.exit(1);await R.createBinDirectoryStructure();let G=R.getBinDirectory(),Z;if($.name)Z=$.name;else Z=n.basename(J);if(process.platform==="win32"&&!Z.endsWith(".exe"))Z=`${Z}.exe`;let Q=n.join(G,Z);if(C.existsSync(Q)&&!$.force&&!$.yes){let{confirmOverwrite:X}=await _$({type:"confirm",name:"confirmOverwrite",message:`Binary already exists at ${Q}. Overwrite?`,initial:!1});if(!X){console.log(B.yellow("Installation cancelled."));return}}if($.symlink){if(console.log(B.blue(`Creating symlink from ${J} to ${Q}...`)),C.existsSync(Q))C.unlinkSync(Q);if(process.platform==="win32")C.symlinkSync(J,Q,"file");else C.symlinkSync(J,Q);console.log(B.green("Symlink created successfully."))}else if(console.log(B.blue(`Installing ${J} to ${Q}...`)),C.copyFileSync(J,Q),process.platform!=="win32")C.chmodSync(Q,493);let H=R.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}=X1("child_process"),q=X(`"${Q}" --version`,{timeout:5000,stdio:["ignore","pipe","ignore"]}).toString().trim(),W=q.match(/v?(\d+\.\d+\.\d+)/);if(W)_=W[1],console.log(B.blue(`Detected binary version: ${_}`));else console.log(B.yellow(`Could not parse version from output: ${q}`)),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:J,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}`)),!R.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)}},F1={command:G$,describe:K$,builder:H$,handler:L$};import P from"node:fs";import w from"chalk";import E$ from"@fnet/prompt";import c from"chalk";import x1 from"@fnet/prompt";async function R$($){let{items:Y,message:J,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 q=Y[0],W=typeof q==="string"?q:q[Z];return console.log(c.blue(`Only one option available: ${typeof q==="string"?q:q[G]}`)),W}let K=Y.map((q)=>{if(typeof q==="string")return{name:q,value:q,message:q};else return{name:q[Z],value:q[Z],message:q[G]||q[Z]}});if(H)K.push({name:"cancel",value:null,message:c.yellow("Cancel")});let _=null;if(Q){let q=K.findIndex((W)=>W.name===Q);if(q!==-1)_=q}let L="selectedItem",{[L]:X}=await x1({type:"select",name:L,message:J,choices:K,initial:_});if(X==="cancel")return null;return X}async function W$($){let{items:Y,message:J,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((q)=>{if(typeof q==="string")return{name:q,value:q,message:q};else return{name:q[Z],value:q[Z],message:q[G]||q[Z]}}),_=[];if(Q&&Q.length>0)_=K.map((q,W)=>Q.includes(q.name)?W:-1).filter((q)=>q!==-1);let L="selectedItems",X=await x1({type:"multiselect",name:L,message:J,choices:K,initial:_,hint:"(Use space to select, enter to confirm)",validate:(q)=>{if(q.length===0&&!H)return"Please select at least one item";return!0}});if(H&&X[L].length===0)return null;return X[L]}var s={promptForSelection:R$,promptForMultipleSelection:W$};var I$="uninstall [name] [options]",M$="Uninstall a binary from the bin directory",O$={name:{describe:"Name of the binary to uninstall",type:"string",demandOption:!1},force:{describe:"Skip confirmation prompt",type:"boolean",default:!1,alias:"f"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},V$=async($)=>{try{let Y=await z($),J=R.getBinDirectory(),G=R.getMetadataFilePath();if(!P.existsSync(J))console.error(w.red(`Bin directory not found: ${J}`)),console.error(w.yellow("Run fbin setup first.")),process.exit(1);if(!P.existsSync(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 E$({type:"confirm",name:"confirmUninstall",message:`Are you sure you want to uninstall ${Q}?`,initial:!1});if(!K){console.log(w.yellow("Uninstallation cancelled."));return}}if(P.existsSync(H))try{P.unlinkSync(H),console.log(w.green(`Binary file removed: ${H}`))}catch(K){console.error(w.red(`Failed to remove binary file: ${K.message}`))}delete Z.binaries[Q],Z.lastUpdated=new Date().toISOString(),P.writeFileSync(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)}},C1={command:I$,describe:M$,builder:O$,handler:V$};import a from"node:fs";import S from"chalk";import U$ from"cli-table3";import k from"chalk";function S1($,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 U$(G)}function z$($,Y,J={}){let G=S1($,J);if(Array.isArray(Y))Y.forEach((Z)=>{G.push(Z)});return G.toString()}function w$($){switch($){case"running":return k.green;case"stopped":return k.yellow;case"failed":return k.red;case"registered":return k.blue;default:return k.gray}}var p={createTable:S1,createTableWithData:z$,getStatusColor:w$};var T$="list [options]",N$="List installed binaries",A$={json:{describe:"Output in JSON format",type:"boolean",default:!1,alias:"j"},filter:{describe:"Filter binaries by name",type:"string",alias:"f"}},B$=async($)=>{try{let Y=await z($),J=R.getBinDirectory(),G=R.getMetadataFilePath();if(!a.existsSync(J))console.error(S.red(`Bin directory not found: ${J}`)),console.error(S.yellow("Run fbin setup first.")),process.exit(1);if(!a.existsSync(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(([q])=>q.toLowerCase().includes(X)).reduce((q,[W,M])=>{return q[W]=M,q},{})}if($.json){console.log(JSON.stringify(Q,null,2));return}let H=Object.keys(Q).length;if(H===0){console.log(S.yellow("No binaries installed."));return}console.log(S.blue(`Found ${H} installed binaries:`)),console.log();let K=["NAME","VERSION","PLATFORM","CREATED"],_=p.createTable(K,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});if(Object.entries(Q).forEach(([X,q])=>{let W=new Date(q.created).toLocaleString();_.push([S.white(X),q.version||"N/A",q.platform||"N/A",W])}),console.log(_.toString()),console.log(),console.log(S.blue(`Bin directory: ${J}`)),!R.checkIfInPath(J))console.log(S.yellow("Bin directory is not in PATH. Run 'fbin path' to add it."))}catch(Y){console.error(S.red(`Failed to list binaries: ${Y.message}`)),process.exit(1)}},D1={command:T$,describe:N$,builder:A$,handler:B$};import $1 from"node:path";import d from"node:fs";import j from"chalk";var j$="backup [options]",F$="Backup shell configs and binaries",x$={config:{describe:"Backup shell configuration files",type:"boolean",default:!1,alias:"c"},binaries:{describe:"Backup installed binaries",type:"boolean",default:!1,alias:"b"},all:{describe:"Backup everything (configs + binaries)",type:"boolean",default:!1,alias:"a"},message:{describe:"Backup description message",type:"string",alias:"m"}},C$=async($)=>{try{let Y=await z($),J=$.all||!$.config&&!$.binaries,G=$.config||J,Z=$.binaries||J;console.log(j.blue("Creating backup..."));let Q=R.createBackupDirectory(),H=[];if(G){console.log(j.blue("Backing up shell configurations..."));let K=$1.join(Q,"configs");d.mkdirSync(K,{recursive:!0});let _=R.detectUserShell(),L=R.getAllShellConfigPaths(_),X=0;for(let q of L)if(d.existsSync(q.path)){if(R.backupFile(q.path,K,q.name))H.push(q.path),X++,console.log(j.green(` ✓ ${q.name}`))}if(X===0)console.log(j.yellow(" No configuration files found to backup"));else console.log(j.green(` Backed up ${X} configuration file(s)`))}if(Z){console.log(j.blue("Backing up binaries..."));let K=$1.join(Q,"binaries");d.mkdirSync(K,{recursive:!0});let _=R.getBinDirectory(),L=R.getMetadataFilePath();if(d.existsSync(L))R.backupFile(L,K,"metadata.json"),H.push(L);if(d.existsSync(_)){let X=d.readdirSync(_),q=0;for(let W of X){let M=$1.join(_,W);if(d.statSync(M).isFile()){if(R.backupFile(M,K,W))H.push(M),q++,console.log(j.green(` ✓ ${W}`))}}if(q===0)console.log(j.yellow(" No binaries found to backup"));else console.log(j.green(` Backed up ${q} binary(ies)`))}else console.log(j.yellow(" Bin directory not found"))}if(R.createBackupMetadata(Q,{type:"manual",command:"fbin backup",message:$.message||"Manual backup",files:H,config:G,binaries:Z}),R.updateLatestSymlink(Q),console.log(),console.log(j.green("✓ Backup created successfully!")),console.log(j.blue(` Location: ${Q}`)),console.log(j.blue(` Files backed up: ${H.length}`)),$.message)console.log(j.blue(` Message: ${$.message}`))}catch(Y){console.error(j.red(`Failed to create backup: ${Y.message}`)),process.exit(1)}},y1={command:j$,describe:F$,builder:x$,handler:C$};import m from"node:path";import F from"node:fs";import U from"chalk";import S$ from"@fnet/prompt";var D$="restore [options]",y$="Restore from backup",v$={config:{describe:"Restore shell configuration files",type:"boolean",default:!1,alias:"c"},binaries:{describe:"Restore installed binaries",type:"boolean",default:!1,alias:"b"},all:{describe:"Restore everything (configs + binaries)",type:"boolean",default:!1,alias:"a"},list:{describe:"List available backups",type:"boolean",default:!1,alias:"l"},timestamp:{describe:"Backup timestamp to restore (defaults to latest)",type:"string",alias:"t"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"}},P$=async($)=>{try{let Y=await z($);if($.list){let _=R.listBackups();if(_.length===0){console.log(U.yellow("No backups found."));return}console.log(U.blue(`Found ${_.length} backup(s):
|
|
15
|
-
`));let L=["TIMESTAMP","TYPE","MESSAGE","FILES"],X=p.createTable(L,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});for(let q of _){let W=q.timestamp||"unknown",M=q.type||"manual",T=q.message||"",N=q.files?q.files.length:0;X.push([U.white(W),M,T.substring(0,40)+(T.length>40?"...":""),N.toString()])}console.log(X.toString()),console.log(),console.log(U.blue(`Backup directory: ${R.getBackupDirectory()}`));return}let J=R.listBackups();if(J.length===0){console.log(U.yellow("No backups found.")),console.log(U.blue("Create a backup first with: fbin backup"));return}let G;if($.timestamp){if(G=J.find((_)=>_.timestamp===$.timestamp),!G)console.error(U.red(`Backup not found: ${$.timestamp}`)),console.log(U.yellow("Use --list to see available backups")),process.exit(1)}else if($.yes)G=J[0],console.log(U.yellow(`Auto-selecting latest backup: ${G.timestamp}`));else{let _=J.map((X)=>({name:X.timestamp,message:`${X.timestamp} - ${X.message||"No message"} (${X.files?.length||0} files)`})),L=await s.promptForSelection({items:_.map((X)=>X.name),message:"Select a backup to restore:",allowAbort:!0});if(L===null){console.log(U.yellow("Restore cancelled."));return}G=J.find((X)=>X.timestamp===L)}console.log(U.blue(`Restoring from backup: ${G.timestamp}`));let Z=$.all||!$.config&&!$.binaries,Q=$.config||Z,H=$.binaries||Z;if(!$.yes){let{confirmRestore:_}=await S$({type:"confirm",name:"confirmRestore",message:"This will overwrite current files. Continue?",initial:!1});if(!_){console.log(U.yellow("Restore cancelled."));return}}let K=0;if(Q){let _=m.join(G.path,"configs");if(F.existsSync(_)){console.log(U.blue("Restoring shell configurations..."));let L=F.readdirSync(_);for(let X of L){let q=m.join(_,X),W=R.detectUserShell(),T=R.getAllShellConfigPaths(W).find((N)=>N.name===X);if(T){let N=T.path,b=m.dirname(N);if(!F.existsSync(b))F.mkdirSync(b,{recursive:!0});F.copyFileSync(q,N),console.log(U.green(` ✓ ${X}`)),K++}}}}if(H){let _=m.join(G.path,"binaries");if(F.existsSync(_)){console.log(U.blue("Restoring binaries..."));let L=R.getBinDirectory();if(!F.existsSync(L))F.mkdirSync(L,{recursive:!0});let X=F.readdirSync(_);for(let q of X){let W=m.join(_,q),M=m.join(L,q);if(q==="metadata.json"){let T=R.getMetadataFilePath(),N=m.dirname(T);if(!F.existsSync(N))F.mkdirSync(N,{recursive:!0});F.copyFileSync(W,T),console.log(U.green(" ✓ metadata.json")),K++;continue}if(F.copyFileSync(W,M),process.platform!=="win32")F.chmodSync(M,493);console.log(U.green(` ✓ ${q}`)),K++}}}console.log(),console.log(U.green("✓ Restore completed successfully!")),console.log(U.blue(` Files restored: ${K}`))}catch(Y){console.error(U.red(`Failed to restore backup: ${Y.message}`)),process.exit(1)}},v1={command:D$,describe:y$,builder:v$,handler:P$};import d$ from"node:path";import Y1 from"node:fs";import V from"chalk";import m$ from"@fnet/prompt";var u$="cleanup [options]",k$="Clean up old backups",p$={keep:{describe:"Number of recent backups to keep",type:"number",default:10,alias:"k"},older:{describe:"Remove backups older than N days",type:"number",alias:"o"},all:{describe:"Remove all backups",type:"boolean",default:!1,alias:"a"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},"dry-run":{describe:"Show what would be deleted without actually deleting",type:"boolean",default:!1,alias:"d"}},f$=async($)=>{try{let Y=await z($),J=R.listBackups();if(J.length===0){console.log(V.yellow("No backups found."));return}console.log(V.blue(`Found ${J.length} backup(s)`));let G=[];if($.all)G=J;else if($.older){let X=new Date;X.setDate(X.getDate()-$.older),G=J.filter((q)=>{return new Date(q.created)<X}),console.log(V.blue(`Removing backups older than ${$.older} days (before ${X.toLocaleDateString()})`))}else if(J.length>$.keep)G=J.slice($.keep),console.log(V.blue(`Keeping ${$.keep} most recent backup(s), removing ${G.length} old backup(s)`));else{console.log(V.green(`Only ${J.length} backup(s) found, keeping all (limit: ${$.keep})`));return}if(G.length===0){console.log(V.green("No backups to delete."));return}console.log(),console.log(V.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 q=X.timestamp||"unknown",W=X.type||"manual",M=X.message||"",T=X.files?X.files.length:0,N=0;try{let i=(q1)=>{let t=0,u1=Y1.readdirSync(q1);for(let k1 of u1){let J1=d$.join(q1,k1),Q1=Y1.statSync(J1);if(Q1.isDirectory())t+=i(J1);else t+=Q1.size}return t};N=i(X.path),H+=N}catch(i){}let b=N>0?`${(N/1024/1024).toFixed(2)} MB`:"N/A";Q.push([V.white(q),W,M.substring(0,30)+(M.length>30?"...":""),T.toString(),b])}if(console.log(Q.toString()),console.log(),console.log(V.blue(`Total size to free: ${(H/1024/1024).toFixed(2)} MB`)),$["dry-run"]){console.log(),console.log(V.yellow("DRY RUN: No backups were deleted.")),console.log(V.blue("Run without --dry-run to actually delete these backups."));return}if(!$.yes){console.log();let{confirmDelete:X}=await m$({type:"confirm",name:"confirmDelete",message:`Delete ${G.length} backup(s)?`,initial:!1});if(!X){console.log(V.yellow("Cleanup cancelled."));return}}console.log(),console.log(V.blue("Deleting backups..."));let K=0,_=0;for(let X of G)try{Y1.rmSync(X.path,{recursive:!0,force:!0}),console.log(V.green(` ✓ ${X.timestamp}`)),K++}catch(q){console.log(V.red(` ✗ ${X.timestamp}: ${q.message}`)),_++}if(console.log(),console.log(V.green("✓ Cleanup completed!")),console.log(V.blue(` Deleted: ${K}`)),_>0)console.log(V.yellow(` Failed: ${_}`));console.log(V.blue(` Space freed: ${(H/1024/1024).toFixed(2)} MB`));let L=R.listBackups();console.log(V.blue(` Remaining backups: ${L.length}`))}catch(Y){console.error(V.red(`Failed to cleanup backups: ${Y.message}`)),process.exit(1)}},P1={command:u$,describe:k$,builder:p$,handler:f$};import{promisify as b$}from"node:util";import g$ from"tree-kill";var F0=b$(g$),r=!1;function d1(){process.on("uncaughtException",($)=>{if(!r)r=!0,setTimeout(()=>process.exit(1),500)}),process.on("unhandledRejection",($)=>{if(!r)r=!0,setTimeout(()=>process.exit(1),500)})}d1();M1();async function l$(){try{h$(o$(process.argv)).scriptName("fbin").usage("Usage: $0 <command> [options]").command(T1).command(B1).command(j1).command(F1).command(C1).command(D1).command(y1).command(v1).command(P1).demandCommand(1,"You need to specify a command").help().version("1.
|
|
15
|
+
`));let L=["TIMESTAMP","TYPE","MESSAGE","FILES"],X=p.createTable(L,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});for(let q of _){let W=q.timestamp||"unknown",M=q.type||"manual",T=q.message||"",N=q.files?q.files.length:0;X.push([U.white(W),M,T.substring(0,40)+(T.length>40?"...":""),N.toString()])}console.log(X.toString()),console.log(),console.log(U.blue(`Backup directory: ${R.getBackupDirectory()}`));return}let J=R.listBackups();if(J.length===0){console.log(U.yellow("No backups found.")),console.log(U.blue("Create a backup first with: fbin backup"));return}let G;if($.timestamp){if(G=J.find((_)=>_.timestamp===$.timestamp),!G)console.error(U.red(`Backup not found: ${$.timestamp}`)),console.log(U.yellow("Use --list to see available backups")),process.exit(1)}else if($.yes)G=J[0],console.log(U.yellow(`Auto-selecting latest backup: ${G.timestamp}`));else{let _=J.map((X)=>({name:X.timestamp,message:`${X.timestamp} - ${X.message||"No message"} (${X.files?.length||0} files)`})),L=await s.promptForSelection({items:_.map((X)=>X.name),message:"Select a backup to restore:",allowAbort:!0});if(L===null){console.log(U.yellow("Restore cancelled."));return}G=J.find((X)=>X.timestamp===L)}console.log(U.blue(`Restoring from backup: ${G.timestamp}`));let Z=$.all||!$.config&&!$.binaries,Q=$.config||Z,H=$.binaries||Z;if(!$.yes){let{confirmRestore:_}=await S$({type:"confirm",name:"confirmRestore",message:"This will overwrite current files. Continue?",initial:!1});if(!_){console.log(U.yellow("Restore cancelled."));return}}let K=0;if(Q){let _=m.join(G.path,"configs");if(F.existsSync(_)){console.log(U.blue("Restoring shell configurations..."));let L=F.readdirSync(_);for(let X of L){let q=m.join(_,X),W=R.detectUserShell(),T=R.getAllShellConfigPaths(W).find((N)=>N.name===X);if(T){let N=T.path,b=m.dirname(N);if(!F.existsSync(b))F.mkdirSync(b,{recursive:!0});F.copyFileSync(q,N),console.log(U.green(` ✓ ${X}`)),K++}}}}if(H){let _=m.join(G.path,"binaries");if(F.existsSync(_)){console.log(U.blue("Restoring binaries..."));let L=R.getBinDirectory();if(!F.existsSync(L))F.mkdirSync(L,{recursive:!0});let X=F.readdirSync(_);for(let q of X){let W=m.join(_,q),M=m.join(L,q);if(q==="metadata.json"){let T=R.getMetadataFilePath(),N=m.dirname(T);if(!F.existsSync(N))F.mkdirSync(N,{recursive:!0});F.copyFileSync(W,T),console.log(U.green(" ✓ metadata.json")),K++;continue}if(F.copyFileSync(W,M),process.platform!=="win32")F.chmodSync(M,493);console.log(U.green(` ✓ ${q}`)),K++}}}console.log(),console.log(U.green("✓ Restore completed successfully!")),console.log(U.blue(` Files restored: ${K}`))}catch(Y){console.error(U.red(`Failed to restore backup: ${Y.message}`)),process.exit(1)}},v1={command:D$,describe:y$,builder:v$,handler:P$};import d$ from"node:path";import Y1 from"node:fs";import V from"chalk";import m$ from"@fnet/prompt";var u$="cleanup [options]",k$="Clean up old backups",p$={keep:{describe:"Number of recent backups to keep",type:"number",default:10,alias:"k"},older:{describe:"Remove backups older than N days",type:"number",alias:"o"},all:{describe:"Remove all backups",type:"boolean",default:!1,alias:"a"},yes:{describe:"Automatically answer yes to all prompts",type:"boolean",default:!1,alias:"y"},"dry-run":{describe:"Show what would be deleted without actually deleting",type:"boolean",default:!1,alias:"d"}},f$=async($)=>{try{let Y=await z($),J=R.listBackups();if(J.length===0){console.log(V.yellow("No backups found."));return}console.log(V.blue(`Found ${J.length} backup(s)`));let G=[];if($.all)G=J;else if($.older){let X=new Date;X.setDate(X.getDate()-$.older),G=J.filter((q)=>{return new Date(q.created)<X}),console.log(V.blue(`Removing backups older than ${$.older} days (before ${X.toLocaleDateString()})`))}else if(J.length>$.keep)G=J.slice($.keep),console.log(V.blue(`Keeping ${$.keep} most recent backup(s), removing ${G.length} old backup(s)`));else{console.log(V.green(`Only ${J.length} backup(s) found, keeping all (limit: ${$.keep})`));return}if(G.length===0){console.log(V.green("No backups to delete."));return}console.log(),console.log(V.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 q=X.timestamp||"unknown",W=X.type||"manual",M=X.message||"",T=X.files?X.files.length:0,N=0;try{let i=(q1)=>{let t=0,u1=Y1.readdirSync(q1);for(let k1 of u1){let J1=d$.join(q1,k1),Q1=Y1.statSync(J1);if(Q1.isDirectory())t+=i(J1);else t+=Q1.size}return t};N=i(X.path),H+=N}catch(i){}let b=N>0?`${(N/1024/1024).toFixed(2)} MB`:"N/A";Q.push([V.white(q),W,M.substring(0,30)+(M.length>30?"...":""),T.toString(),b])}if(console.log(Q.toString()),console.log(),console.log(V.blue(`Total size to free: ${(H/1024/1024).toFixed(2)} MB`)),$["dry-run"]){console.log(),console.log(V.yellow("DRY RUN: No backups were deleted.")),console.log(V.blue("Run without --dry-run to actually delete these backups."));return}if(!$.yes){console.log();let{confirmDelete:X}=await m$({type:"confirm",name:"confirmDelete",message:`Delete ${G.length} backup(s)?`,initial:!1});if(!X){console.log(V.yellow("Cleanup cancelled."));return}}console.log(),console.log(V.blue("Deleting backups..."));let K=0,_=0;for(let X of G)try{Y1.rmSync(X.path,{recursive:!0,force:!0}),console.log(V.green(` ✓ ${X.timestamp}`)),K++}catch(q){console.log(V.red(` ✗ ${X.timestamp}: ${q.message}`)),_++}if(console.log(),console.log(V.green("✓ Cleanup completed!")),console.log(V.blue(` Deleted: ${K}`)),_>0)console.log(V.yellow(` Failed: ${_}`));console.log(V.blue(` Space freed: ${(H/1024/1024).toFixed(2)} MB`));let L=R.listBackups();console.log(V.blue(` Remaining backups: ${L.length}`))}catch(Y){console.error(V.red(`Failed to cleanup backups: ${Y.message}`)),process.exit(1)}},P1={command:u$,describe:k$,builder:p$,handler:f$};import{promisify as b$}from"node:util";import g$ from"tree-kill";var F0=b$(g$),r=!1;function d1(){process.on("uncaughtException",($)=>{if(!r)r=!0,setTimeout(()=>process.exit(1),500)}),process.on("unhandledRejection",($)=>{if(!r)r=!0,setTimeout(()=>process.exit(1),500)})}d1();M1();async function l$(){try{h$(o$(process.argv)).scriptName("fbin").usage("Usage: $0 <command> [options]").command(T1).command(B1).command(j1).command(F1).command(C1).command(D1).command(y1).command(v1).command(P1).demandCommand(1,"You need to specify a command").help().version("1.5.0").parse()}catch($){console.error(m1.red(`Fatal error: ${$.message}`)),process.exit(1)}}l$().catch(($)=>{console.error(m1.red(`Fatal error: ${$.message}`)),process.exit(1)});
|
package/dist/fnet/index.js
CHANGED
|
@@ -17,4 +17,4 @@ Express Projects:`));let q=(await import("./index.tnk86191.js")).default,Y=["NAM
|
|
|
17
17
|
Total: ${X.length} projects`))}catch(Z){console.error(F.red(`Error listing express projects: ${Z.message}`)),process.exit(1)}}async function A1(Q){try{if(!N.existsSync(c)){console.log(F.yellow("No express projects found."));return}let Z;if(Q.latest){if(Z=await a8(),!Z){console.log(F.yellow("No express projects found."));return}}else if(Q.projectName){if(Z=await n8(Q.projectName),!Z){console.log(F.yellow(`Project "${Q.projectName}" not found.`));return}}else{let X=await r8();if(!X){console.log(F.yellow("No project selected."));return}Z=P.join(c,X)}await k7(Z)}catch(Z){console.error(F.red(`Error opening express project: ${Z.message}`)),process.exit(1)}}async function R1(Q){try{let Z=process.cwd(),X=Z.includes(c),q;if(X)q=Z,console.log(F.blue(`Using current express project: ${P.basename(q)}`));else if(Q.latest){if(q=await a8(),!q){console.log(F.yellow("No express projects found."));return}}else if(Q.projectName){if(q=await n8(Q.projectName),!q){console.log(F.yellow(`Project "${Q.projectName}" not found.`));return}}else{let H=await r8();if(!H){console.log(F.yellow("No project selected."));return}q=P.join(c,H)}let Y=Q.destination;if(!Y)Y=(await T0({type:"input",name:"destination",message:"Enter destination directory:",initial:P.join(process.cwd(),P.basename(q))})).destination;if(Y.startsWith("~"))Y=P.join(p8.homedir(),Y.slice(1));if(Y=P.resolve(Y),Y.startsWith(q+P.sep)||Y===q){console.log(F.red("Destination cannot be inside the source directory."));return}if(N.existsSync(Y)){if(!N.statSync(Y).isDirectory()){console.log(F.red(`Destination "${Y}" is not a directory.`));return}if(N.readdirSync(Y).length>0){if(!(await T0({type:"confirm",name:"overwrite",message:`Destination "${Y}" is not empty. Continue anyway?`,initial:!1})).overwrite){console.log(F.yellow("Project move cancelled."));return}}}else N.mkdirSync(Y,{recursive:!0});if(console.log(F.blue(`Moving project from ${q} to ${Y}...`)),UZ(q,Y),console.log(F.green(`
|
|
18
18
|
Project moved successfully to ${Y}`)),(await T0({type:"confirm",name:"deleteOriginal",message:"Delete the original express project?",initial:!1})).deleteOriginal)N.rmSync(q,{recursive:!0,force:!0}),console.log(F.green("Original project deleted."));await k7(Y)}catch(Z){console.error(F.red(`Error moving express project: ${Z.message}`)),process.exit(1)}}async function a8(){let Q=N.readdirSync(c).filter((H)=>/^\d{8}$/.test(H)).sort((H,W)=>W.localeCompare(H));if(Q.length===0)return null;let Z=Q[0],X=P.join(c,Z),q=N.readdirSync(X);if(q.length===0)return null;let Y=null,J=0;for(let H of q){let W=P.join(X,H),V=N.statSync(W);if(V.birthtimeMs>J)J=V.birthtimeMs,Y=W}return Y}async function n8(Q){let Z=N.readdirSync(c).filter((X)=>/^\d{8}$/.test(X)).sort((X,q)=>q.localeCompare(X));for(let X of Z){let q=P.join(c,X),Y=N.readdirSync(q);if(Y.includes(Q))return P.join(q,Q);let J=Y.filter((H)=>H.includes(Q));if(J.length>0)if(J.length===1)return P.join(q,J[0]);else{let H=J.map((V)=>({name:P.join(q,V),value:P.join(q,V),message:`${V} (${X})`})),W=await P7.promptForSelection({items:H,message:`Multiple projects match "${Q}". Please select one:`,nameField:"message",valueField:"value",allowAbort:!0});if(W===null)return console.log(F.yellow("Operation cancelled.")),null;return W}}return null}async function r8(){let Q=[],Z=N.readdirSync(c).filter((q)=>/^\d{8}$/.test(q)).sort((q,Y)=>Y.localeCompare(q));for(let q of Z){let Y=P.join(c,q),J=N.readdirSync(Y);for(let H of J){let W=P.join(Y,H),V=N.statSync(W),K=`${q}/${H}`;Q.push({name:K,value:K,created:V.birthtime})}}if(Q.sort((q,Y)=>Y.created-q.created),Q.length===0)return null;let X=await P7.promptForSelection({items:Q,message:"Select a project:",nameField:"value",valueField:"value",allowAbort:!0});if(X===null)return console.log(F.yellow("Operation cancelled.")),null;return X}async function B1(Q){try{if((await T0({type:"confirm",name:"openIDE",message:"Would you like to open the project in an IDE?",initial:!0})).openIDE)await k7(Q)}catch(Z){console.error(F.red(`Error opening IDE: ${Z.message}`))}}async function k7(Q){let Z=await zZ("code --version"),X=await zZ("code-insiders --version"),q=null;if(Z&&X)q=(await T0({type:"select",name:"ide",message:"Which IDE would you like to use?",choices:[{name:"Visual Studio Code",value:"code"},{name:"Visual Studio Code Insiders",value:"code-insiders"}]})).ide;else if(Z)q="code";else if(X)q="code-insiders";else{console.log(F.yellow("No supported IDE found. Please open the project manually.")),console.log(F.blue(`Project path: ${Q}`));return}console.log(F.blue(`Opening project in ${q}...`)),console.log(F.blue(`Project path: ${Q}`));let Y=i8(q,[Q],{stdio:"inherit",shell:!0});return new Promise((J,H)=>{Y.on("close",(W)=>{if(W===0)console.log(F.green(`Project opened in ${q}.`)),J();else console.error(F.red(`Failed to open project in ${q}.`)),H(Error(`Process exited with code ${W}`))})})}async function zZ(Q){return new Promise((Z)=>{i8(Q,{shell:!0,stdio:"ignore"}).on("close",(q)=>{Z(q===0)})})}function UZ(Q,Z){if(!N.existsSync(Z))N.mkdirSync(Z,{recursive:!0});let X=N.readdirSync(Q,{withFileTypes:!0});for(let q of X){let Y=P.join(Q,q.name),J=P.join(Z,q.name);if(q.isDirectory()){if(q.name===".git"||q.name===".workspace")continue;UZ(Y,J)}else N.copyFileSync(Y,J)}}async function I1(Q){try{if(!N.existsSync(c)){console.log(F.yellow("No express projects found."));return}let Z;if(Q.latest){if(Z=await a8(),!Z){console.log(F.yellow("No express projects found."));return}}else if(Q.projectName){if(Z=await n8(Q.projectName),!Z){console.log(F.yellow(`Project "${Q.projectName}" not found.`));return}}else{let q=await r8();if(!q){console.log(F.yellow("No project selected."));return}Z=P.join(c,q)}let X=P.basename(Z);if(!Q.yes){if(!(await T0({type:"confirm",name:"confirm",message:`Are you sure you want to remove project "${X}"?`,initial:!1})).confirm){console.log(F.yellow("Project removal cancelled."));return}}console.log(F.blue(`Removing project "${X}"...`)),N.rmSync(Z,{recursive:!0,force:!0}),console.log(F.green(`Project "${X}" removed successfully.`))}catch(Z){console.error(F.red(`Error removing express project: ${Z.message}`)),process.exit(1)}}async function L1(Q){try{if(!N.existsSync(c)){console.log(F.yellow("No express projects found."));return}let Z;if(Q.latest){if(Z=await a8(),!Z){console.log(F.yellow("No express projects found."));return}}else if(Q.projectName){if(Z=await n8(Q.projectName),!Z){console.log(F.yellow(`Project "${Q.projectName}" not found.`));return}}else{let Y=await r8();if(!Y){console.log(F.yellow("No project selected."));return}Z=P.join(c,Y)}console.log(F.blue(`Entering project directory: ${Z}`)),console.log(F.yellow(`
|
|
19
19
|
Opening a new shell in the project directory...`));let X=process.env.SHELL||"/bin/bash",q=i8(X,[],{stdio:"inherit",cwd:Z,shell:!0});return new Promise((Y)=>{q.on("close",()=>{console.log(F.green(`
|
|
20
|
-
Returned from project directory.`)),Y()})})}catch(Z){console.error(F.red(`Error entering express project directory: ${Z.message}`)),process.exit(1)}}import MZ from"node:path";import{fileURLToPath as w1}from"node:url";import F1 from"node:fs";import s8 from"node:path";import{fileURLToPath as T1}from"node:url";var j1=s8.dirname(T1(import.meta.url));function C1({baseDir:Q}){Q=Q||j1;let Z=Q;while(Z!==s8.parse(Z).root){let X=s8.join(Z,"node_modules");if(F1.existsSync(X))return X;Z=s8.dirname(Z)}return null}var $Z=C1;var S1=MZ.dirname(w1(import.meta.url));function OZ(){let Q=$Z({baseDir:S1}),Z=process.platform==="win32"?";":":";if(Q)process.env.PATH=`${MZ.join(Q,"/.bin")}${Z}${process.env.PATH}`}var D7=new P1;OZ();async function k1(){try{let Q=N1(process.argv.slice(2)).scriptName("fnet").usage("Usage: fnet <command> [options]").command(d7).command(p7).command(YZ).command(JZ).command(WZ).command(HZ).command(KZ).command("express","Create and manage express projects",GZ);Q=s(Q,{bin:"npm",createContext:b}),Q=s(Q,{bin:"node",createContext:b}),Q=s(Q,{bin:"bun",createContext:b}),Q=s(Q,{name:"serve",bin:"bun",preArgs:["run","serve","--"],createContext:b}),Q=s(Q,{name:"watch",bin:"bun",preArgs:["run","watch","--"],createContext:b}),Q=s(Q,{name:"app",bin:"bun",preArgs:["run","app","--"],createContext:b}),Q=s(Q,{name:"cli",bin:"bun",preArgs:["run","cli","--"],createContext:b}),Q=s(Q,{name:"cli:dev",bin:"bun",preArgs:["run","cli:dev","--"],createContext:b}),Q=s(Q,{name:"cli:compile",bin:"bun",preArgs:["run","cli:compile","--"],createContext:b}),Q=s(Q,{name:"cli:compile:dev",bin:"bun",preArgs:["run","cli:compile:dev","--"],createContext:b}),Q=s(Q,{name:"cli:install",bin:"bun",preArgs:["run","cli:install","--"],createContext:b}),Q=s(Q,{name:"compile",bin:"bun",preArgs:["run","compile","--"],createContext:b}),Q=c7(Q,{name:"install",createContext:b}),Q=s(Q,{bin:"npx",createContext:b}),Q=s(Q,{bin:"cdk",createContext:b}),Q=s(Q,{bin:"aws",createContext:b}),Q=g7(Q,{name:"with",createContext:b}),Q=m7(Q,{name:"run",projectType:"fnet",processManager:D7}),Q.demandCommand(1,"You need at least one command before moving on").help().version("1.
|
|
20
|
+
Returned from project directory.`)),Y()})})}catch(Z){console.error(F.red(`Error entering express project directory: ${Z.message}`)),process.exit(1)}}import MZ from"node:path";import{fileURLToPath as w1}from"node:url";import F1 from"node:fs";import s8 from"node:path";import{fileURLToPath as T1}from"node:url";var j1=s8.dirname(T1(import.meta.url));function C1({baseDir:Q}){Q=Q||j1;let Z=Q;while(Z!==s8.parse(Z).root){let X=s8.join(Z,"node_modules");if(F1.existsSync(X))return X;Z=s8.dirname(Z)}return null}var $Z=C1;var S1=MZ.dirname(w1(import.meta.url));function OZ(){let Q=$Z({baseDir:S1}),Z=process.platform==="win32"?";":":";if(Q)process.env.PATH=`${MZ.join(Q,"/.bin")}${Z}${process.env.PATH}`}var D7=new P1;OZ();async function k1(){try{let Q=N1(process.argv.slice(2)).scriptName("fnet").usage("Usage: fnet <command> [options]").command(d7).command(p7).command(YZ).command(JZ).command(WZ).command(HZ).command(KZ).command("express","Create and manage express projects",GZ);Q=s(Q,{bin:"npm",createContext:b}),Q=s(Q,{bin:"node",createContext:b}),Q=s(Q,{bin:"bun",createContext:b}),Q=s(Q,{name:"serve",bin:"bun",preArgs:["run","serve","--"],createContext:b}),Q=s(Q,{name:"watch",bin:"bun",preArgs:["run","watch","--"],createContext:b}),Q=s(Q,{name:"app",bin:"bun",preArgs:["run","app","--"],createContext:b}),Q=s(Q,{name:"cli",bin:"bun",preArgs:["run","cli","--"],createContext:b}),Q=s(Q,{name:"cli:dev",bin:"bun",preArgs:["run","cli:dev","--"],createContext:b}),Q=s(Q,{name:"cli:compile",bin:"bun",preArgs:["run","cli:compile","--"],createContext:b}),Q=s(Q,{name:"cli:compile:dev",bin:"bun",preArgs:["run","cli:compile:dev","--"],createContext:b}),Q=s(Q,{name:"cli:install",bin:"bun",preArgs:["run","cli:install","--"],createContext:b}),Q=s(Q,{name:"compile",bin:"bun",preArgs:["run","compile","--"],createContext:b}),Q=c7(Q,{name:"install",createContext:b}),Q=s(Q,{bin:"npx",createContext:b}),Q=s(Q,{bin:"cdk",createContext:b}),Q=s(Q,{bin:"aws",createContext:b}),Q=g7(Q,{name:"with",createContext:b}),Q=m7(Q,{name:"run",projectType:"fnet",processManager:D7}),Q.demandCommand(1,"You need at least one command before moving on").help().version("1.5.0").parse()}catch(Q){console.error(AZ.red(`Fatal error: ${Q.message}`)),await D7.dispose(),process.exit(1)}}k1().catch(async(Q)=>{console.error(AZ.red(`Fatal error: ${Q.message}`)),await D7.dispose(),process.exit(1)});
|
package/dist/fnode/index.js
CHANGED
|
@@ -7,4 +7,4 @@ Express Projects:`));let Q=(await import("./index.xw4a37ev.js")).default,$=["NAM
|
|
|
7
7
|
Total: ${Z.length} projects`))}catch(z){console.error(J.red(`Error listing express projects: ${z.message}`)),process.exit(1)}}async function nq(q){try{if(!L.existsSync(T)){console.log(J.yellow("No express projects found."));return}let z;if(q.latest){if(z=await h(),!z){console.log(J.yellow("No express projects found."));return}}else if(q.projectName){if(z=await p(q.projectName),!z){console.log(J.yellow(`Project "${q.projectName}" not found.`));return}}else{let Z=await l();if(!Z){console.log(J.yellow("No project selected."));return}z=M.join(T,Z)}await o(z)}catch(z){console.error(J.red(`Error opening express project: ${z.message}`)),process.exit(1)}}async function cq(q){try{let z=process.cwd(),Z=z.includes(T),Q;if(Z)Q=z,console.log(J.blue(`Using current express project: ${M.basename(Q)}`));else if(q.latest){if(Q=await h(),!Q){console.log(J.yellow("No express projects found."));return}}else if(q.projectName){if(Q=await p(q.projectName),!Q){console.log(J.yellow(`Project "${q.projectName}" not found.`));return}}else{let G=await l();if(!G){console.log(J.yellow("No project selected."));return}Q=M.join(T,G)}let $=q.destination;if(!$)$=(await N({type:"input",name:"destination",message:"Enter destination directory:",initial:M.join(process.cwd(),M.basename(Q))})).destination;if($.startsWith("~"))$=M.join(u.homedir(),$.slice(1));if($=M.resolve($),$.startsWith(Q+M.sep)||$===Q){console.log(J.red("Destination cannot be inside the source directory."));return}if(L.existsSync($)){if(!L.statSync($).isDirectory()){console.log(J.red(`Destination "${$}" is not a directory.`));return}if(L.readdirSync($).length>0){if(!(await N({type:"confirm",name:"overwrite",message:`Destination "${$}" is not empty. Continue anyway?`,initial:!1})).overwrite){console.log(J.yellow("Project move cancelled."));return}}}else L.mkdirSync($,{recursive:!0});if(console.log(J.blue(`Moving project from ${Q} to ${$}...`)),Xq(Q,$),console.log(J.green(`
|
|
8
8
|
Project moved successfully to ${$}`)),(await N({type:"confirm",name:"deleteOriginal",message:"Delete the original express project?",initial:!1})).deleteOriginal)L.rmSync(Q,{recursive:!0,force:!0}),console.log(J.green("Original project deleted."));await o($)}catch(z){console.error(J.red(`Error moving express project: ${z.message}`)),process.exit(1)}}async function h(){let q=L.readdirSync(T).filter((G)=>/^\d{8}$/.test(G)).sort((G,K)=>K.localeCompare(G));if(q.length===0)return null;let z=q[0],Z=M.join(T,z),Q=L.readdirSync(Z);if(Q.length===0)return null;let $=null,W=0;for(let G of Q){let K=M.join(Z,G),O=L.statSync(K);if(O.birthtimeMs>W)W=O.birthtimeMs,$=K}return $}async function p(q){let z=L.readdirSync(T).filter((Z)=>/^\d{8}$/.test(Z)).sort((Z,Q)=>Q.localeCompare(Z));for(let Z of z){let Q=M.join(T,Z),$=L.readdirSync(Q);if($.includes(q))return M.join(Q,q);let W=$.filter((G)=>G.includes(q));if(W.length>0)if(W.length===1)return M.join(Q,W[0]);else{let G=W.map((O)=>({name:M.join(Q,O),value:M.join(Q,O),message:`${O} (${Z})`})),K=await i.promptForSelection({items:G,message:`Multiple projects match "${q}". Please select one:`,nameField:"message",valueField:"value",allowAbort:!0});if(K===null)return console.log(J.yellow("Operation cancelled.")),null;return K}}return null}async function l(){let q=[],z=L.readdirSync(T).filter((Q)=>/^\d{8}$/.test(Q)).sort((Q,$)=>$.localeCompare(Q));for(let Q of z){let $=M.join(T,Q),W=L.readdirSync($);for(let G of W){let K=M.join($,G),O=L.statSync(K),H=`${Q}/${G}`;q.push({name:H,value:H,message:`${G} (${Q})`,created:O.birthtime})}}if(q.sort((Q,$)=>$.created-Q.created),q.length===0)return null;let Z=await i.promptForSelection({items:q,message:"Select a project:",nameField:"message",valueField:"value",allowAbort:!0});if(Z===null)return console.log(J.yellow("Operation cancelled.")),null;return Z}async function sq(q){try{if((await N({type:"confirm",name:"openIDE",message:"Would you like to open the project in an IDE?",initial:!0})).openIDE)await o(q)}catch(z){console.error(J.red(`Error opening IDE: ${z.message}`))}}async function o(q){let z=await Vq("code --version"),Z=await Vq("code-insiders --version"),Q=null;if(z&&Z)Q=(await N({type:"select",name:"ide",message:"Which IDE would you like to use?",choices:[{name:"Visual Studio Code",value:"code"},{name:"Visual Studio Code Insiders",value:"code-insiders"}]})).ide;else if(z)Q="code";else if(Z)Q="code-insiders";else{console.log(J.yellow("No supported IDE found. Please open the project manually.")),console.log(J.blue(`Project path: ${q}`));return}console.log(J.blue(`Opening project in ${Q}...`)),console.log(J.blue(`Project path: ${q}`));let $=g(Q,[q],{stdio:"inherit",shell:!0});return new Promise((W,G)=>{$.on("close",(K)=>{if(K===0)console.log(J.green(`Project opened in ${Q}.`)),W();else console.error(J.red(`Failed to open project in ${Q}.`)),G(Error(`Process exited with code ${K}`))})})}async function Vq(q){return new Promise((z)=>{g(q,{shell:!0,stdio:"ignore"}).on("close",(Q)=>{z(Q===0)})})}function Xq(q,z){if(!L.existsSync(z))L.mkdirSync(z,{recursive:!0});let Z=L.readdirSync(q,{withFileTypes:!0});for(let Q of Z){let $=M.join(q,Q.name),W=M.join(z,Q.name);if(Q.isDirectory()){if(Q.name===".git"||Q.name===".workspace")continue;Xq($,W)}else L.copyFileSync($,W)}}async function iq(q){try{if(!L.existsSync(T)){console.log(J.yellow("No express projects found."));return}let z;if(q.latest){if(z=await h(),!z){console.log(J.yellow("No express projects found."));return}}else if(q.projectName){if(z=await p(q.projectName),!z){console.log(J.yellow(`Project "${q.projectName}" not found.`));return}}else{let Q=await l();if(!Q){console.log(J.yellow("No project selected."));return}z=M.join(T,Q)}let Z=M.basename(z);if(!q.yes){if(!(await N({type:"confirm",name:"confirm",message:`Are you sure you want to remove project "${Z}"?`,initial:!1})).confirm){console.log(J.yellow("Project removal cancelled."));return}}console.log(J.blue(`Removing project "${Z}"...`)),L.rmSync(z,{recursive:!0,force:!0}),console.log(J.green(`Project "${Z}" removed successfully.`))}catch(z){console.error(J.red(`Error removing express project: ${z.message}`)),process.exit(1)}}async function oq(q){try{if(!L.existsSync(T)){console.log(J.yellow("No express projects found."));return}let z;if(q.latest){if(z=await h(),!z){console.log(J.yellow("No express projects found."));return}}else if(q.projectName){if(z=await p(q.projectName),!z){console.log(J.yellow(`Project "${q.projectName}" not found.`));return}}else{let $=await l();if(!$){console.log(J.yellow("No project selected."));return}z=M.join(T,$)}console.log(J.blue(`Entering project directory: ${z}`)),console.log(J.yellow(`
|
|
9
9
|
Opening a new shell in the project directory...`));let Z=process.env.SHELL||"/bin/bash",Q=g(Z,[],{stdio:"inherit",cwd:z,shell:!0});return new Promise(($)=>{Q.on("close",()=>{console.log(J.green(`
|
|
10
|
-
Returned from project directory.`)),$()})})}catch(z){console.error(J.red(`Error entering express project directory: ${z.message}`)),process.exit(1)}}import wq from"node:path";import{fileURLToPath as qz}from"node:url";import aq from"node:fs";import d from"node:path";import{fileURLToPath as rq}from"node:url";var tq=d.dirname(rq(import.meta.url));function eq({baseDir:q}){q=q||tq;let z=q;while(z!==d.parse(z).root){let Z=d.join(z,"node_modules");if(aq.existsSync(Z))return Z;z=d.dirname(z)}return null}var Tq=eq;var zz=wq.dirname(qz(import.meta.url));function Iq(){let q=Tq({baseDir:zz}),z=process.platform==="win32"?";":":";if(q)process.env.PATH=`${wq.join(q,"/.bin")}${z}${process.env.PATH}`}var a=new Zz;Iq();async function $z(){try{let q=Qz(process.argv.slice(2)).scriptName("fnode").usage("Usage: fnode <command> [options]").command($q).command(Gq).command(Kq).command(Yq).command(Jq).command(Uq).command(Lq).command("express","Create and manage express projects",Mq);q=w(q,{bin:"npm",createContext:V}),q=w(q,{bin:"node",createContext:V}),q=w(q,{bin:"bun",createContext:V}),q=w(q,{name:"serve",bin:"bun",preArgs:["run","serve","--"],createContext:V}),q=w(q,{name:"watch",bin:"bun",preArgs:["run","watch","--"],createContext:V}),q=w(q,{name:"app",bin:"bun",preArgs:["run","app","--"],createContext:V}),q=w(q,{name:"cli",bin:"bun",preArgs:["run","cli","--"],createContext:V}),q=w(q,{name:"cli:dev",bin:"bun",preArgs:["run","cli:dev","--"],createContext:V}),q=w(q,{name:"cli:compile",bin:"bun",preArgs:["run","cli:compile","--"],createContext:V}),q=w(q,{name:"cli:compile:dev",bin:"bun",preArgs:["run","cli:compile:dev","--"],createContext:V}),q=w(q,{name:"cli:install",bin:"bun",preArgs:["run","cli:install","--"],createContext:V}),q=w(q,{name:"compile",bin:"bun",preArgs:["run","compile","--"],createContext:V}),q=zq(q,{name:"install",createContext:V}),q=w(q,{bin:"npx",createContext:V}),q=w(q,{bin:"cdk",createContext:V}),q=w(q,{bin:"aws",createContext:V}),q=e(q,{name:"with",createContext:V}),q=qq(q,{name:"run",projectType:"fnode",processManager:a}),q=y(q,{name:"python",createContext:V}),q=y(q,{name:"python3",createContext:V}),q=y(q,{name:"pip",createContext:V}),q=y(q,{name:"pip3",createContext:V}),q=t(q,{name:"bin",createContext:V}),q.demandCommand(1,"You need at least one command before moving on").help().version("1.
|
|
10
|
+
Returned from project directory.`)),$()})})}catch(z){console.error(J.red(`Error entering express project directory: ${z.message}`)),process.exit(1)}}import wq from"node:path";import{fileURLToPath as qz}from"node:url";import aq from"node:fs";import d from"node:path";import{fileURLToPath as rq}from"node:url";var tq=d.dirname(rq(import.meta.url));function eq({baseDir:q}){q=q||tq;let z=q;while(z!==d.parse(z).root){let Z=d.join(z,"node_modules");if(aq.existsSync(Z))return Z;z=d.dirname(z)}return null}var Tq=eq;var zz=wq.dirname(qz(import.meta.url));function Iq(){let q=Tq({baseDir:zz}),z=process.platform==="win32"?";":":";if(q)process.env.PATH=`${wq.join(q,"/.bin")}${z}${process.env.PATH}`}var a=new Zz;Iq();async function $z(){try{let q=Qz(process.argv.slice(2)).scriptName("fnode").usage("Usage: fnode <command> [options]").command($q).command(Gq).command(Kq).command(Yq).command(Jq).command(Uq).command(Lq).command("express","Create and manage express projects",Mq);q=w(q,{bin:"npm",createContext:V}),q=w(q,{bin:"node",createContext:V}),q=w(q,{bin:"bun",createContext:V}),q=w(q,{name:"serve",bin:"bun",preArgs:["run","serve","--"],createContext:V}),q=w(q,{name:"watch",bin:"bun",preArgs:["run","watch","--"],createContext:V}),q=w(q,{name:"app",bin:"bun",preArgs:["run","app","--"],createContext:V}),q=w(q,{name:"cli",bin:"bun",preArgs:["run","cli","--"],createContext:V}),q=w(q,{name:"cli:dev",bin:"bun",preArgs:["run","cli:dev","--"],createContext:V}),q=w(q,{name:"cli:compile",bin:"bun",preArgs:["run","cli:compile","--"],createContext:V}),q=w(q,{name:"cli:compile:dev",bin:"bun",preArgs:["run","cli:compile:dev","--"],createContext:V}),q=w(q,{name:"cli:install",bin:"bun",preArgs:["run","cli:install","--"],createContext:V}),q=w(q,{name:"compile",bin:"bun",preArgs:["run","compile","--"],createContext:V}),q=zq(q,{name:"install",createContext:V}),q=w(q,{bin:"npx",createContext:V}),q=w(q,{bin:"cdk",createContext:V}),q=w(q,{bin:"aws",createContext:V}),q=e(q,{name:"with",createContext:V}),q=qq(q,{name:"run",projectType:"fnode",processManager:a}),q=y(q,{name:"python",createContext:V}),q=y(q,{name:"python3",createContext:V}),q=y(q,{name:"pip",createContext:V}),q=y(q,{name:"pip3",createContext:V}),q=t(q,{name:"bin",createContext:V}),q.demandCommand(1,"You need at least one command before moving on").help().version("1.5.0").parse()}catch(q){console.error(_q.red(`Fatal error: ${q.message}`)),await a.dispose(),process.exit(1)}}$z().catch(async(q)=>{console.error(_q.red(`Fatal error: ${q.message}`)),await a.dispose(),process.exit(1)});
|
package/dist/frun/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import C from"yargs";import{hideBin as T}from"yargs/helpers";import{ProcessManager as Y}from"@fnet/shell-flow";import _ from"fs";import x from"path";import W from"chalk";import H from"@fnet/yaml";import b,{ProcessManager as y}from"@fnet/shell-flow";function w(q){if(Array.isArray(q))return q;if(q&&typeof q==="object"&&q.steps)return q.steps;return q}async function L({projectType:q,group:A,tags:D,args:E,argv:J,processManager:U}){try{let I=await S(q),{parsed:X}=await H({file:I.path,tags:D}),V=X.commands;if(!V)throw Error(`Commands section not found in ${I.name}`);let Q=V[A];if(!Q)throw Error(`Command group '${A}' not found in ${I.name}`);let Z=w(Q);await b({commands:Z,context:{args:E,argv:J,projectType:I.type},processManager:U})}catch(I){console.error(`Error: ${I.message}`),process.exit(1)}}async function O({projectType:q,tags:A}){try{let D=await S(q),{parsed:E}=await H({file:D.path,tags:A}),J=E.commands;if(!J){console.log(W.yellow(`No commands found in ${D.name}`));return}console.log(`
|
|
3
3
|
${W.bold("Available commands")} ${W.dim(`(${D.name})`)}:
|
|
4
|
-
`);let U=Object.entries(J),I=Math.max(...U.map(([V])=>V.length)),X=!1;for(let[V,Q]of U){let Z=Q&&typeof Q==="object"&&!Array.isArray(Q),K=Z?Q.description||"":"",$=Z?Q.usage||"":"",z=!!(K||$);if(z&&X)console.log("");let R=V.padEnd(I);if(z){if(console.log(` ${W.bold.cyan(R)} ${K}`),$)console.log(` ${"".padEnd(I)} ${W.dim("$ "+$)}`);console.log("")}else console.log(` ${W.cyan(R)}`);X=z}}catch(D){console.error(`Error: ${D.message}`),process.exit(1)}}async function S(q){let A=process.cwd(),D=x.resolve(A,"fnode.yaml"),E=x.resolve(A,"fnet.yaml");if(q==="fnode"){if(_.existsSync(D))return{path:D,name:"fnode.yaml",type:"fnode"};throw Error("fnode.yaml file not found in current directory")}if(q==="fnet"){if(_.existsSync(E))return{path:E,name:"fnet.yaml",type:"fnet"};throw Error("fnet.yaml file not found in current directory")}if(_.existsSync(D))return{path:D,name:"fnode.yaml",type:"fnode"};if(_.existsSync(E))return{path:E,name:"fnet.yaml",type:"fnet"};throw Error("No project file (fnode.yaml or fnet.yaml) found in current directory")}function B({processManager:q}){return{command:"$0 [group] [options..]",describe:"Run a command group from project file",builder:(A)=>{return A.parserConfiguration({}).middleware((D)=>{let E=/^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)+$/;Object.keys(D).forEach((J)=>{if(E.test(J)){let U=J.replace(/-/g,"_");D[U]=D[J]}})}).positional("group",{type:"string",describe:"Command group to run"}).option("list",{type:"boolean",describe:"List all available command groups",alias:"l"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}).example("$0 build","Run the build command group").example("$0 --list","List all available command groups").example("$0 test --ftag dev","Run the test command group with dev tag")},handler:async(A)=>{try{if(A.list){await O({projectType:"auto",tags:A.ftag});return}if(!A.group)console.error("Error: Please specify a command group or use --list to see available commands."),process.exit(1);await L({projectType:"auto",group:A.group,tags:A.ftag,args:A,argv:process.argv,processManager:q})}catch(D){console.error(`Error: ${D.message}`),await q.dispose(),process.exit(1)}}}}var N=new Y;C(T(process.argv)).scriptName("frun").usage("Usage: $0 <command> [options]").command(B({processManager:N})).help().version("1.
|
|
4
|
+
`);let U=Object.entries(J),I=Math.max(...U.map(([V])=>V.length)),X=!1;for(let[V,Q]of U){let Z=Q&&typeof Q==="object"&&!Array.isArray(Q),K=Z?Q.description||"":"",$=Z?Q.usage||"":"",z=!!(K||$);if(z&&X)console.log("");let R=V.padEnd(I);if(z){if(console.log(` ${W.bold.cyan(R)} ${K}`),$)console.log(` ${"".padEnd(I)} ${W.dim("$ "+$)}`);console.log("")}else console.log(` ${W.cyan(R)}`);X=z}}catch(D){console.error(`Error: ${D.message}`),process.exit(1)}}async function S(q){let A=process.cwd(),D=x.resolve(A,"fnode.yaml"),E=x.resolve(A,"fnet.yaml");if(q==="fnode"){if(_.existsSync(D))return{path:D,name:"fnode.yaml",type:"fnode"};throw Error("fnode.yaml file not found in current directory")}if(q==="fnet"){if(_.existsSync(E))return{path:E,name:"fnet.yaml",type:"fnet"};throw Error("fnet.yaml file not found in current directory")}if(_.existsSync(D))return{path:D,name:"fnode.yaml",type:"fnode"};if(_.existsSync(E))return{path:E,name:"fnet.yaml",type:"fnet"};throw Error("No project file (fnode.yaml or fnet.yaml) found in current directory")}function B({processManager:q}){return{command:"$0 [group] [options..]",describe:"Run a command group from project file",builder:(A)=>{return A.parserConfiguration({}).middleware((D)=>{let E=/^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)+$/;Object.keys(D).forEach((J)=>{if(E.test(J)){let U=J.replace(/-/g,"_");D[U]=D[J]}})}).positional("group",{type:"string",describe:"Command group to run"}).option("list",{type:"boolean",describe:"List all available command groups",alias:"l"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}).example("$0 build","Run the build command group").example("$0 --list","List all available command groups").example("$0 test --ftag dev","Run the test command group with dev tag")},handler:async(A)=>{try{if(A.list){await O({projectType:"auto",tags:A.ftag});return}if(!A.group)console.error("Error: Please specify a command group or use --list to see available commands."),process.exit(1);await L({projectType:"auto",group:A.group,tags:A.ftag,args:A,argv:process.argv,processManager:q})}catch(D){console.error(`Error: ${D.message}`),await q.dispose(),process.exit(1)}}}}var N=new Y;C(T(process.argv)).scriptName("frun").usage("Usage: $0 <command> [options]").command(B({processManager:N})).help().version("1.5.0").fail(async(q,A)=>{if(A)console.error(`Error: ${A.message}`);else if(q)console.error(`Error: ${q}`);await N.dispose(),process.exit(1)}).parse();
|
package/dist/fservice/index.js
CHANGED
|
@@ -15,5 +15,5 @@ ${z}
|
|
|
15
15
|
`).filter((T)=>T.includes("=")).reduce((T,E)=>{let[z,...K]=E.split("=");return T[z.trim()]=K.join("=").trim(),T},{})}}},workingDir:{type:"string",description:"Working directory","x-prompt":{type:"input",message:"Enter working directory (optional):"}},autoStart:{type:"boolean",description:"Start on boot",default:!1,"x-prompt":{type:"confirm",message:"Start service on boot?",initial:!1}},restartOnFailure:{type:"boolean",description:"Restart on failure",default:!0,"x-prompt":{type:"confirm",message:"Restart service on failure?",initial:!0}},system:{type:"boolean",description:"System service",default:!0,"x-prompt":{type:"confirm",message:"Register as system service?",initial:!0}},user:{type:"string",description:"User to run the service as","x-prompt":{type:"input",message:"Enter user to run the service as (optional):"}},instances:{type:"integer",description:"Number of instances to run",default:1,minimum:1,"x-prompt":{type:"number",message:"Enter number of instances to run:",initial:1}},metadata:{type:"object",additionalProperties:!0,description:"Custom metadata"}}}}var h={getServiceManifestSchema:j$};import p from"chalk";import E$ from"@fnet/prompt";async function D$($){let{items:_,message:Y,nameField:T="name",valueField:E="name",initialValue:z=null,allowAbort:K=!0}=$;if(!_||_.length===0)return console.log(p.yellow("No items available for selection.")),null;if(_.length===1&&!K){let q=_[0],P=typeof q==="string"?q:q[E];return console.log(p.blue(`Only one option available: ${typeof q==="string"?q:q[T]}`)),P}let Q=_.map((q)=>{if(typeof q==="string")return{name:q,value:q,message:q};else return{name:q[E],value:q[E],message:q[T]||q[E]}});if(K)Q.push({name:"cancel",value:null,message:p.yellow("Cancel")});let G=null;if(z){let q=Q.findIndex((P)=>P.name===z);if(q!==-1)G=q}let O="selectedItem",{[O]:M}=await E$({type:"select",name:O,message:Y,choices:Q,initial:G});if(M==="cancel")return null;return M}async function P$($){let{items:_,message:Y,nameField:T="name",valueField:E="name",initialValues:z=[],allowAbort:K=!0}=$;if(!_||_.length===0)return console.log(p.yellow("No items available for selection.")),null;let Q=_.map((q)=>{if(typeof q==="string")return{name:q,value:q,message:q};else return{name:q[E],value:q[E],message:q[T]||q[E]}}),G=[];if(z&&z.length>0)G=Q.map((q,P)=>z.includes(q.name)?P:-1).filter((q)=>q!==-1);let O="selectedItems",M=await E$({type:"multiselect",name:O,message:Y,choices:Q,initial:G,hint:"(Use space to select, enter to confirm)",validate:(q)=>{if(q.length===0&&!K)return"Please select at least one item";return!0}});if(K&&M[O].length===0)return null;return M[O]}var w={promptForSelection:D$,promptForMultipleSelection:P$};var b$={command:"manifest <subcommand>",describe:"Manage service manifests",builder:($)=>{return $.command({command:"create",describe:"Create a new service manifest",builder:(_)=>{return _.option("name",{describe:"Service manifest name",type:"string"}).option("output",{describe:"Output file path",type:"string",alias:"o"})},handler:S$}).command({command:"list",describe:"List service manifests",builder:(_)=>{return _.option("format",{describe:"Output format",type:"string",choices:["json","text","table"],default:"table"})},handler:N$}).command({command:"show [n]",describe:"Show service manifest details",builder:(_)=>{return _.positional("name",{describe:"Service manifest name",type:"string",demandOption:!1}).option("format",{describe:"Output format",type:"string",choices:["json","yaml"],default:"yaml"})},handler:y$}).command({command:"edit [n]",describe:"Edit a service manifest",builder:(_)=>{return _.positional("name",{describe:"Service manifest name",type:"string",demandOption:!1})},handler:u$}).command({command:"delete [n]",describe:"Delete a service manifest",builder:(_)=>{return _.positional("name",{describe:"Service manifest name",type:"string",demandOption:!1}).option("force",{describe:"Force deletion without confirmation",type:"boolean",default:!1,alias:"f"})},handler:k$}).command({command:"validate [n]",describe:"Validate a service manifest",builder:(_)=>{return _.positional("name",{describe:"Service manifest name",type:"string",demandOption:!1})},handler:d$}).demandCommand(1,"You need to specify a subcommand")},handler:()=>{}};async function S$($){try{let _=await I($),Y=h.getServiceManifestSchema(),T=await J$({schema:Y,format:"yaml"});console.log("Result from fnetObjectFromSchema:",T);let E;if(typeof T==="string")try{E=(await import("yaml")).default.parse(T)}catch(Q){console.warn(X.yellow(`Failed to parse YAML: ${Q.message}`)),E={name:"service-"+Date.now()}}else if(T&&typeof T==="object")E=T.data||T;else E={name:"service-"+Date.now()};console.log("Generated manifest:",E);let z=$.name||(E&&E.name?E.name:"service-"+Date.now());if(J.servicManifestExists(z)&&!$.force){let{confirmOverwrite:Q}=await K$({type:"confirm",name:"confirmOverwrite",message:`Service manifest '${z}' already exists. Overwrite?`,initial:!1});if(!Q){console.log(X.yellow("Operation cancelled."));return}}if(J.saveServiceManifest(z,E))console.log(X.green(`Service manifest '${z}' created successfully.`)),console.log(X.blue(`Location: ${J.getServiceManifestPath(z)}`));else console.error(X.red(`Failed to create service manifest '${z}'.`))}catch(_){console.error(X.red(`Error: ${_.message}`)),process.exit(1)}}async function N$($){try{let _=await I($),Y=J.listServiceManifests();if(Y.length===0){console.log(X.yellow("No service manifests found."));return}if($.format==="json")console.log(JSON.stringify(Y,null,2));else if($.format==="text")Y.forEach((T)=>console.log(T));else{console.log(X.bold(`
|
|
16
16
|
Service Definitions:`));let T=(await import("./index.ezmyhtvd.js")).default,E=["NAME","BINARY","DESCRIPTION"],z=T.createTable(E,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});for(let K of Y){let Q=J.loadServiceManifest(K);if(Q)z.push([X.white(K),X.cyan(Q.binary||"undefined"),Q.description||""])}console.log(z.toString()),console.log(`Total: ${Y.length} manifest(s)`)}}catch(_){console.error(X.red(`Error: ${_.message}`)),process.exit(1)}}async function y$($){try{let _=await I($);if(!$.name){let T=J.listServiceManifests();if(T.length===0){console.log(X.yellow("No service manifests found."));return}let E=await w.promptForSelection({items:T,message:"Select a service manifest to show:",allowAbort:!0});if(E===null){console.log(X.yellow("Operation cancelled."));return}$.name=E}let Y=J.loadServiceManifest($.name);if(!Y)console.error(X.red(`Service manifest '${$.name}' not found.`)),process.exit(1);if($.format==="json")console.log(JSON.stringify(Y,null,2));else{let T=(await import("yaml")).default;console.log(T.stringify(Y))}}catch(_){console.error(X.red(`Error: ${_.message}`)),process.exit(1)}}async function u$($){try{let _=await I($);if(!$.name){let Q=J.listServiceManifests();if(Q.length===0){console.log(X.yellow("No service manifests found."));return}let G=await w.promptForSelection({items:Q,message:"Select a service manifest to edit:",allowAbort:!0});if(G===null){console.log(X.yellow("Operation cancelled."));return}$.name=G}let Y=J.loadServiceManifest($.name);if(!Y)console.error(X.red(`Service manifest '${$.name}' not found.`)),process.exit(1);let T=h.getServiceManifestSchema(),z=(await J$({schema:T,ref:Y,format:"yaml"})).data;if(J.saveServiceManifest($.name,z))console.log(X.green(`Service manifest '${$.name}' updated successfully.`));else console.error(X.red(`Failed to update service manifest '${$.name}'.`))}catch(_){console.error(X.red(`Error: ${_.message}`)),process.exit(1)}}async function k$($){try{let _=await I($);if(!$.name){let T=J.listServiceManifests();if(T.length===0){console.log(X.yellow("No service manifests found."));return}let E=await w.promptForSelection({items:T,message:"Select a service manifest to delete:",allowAbort:!0});if(E===null){console.log(X.yellow("Operation cancelled."));return}$.name=E}if(!J.servicManifestExists($.name))console.error(X.red(`Service manifest '${$.name}' not found.`)),process.exit(1);if(!$.force){let{confirmDelete:T}=await K$({type:"confirm",name:"confirmDelete",message:`Are you sure you want to delete service manifest '${$.name}'?`,initial:!1});if(!T){console.log(X.yellow("Operation cancelled."));return}}if(J.deleteServiceManifest($.name))console.log(X.green(`Service manifest '${$.name}' deleted successfully.`));else console.error(X.red(`Failed to delete service manifest '${$.name}'.`))}catch(_){console.error(X.red(`Error: ${_.message}`)),process.exit(1)}}async function d$($){try{let _=await I($);if(!$.name){let E=J.listServiceManifests();if(E.length===0){console.log(X.yellow("No service manifests found."));return}let z=await w.promptForSelection({items:E,message:"Select a service manifest to validate:",allowAbort:!0});if(z===null){console.log(X.yellow("Operation cancelled."));return}$.name=z}let Y=J.loadServiceManifest($.name);if(!Y)console.error(X.red(`Service manifest '${$.name}' not found.`)),process.exit(1);let T=J.validateServiceManifest(Y);if(T.valid)console.log(X.green(`Service manifest '${$.name}' is valid.`));else console.error(X.red(`Service manifest '${$.name}' is invalid:`)),T.errors.forEach((E)=>{console.error(X.red(`- ${E}`))}),process.exit(1)}catch(_){console.error(X.red(`Error: ${_.message}`)),process.exit(1)}}var Q$=b$;import B from"chalk";var p$={command:"register",describe:"Register a service manifest as a system service",builder:($)=>{return $.option("manifest",{describe:"Service manifest name",type:"string",demandOption:!1,alias:"d"}).option("start",{describe:"Start the service after registration",type:"boolean",default:!1})},handler:async($)=>{try{let _=await I($),Y=$.manifest;if(!Y){let E=J.listServiceManifests();if(E.length===0)console.log(B.yellow('No service manifests found. Create one first using "fservice manifest create".')),process.exit(1);if(Y=await w.promptForSelection({items:E,message:"Select a service manifest to register:",allowAbort:!0}),!Y){console.log(B.yellow("Operation cancelled."));return}}if(!J.servicManifestExists(Y))console.error(B.red(`Service manifest '${Y}' not found.`)),process.exit(1);console.log(B.blue(`Registering service from manifest '${Y}'...`));let T=await J.registerService(Y);if(console.log(B.green(`Service '${T.name}' registered successfully.`)),$.start){console.log(B.blue(`Starting service '${T.name}'...`));let E=(await import("@fnet/service")).default;try{await E({action:"start",name:T.name}),console.log(B.green(`Service '${T.name}' started successfully.`));let z=J.loadServiceMetadata();if(z.services[T.name])z.services[T.name].status="running",z.services[T.name].lastStarted=new Date().toISOString(),J.saveServiceMetadata(z)}catch(z){console.error(B.red(`Failed to start service: ${z.message}`))}}}catch(_){console.error(B.red(`Error: ${_.message}`)),process.exit(1)}}},W$=p$;import H from"chalk";import g$ from"@fnet/prompt";var f$={command:"unregister",describe:"Unregister a service from the system",builder:($)=>{return $.option("name",{describe:"Service name",type:"string",demandOption:!1,alias:"n"}).option("keep-manifest",{describe:"Keep the service manifest",type:"boolean",default:!0}).option("force",{describe:"Force unregistration without confirmation",type:"boolean",default:!1,alias:"f"})},handler:async($)=>{try{let _=await I($),Y=J.loadServiceMetadata(),T=$.name;if(!T){let z=Object.keys(Y.services);if(z.length===0)console.log(H.yellow("No registered services found.")),process.exit(1);if(T=await w.promptForSelection({items:z,message:"Select a service to unregister:",allowAbort:!0}),!T){console.log(H.yellow("Operation cancelled."));return}}if(!Y.services[T])console.error(H.red(`Service '${T}' not found in metadata.`)),process.exit(1);if(!$.force){let{confirmUnregister:z}=await g$({type:"confirm",name:"confirmUnregister",message:`Are you sure you want to unregister service '${T}'?`,initial:!1});if(!z){console.log(H.yellow("Operation cancelled."));return}}console.log(H.blue(`Unregistering service '${T}'...`));let E=(await import("@fnet/service")).default;try{let z=Y.services[T].manifest,K=J.loadServiceManifest(z);if(!K)throw Error(`Service manifest '${z}' not found`);let Q=K.system!==!1;try{await E({action:"stop",name:T,system:Q}),console.log(H.blue(`Service '${T}' stopped.`))}catch(G){console.warn(H.yellow(`Warning: Failed to stop service: ${G.message}`))}if(await E({action:"unregister",name:T,system:Q}),console.log(H.green(`Service '${T}' unregistered successfully.`)),delete Y.services[T],J.saveServiceMetadata(Y),!$.keepDefinition&&z){if(J.servicManifestExists(z))if(J.deleteServiceManifest(z))console.log(H.green(`Service manifest '${z}' deleted.`));else console.warn(H.yellow(`Warning: Failed to delete service manifest '${z}'.`))}}catch(z){console.error(H.red(`Failed to unregister service: ${z.message}`)),process.exit(1)}}catch(_){console.error(H.red(`Error: ${_.message}`)),process.exit(1)}}},X$=f$;import x from"chalk";var h$={command:"start",describe:"Start a registered service",builder:($)=>{return $.option("name",{describe:"Service name",type:"string",demandOption:!1,alias:"n"})},handler:async($)=>{try{let _=await I($),Y=J.loadServiceMetadata(),T=$.name;if(!T){let z=Object.keys(Y.services);if(z.length===0)console.log(x.yellow("No registered services found.")),process.exit(1);if(T=await w.promptForSelection({items:z,message:"Select a service to start:",allowAbort:!0}),!T){console.log(x.yellow("Operation cancelled."));return}}if(!Y.services[T])console.error(x.red(`Service '${T}' not found in metadata.`)),process.exit(1);console.log(x.blue(`Starting service '${T}'...`));let E=(await import("@fnet/service")).default;try{let z=Y.services[T].manifest,K=J.loadServiceManifest(z);if(!K)throw Error(`Service manifest '${z}' not found`);await E({action:"start",name:T,system:K.system!==!1}),console.log(x.green(`Service '${T}' started successfully.`)),Y.services[T].status="running",Y.services[T].lastStarted=new Date().toISOString(),J.saveServiceMetadata(Y)}catch(z){console.error(x.red(`Failed to start service: ${z.message}`)),process.exit(1)}}catch(_){console.error(x.red(`Error: ${_.message}`)),process.exit(1)}}},Z$=h$;import F from"chalk";var o$={command:"stop",describe:"Stop a running service",builder:($)=>{return $.option("name",{describe:"Service name",type:"string",demandOption:!1,alias:"n"})},handler:async($)=>{try{let _=await I($),Y=J.loadServiceMetadata(),T=$.name;if(!T){let z=Object.keys(Y.services);if(z.length===0)console.log(F.yellow("No registered services found.")),process.exit(1);if(T=await w.promptForSelection({items:z,message:"Select a service to stop:",allowAbort:!0}),!T){console.log(F.yellow("Operation cancelled."));return}}if(!Y.services[T])console.error(F.red(`Service '${T}' not found in metadata.`)),process.exit(1);console.log(F.blue(`Stopping service '${T}'...`));let E=(await import("@fnet/service")).default;try{let z=Y.services[T].manifest,K=J.loadServiceManifest(z);if(!K)throw Error(`Service manifest '${z}' not found`);await E({action:"stop",name:T,system:K.system!==!1}),console.log(F.green(`Service '${T}' stopped successfully.`)),Y.services[T].status="stopped",Y.services[T].lastStopped=new Date().toISOString(),J.saveServiceMetadata(Y)}catch(z){console.error(F.red(`Failed to stop service: ${z.message}`)),process.exit(1)}}catch(_){console.error(F.red(`Error: ${_.message}`)),process.exit(1)}}},q$=o$;import U from"chalk";var v$={command:"restart",describe:"Restart a service",builder:($)=>{return $.option("name",{describe:"Service name",type:"string",demandOption:!1,alias:"n"})},handler:async($)=>{try{let _=await I($),Y=J.loadServiceMetadata(),T=$.name;if(!T){let z=Object.keys(Y.services);if(z.length===0)console.log(U.yellow("No registered services found.")),process.exit(1);if(T=await w.promptForSelection({items:z,message:"Select a service to restart:",allowAbort:!0}),!T){console.log(U.yellow("Operation cancelled."));return}}if(!Y.services[T])console.error(U.red(`Service '${T}' not found in metadata.`)),process.exit(1);console.log(U.blue(`Restarting service '${T}'...`));let E=(await import("@fnet/service")).default;try{await E({action:"stop",name:T}),console.log(U.blue(`Service '${T}' stopped.`)),await E({action:"start",name:T}),console.log(U.green(`Service '${T}' restarted successfully.`)),Y.services[T].status="running",Y.services[T].lastRestarted=new Date().toISOString(),J.saveServiceMetadata(Y)}catch(z){console.error(U.red(`Failed to restart service: ${z.message}`)),process.exit(1)}}catch(_){console.error(U.red(`Error: ${_.message}`)),process.exit(1)}}},I$=v$;import L from"chalk";var l$={command:"status",describe:"Check the status of a service",builder:($)=>{return $.option("name",{describe:"Service name",type:"string",demandOption:!1,alias:"n"}).option("format",{describe:"Output format",type:"string",choices:["json","text","table"],default:"table"})},handler:async($)=>{try{let _=await I($),Y=J.loadServiceMetadata(),T=$.name;if(!T){let z=Object.keys(Y.services);if(z.length===0)console.log(L.yellow("No registered services found.")),process.exit(1);if(T=await w.promptForSelection({items:z,message:"Select a service to check status:",allowAbort:!0}),!T){console.log(L.yellow("Operation cancelled."));return}}if(!Y.services[T])console.error(L.red(`Service '${T}' not found in metadata.`)),process.exit(1);console.log(L.blue(`Checking status of service '${T}'...`));let E=(await import("@fnet/service")).default;try{let z=Y.services[T].manifest,K=J.loadServiceManifest(z);if(!K)throw Error(`Service manifest '${z}' not found`);let Q=await E({action:"status",name:T,system:K.system!==!1});if(console.log(L.green(`Service '${T}' status: ${Q}`)),Y.services[T].status=Q||"unknown",Y.services[T].lastChecked=new Date().toISOString(),J.saveServiceMetadata(Y),$.format==="json")console.log(JSON.stringify({name:T,status:Q||"unknown",manifest:z,binary:Y.services[T].binary},null,2));else if($.format==="text")console.log(`Name: ${T}`),console.log(`Status: ${Q||"unknown"}`),console.log(`Definition: ${z}`),console.log(`Binary: ${Y.services[T].binary}`);else console.log(L.bold(`
|
|
17
17
|
Service Status:`)),console.log(L.bold("─".repeat(50))),console.log(`${L.bold("Name:")} ${T}`),console.log(`${L.bold("Status:")} ${n$(Q)(Q||"unknown")}`),console.log(`${L.bold("Definition:")} ${z}`),console.log(`${L.bold("Binary:")} ${Y.services[T].binary}`),console.log(L.bold("─".repeat(50)))}catch(z){console.error(L.red(`Failed to check service status: ${z.message}`)),process.exit(1)}}catch(_){console.error(L.red(`Error: ${_.message}`)),process.exit(1)}}};function n$($){switch($){case"running":return L.green;case"stopped":return L.yellow;case"failed":return L.red;default:return L.gray}}var G$=l$;import N from"chalk";var m$={command:"list",describe:"List all registered services",builder:($)=>{return $.option("binary",{describe:"Filter by binary name",type:"string",alias:"b"}).option("status",{describe:"Filter by status",type:"string",choices:["running","stopped","failed","unknown"],alias:"s"}).option("format",{describe:"Output format",type:"string",choices:["json","text","table"],default:"table"})},handler:async($)=>{try{let _=await I($),Y=J.loadServiceMetadata(),T=Object.entries(Y.services).map(([E,z])=>({name:E,...z}));if($.binary)T=T.filter((E)=>E.binary===$.binary);if($.status)T=T.filter((E)=>E.status===$.status);if(T.length===0){console.log(N.yellow("No services found."));return}if($.format==="json")console.log(JSON.stringify(T,null,2));else if($.format==="text")T.forEach((E)=>{console.log(`${E.name} (${E.status||"unknown"})`)});else{let E=["NAME","STATUS","BINARY","DEFINITION"],z=o.createTable(E,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});T.forEach((K)=>{let Q=o.getStatusColor(K.status);z.push([N.white(K.name),Q(K.status||"unknown"),N.cyan(K.binary),K.manifest])}),console.log(N.bold(`
|
|
18
|
-
Registered Services:`)),console.log(z.toString()),console.log(`Total: ${T.length} service(s)`)}}catch(_){console.error(N.red(`Error: ${_.message}`)),process.exit(1)}}},R$=m$;var w_=c$(r$(process.argv)).scriptName("fservice").usage("Usage: $0 <command> [options]").version("1.
|
|
18
|
+
Registered Services:`)),console.log(z.toString()),console.log(`Total: ${T.length} service(s)`)}}catch(_){console.error(N.red(`Error: ${_.message}`)),process.exit(1)}}},R$=m$;var w_=c$(r$(process.argv)).scriptName("fservice").usage("Usage: $0 <command> [options]").version("1.5.0").command(Q$).command(W$).command(X$).command(Z$).command(q$).command(I$).command(G$).command(R$).demandCommand(1,"You need to specify a command").strict().help().alias("h","help").alias("v","version").fail(($,_,Y)=>{if(_)console.error(v.red(`Error: ${_.message}`)),console.error(_);else console.error(v.red(`Error: ${$}`));console.error(v.yellow(`
|
|
19
19
|
Usage:`),Y.help()),process.exit(1)}).parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fnet/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"template",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@fnet/to-pyip": "^0.2.1",
|
|
52
52
|
"@fnet/to-rust": "^0.1.14",
|
|
53
53
|
"@fnet/up-list-files": "^0.1.14",
|
|
54
|
-
"@fnet/yaml": "^0.1.
|
|
54
|
+
"@fnet/yaml": "^0.1.47",
|
|
55
55
|
"@node-red/util": "^4.1.8",
|
|
56
56
|
"ajv": "^8.18.0",
|
|
57
57
|
"ajv-formats": "^3.0.1",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"lodash.merge": "^4.6.2",
|
|
67
67
|
"nunjucks": "^3.2.4",
|
|
68
68
|
"object-hash": "^3.0.0",
|
|
69
|
-
"prettier": "^3.8.
|
|
69
|
+
"prettier": "^3.8.2",
|
|
70
70
|
"rollup": "^4.60.1",
|
|
71
71
|
"semver": "^7.7.4",
|
|
72
72
|
"set-value": "^4.1.0",
|