@fnet/cli 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{e as E}from"./index.9qgtmxq3.js";import{f as c}from"./index.05n3mvs9.js";import{i as k}from"./index.cvxrf34y.js";import q$ from"yargs";import w1 from"chalk";import{promisify as I1}from"node:util";import F1 from"tree-kill";var r=I1(F1),N=!1;async function n($,W){if(N)return;if(N=!0,!$.killed&&$.pid)try{if(await r($.pid,"SIGTERM").catch(()=>{}),await new Promise((q)=>setTimeout(q,500)),!$.killed)await r($.pid,"SIGKILL").catch(()=>{})}catch(q){}await new Promise((q)=>setTimeout(q,100));let z=W==="SIGINT"?130:W==="SIGTERM"?143:1;process.exit(z)}function S($){["SIGINT","SIGTERM","SIGQUIT"].forEach((W)=>{process.once(W,async()=>{await n($,W)})}),process.on("uncaughtException",async(W)=>{await n($)}),process.on("unhandledRejection",async(W)=>{await n($)}),$.on("close",(W)=>{if(!N)process.exit(W)})}function a(){process.on("uncaughtException",($)=>{if(!N)N=!0,setTimeout(()=>process.exit(1),500)}),process.on("unhandledRejection",($)=>{if(!N)N=!0,setTimeout(()=>process.exit(1),500)})}import x from"node:path";import{spawn as v}from"node:child_process";import u from"node:fs";import b from"chalk";import _1 from"@fnet/config";function C($,{name:W,bin:z,preArgs:q=[],createContext:G}){if(typeof z==="function")z=z();return $.command(`${W||z} [commands..]`,`${z} ${q.join(" ")}`,(Z)=>{return Z.help(!1).version(!1)},async(Z)=>{try{let Q=await G(Z),{projectDir:Y}=Q,L=(I)=>{if(!I.includes(" "))return I;if(process.platform==="win32")return`"${I.replace(/(["^])/g,"^$1")}"`;else return`"${I.replace(/(["\\$`])/g,"\\$1")}"`},M=process.argv.slice(3).map(L),J={...process.env},K=x.join(Y,"node_modules");J.NODE_PATH=K,J.NODE_PRESERVE_SYMLINKS=1;let T=v(z,[...q,...M],{cwd:Y,stdio:"inherit",shell:!0,detached:!0,env:J});S(T)}catch(Q){console.error(Q.message),process.exit(1)}})}function y($,{name:W,bin:z,preArgs:q=[],createContext:G}){return $.command(`${W||z} [commands..]`,`${z} ${q.join(" ")}`,(Z)=>{return Z.help(!1).version(!1)},async(Z)=>{try{let Q=await G(Z),{projectDir:Y}=Q,L=(K)=>{if(!K.includes(" "))return K;if(process.platform==="win32")return`"${K.replace(/(["^])/g,"^$1")}"`;else return`"${K.replace(/(["\\$`])/g,"\\$1")}"`},M=process.argv.slice(3).map(L);z=x.join(Y,".conda","bin",z||W);let J=v(z,[...q,...M],{cwd:Y,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:Y}});S(J)}catch(Q){console.error(Q.message),process.exit(1)}})}function t($,{name:W,createContext:z}){return $.command(`${W} <binary> [commands..]`,"Run a binary from conda environment",(q)=>{return q.positional("binary",{type:"string",describe:"Binary name to run from .conda/bin"}).help(!1).version(!1)},async(q)=>{try{let G=await z(q),{projectDir:Z}=G,Q=(K)=>{if(!K.includes(" "))return K;if(process.platform==="win32")return`"${K.replace(/(["^])/g,"^$1")}"`;else return`"${K.replace(/(["\\$`])/g,"\\$1")}"`},Y=q.binary,L=process.argv.slice(4).map(Q),M=x.join(Z,".conda","bin",Y),J=v(M,L,{cwd:Z,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:Z}});S(J)}catch(G){console.error(G.message),process.exit(1)}})}function e($,{name:W,preArgs:z=[],createContext:q}){return $.command(`${W} <config> <command> [options..]`,"Run a command with a config context",(G)=>{return G.positional("config",{type:"string"}).positional("command",{type:"string"}).help(!1).version(!1)},async(G)=>{try{let Z=await q(G),{projectDir:Q}=Z,Y=G.config,M=(await _1({name:Y,dir:Q,transferEnv:!1,optional:!0,tags:Z.tags}))?.data?.env||void 0,J=G.command,K=process.argv.slice(5),T=v(J,[...z,...K],{cwd:u.existsSync(Q)?Q:process.cwd(),stdio:"inherit",shell:!0,detached:!0,env:{...process.env,...M}});S(T)}catch(Z){console.error(Z.message),process.exit(1)}})}function $1($,{name:W,projectType:z="auto"}){return $.command(`${W} group [options..]`,"Run a command group.",(q)=>{return q.positional("group",{type:"string"}).option("ftag",{type:"array"}).help(!1).version(!1)},async(q)=>{try{let{runCommandGroup:G}=await import("./index.2pnjg6dc.js");await G({projectType:z,group:q.group,tags:q.ftag,args:q,argv:process.argv})}catch(G){console.error(G.message),process.exit(1)}})}function W1($,{name:W,createContext:z}){return $.command(`${W} [options]`,"Install the project as a binary",(q)=>{return q.option("name",{alias:"n",describe:"Name to use for the installed binary",type:"string"}).option("force",{alias:"f",describe:"Force overwrite if binary already exists",type:"boolean",default:!1}).option("yes",{alias:"y",describe:"Automatically answer yes to all prompts",type:"boolean",default:!1})},async(q)=>{try{let G=await z(q),{projectDir:Z}=G;console.log(b.blue("Compiling project..."));let Q=x.join(Z,".bin");if(!u.existsSync(Q))u.mkdirSync(Q,{recursive:!0});let Y=x.basename(x.dirname(Z)),L=G.project?.projectFileParsed?.features?.cli?.bin,M=q.name||L||Y;console.log(b.blue(`Using binary name: ${M}`));let J=x.join(Q,M),{spawn:K}=await import("child_process"),T=K("bun",["build","./dist/cli/esm/index.js","--compile",`--outfile=${J}`],{cwd:Z,stdio:"inherit",shell:!0});if(await new Promise((f,F)=>{T.on("close",(_)=>{if(_===0)f();else F(Error(`Compilation failed with code ${_}`))}),T.on("error",(_)=>{F(_)})}),process.platform!=="win32")u.chmodSync(J,493);console.log(b.green(`Binary compiled successfully: ${J}`)),console.log(b.blue("Installing binary..."));let I=["install",J];if(q.name)I.push("--name",q.name);if(q.force)I.push("--force");if(q.yes)I.push("--yes");let D=K("fbin",I,{stdio:"inherit",shell:!0});await new Promise((f,F)=>{D.on("close",(_)=>{if(_===0)f();else F(Error(`Installation failed with code ${_}`))}),D.on("error",(_)=>{F(_)})})}catch(G){console.error(b.red(`Failed to install binary: ${G.message}`)),process.exit(1)}})}import w from"node:path";import B from"node:fs";import q1 from"@fnet/yaml";import A1 from"yaml";async function O($){try{let W=await R1({tags:$.ftag}),z=W.runtime.type==="bun"?"node":W.runtime.type;return{buildId:$.buildId,mode:$.mode,protocol:$.protocol||"src:",templateDir:E(`./template/fnode/${z}`),projectDir:w.resolve(W.projectDir,"./.workspace"),projectSrcDir:w.resolve(W.projectDir,"./src"),projectSrcDirSymlink:w.resolve(W.projectDir,"./.workspace/src-core"),projectAppDir:w.resolve(W.projectDir,"./app"),projectAppDirSymlink:w.resolve(W.projectDir,"./.workspace/app"),projectCliDir:w.resolve(W.projectDir,"./cli"),projectCliDirSymlink:w.resolve(W.projectDir,"./.workspace/cli"),project:W,tags:$.ftag,dev:$.dev,bpmn:$.bpmn===!0}}catch(W){return console.warn(`Warning: Could not load project: ${W.message}`),{projectDir:process.cwd(),tags:$.ftag}}}async function R1({tags:$}){let W=N1(process.cwd());if(!B.existsSync(W))throw Error("fnode.yaml file not found in current directory.");let{raw:z,parsed:q}=await q1({file:W,tags:$}),G=w.dirname(W);q.features=q.features||{};let Z=q.features;if(Z.runtime=Z.runtime||{},Z.runtime.type=Z.runtime.type||"node",Z.runtime.type==="python")Z.runtime.template=Z.runtime.template||"python";else if(Z.runtime.type==="bun")Z.runtime.template=Z.runtime.template||"node";else Z.runtime.template=Z.runtime.template||"node";let Q={libraryAtom:{doc:{...q},fileName:"index"},projectDir:G,projectFilePath:W,projectFileContent:z,projectFileParsed:q,runtime:Z.runtime},Y=w.resolve(G,"fnet/targets.yaml");if(!B.existsSync(Y)){if(Y=w.resolve(G,"node.devops.yaml"),B.existsSync(Y)){let M=w.resolve(G,"fnet");if(!B.existsSync(M))B.mkdirSync(M);B.copyFileSync(Y,w.resolve(G,"fnet/targets.yaml")),B.unlinkSync(Y)}}if(B.existsSync(Y)){let{raw:M,parsed:J}=await q1({file:Y,tags:$}),K=A1.parseDocument(M);Q.devops={filePath:Y,fileContent:M,yamlDocument:K,doc:{...J},type:"library.deploy",save:async()=>{B.writeFileSync(Q.devops.filePath,K.toString())}}}let L=w.resolve(G,"readme.md");if(B.existsSync(L)){let M=B.readFileSync(L,"utf8");Q.readme={filePath:L,fileContent:M,doc:{content:M,"content-type":"markdown"},type:"wiki"}}return Q}function N1($){let W=w.resolve($,"node.yaml"),z=w.resolve($,"fnode.yaml");if(B.existsSync(z))return z;if(B.existsSync(W))try{let q=B.readFileSync(W,"utf8");return B.writeFileSync(z,q,"utf8"),B.unlinkSync(W),console.log(`Migrated node.yaml to fnode.yaml in ${$}`),z}catch(q){return console.error(`Error migrating node.yaml to fnode.yaml: ${q.message}`),W}return z}import x1 from"node:path";import z1 from"node:fs";import k1 from"node:os";import E1 from"@flownet/lib-render-templates-dir";import i from"@fnet/shelljs";var S1={command:"create",describe:"Create a new fnode project",builder:($)=>{return $.option("name",{type:"string",describe:"Project name",demandOption:!0}).option("vscode",{type:"boolean",default:!0,alias:"vs",describe:"Open in VS Code after creation"}).option("runtime",{type:"string",default:"node",choices:["node","python","bun"],describe:"Runtime environment"})},handler:async($)=>{try{let W=process.cwd(),z=E("./template/fnode/project"),q=x1.resolve(W,$.name);if(!z1.existsSync(q))z1.mkdirSync(q);await E1({dir:z,outDir:q,context:{name:$.name,runtime:$.runtime,platform:k1.platform()},copyUnmatchedAlso:!0});let G=await i("fnode build",{cwd:q});if(G.code!==0)throw Error("Failed to build project.");if(c("git")){if(G=await i("git init --initial-branch=main",{cwd:q}),G.code!==0)throw Error("Failed to initialize git.")}if(c("code")&&$.vscode){if(G=await i(`cd ${q} && code .`),G.code!==0)throw Error("Failed to open vscode.")}console.log("Creating project succeeded!"),process.exit(0)}catch(W){console.error("Initialization failed!",W.message),process.exit(1)}}},G1=S1;import b1 from"node:os";import y1 from"@flownet/lib-render-templates-dir";import D1 from"@fnet/shelljs";var f1={command:"project",describe:"Manage fnode project",builder:($)=>{return $.option("update",{type:"boolean",default:!1,alias:"-u",describe:"Update project files"})},handler:async($)=>{try{let W=E("./template/fnode/project"),z=process.cwd(),q=await O($);if($.update){if(await y1({dir:W,outDir:z,context:{name:q.project.projectFileParsed.name,runtime:q.project.runtime.type,platform:b1.platform()},copyUnmatchedAlso:!0}),(await D1("fnode build",{cwd:z})).code!==0)throw Error("Failed to build project.");console.log("Updating project succeeded!")}process.exit(0)}catch(W){console.error("Project failed.",W.message),process.exit(1)}}},Q1=f1;class Z1{static async createBuilder($){if(!$.project)return console.warn("No project provided, defaulting to node runtime"),new(await import("./index.k98v9acr.js")).default($);let W=$.project?.runtime?.type||"node";try{return new(await this.loadBuilderClass(W))($)}catch(z){throw Error(`Failed to create builder for runtime '${W}': ${z.message}`)}}static async loadBuilderClass($){switch($.toLowerCase()){case"node":case"bun":return(await import("./index.k98v9acr.js")).default;case"python":return(await import("./index.1nyzphey.js")).default;default:throw Error(`Unsupported runtime type: ${$}`)}}}var R=Z1;var u1={command:"build",describe:"Build fnode project",builder:($)=>{return $.option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("mode",{type:"string",default:"build",choices:["all","file","build","deploy","bpmn"],describe:"Build mode"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}).option("dev",{type:"boolean",default:!1,describe:"Development mode"}).option("bpmn",{type:"boolean",default:!1,describe:"Generate BPMN diagram"})},handler:async($)=>{try{let W=await O($),z=await R.createBuilder(W);await z.init(),await z.build(),console.log("Building library succeeded!"),process.exit(0)}catch(W){console.error("Building library failed!",W.message),process.exit(1)}}},Y1=u1;var v1={command:"build:dev",describe:"Build fnode project",builder:($)=>{return $.option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("mode",{type:"string",default:"build",choices:["all","file","build","deploy","bpmn"],describe:"Build mode"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}).option("dev",{type:"boolean",default:!1,describe:"Development mode"}).option("bpmn",{type:"boolean",default:!1,describe:"Generate BPMN diagram"})},handler:async($)=>{try{$.dev=!0;let W=await O($),z=await R.createBuilder(W);await z.init(),await z.build(),console.log("Building library succeeded!"),process.exit(0)}catch(W){console.error("Building library failed!",W.message),process.exit(1)}}},K1=v1;var P1={command:"deploy",describe:"Build and deploy fnode project",builder:($)=>{return $.option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"})},handler:async($)=>{try{let W=await O({...$,mode:"all"}),z=await R.createBuilder(W);await z.init(),await z.build(),console.log("Building library succeeded!"),process.exit(0)}catch(W){console.error("Building library failed!",W.message),process.exit(1)}}},U1=P1;var j1={command:"file",describe:"Just create files",builder:($)=>{return $.option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"})},handler:async($)=>{try{let W=await O({...$,mode:"file"}),z=await R.createBuilder(W);await z.init(),await z.build(),console.log("Building library succeeded!"),process.exit(0)}catch(W){console.error("Building library failed!",W.message),process.exit(1)}}},J1=j1;import M1 from"node:path";import P from"node:fs";import d1 from"@fnet/prompt";var m1={command:"input [name]",describe:"Create or modify an input config file",builder:($)=>{return $.positional("name",{type:"string",demandOption:!1,describe:"Input name"})},handler:async($)=>{try{let W=await O($),{project:z}=W,{projectDir:q,projectFileParsed:G}=z,Z=G.input;if(!Z)throw Error("Config schema not found in project file.");if(!Reflect.has($,"name")){let{inputName:K}=await d1({type:"input",name:"inputName",message:"Input name:",initial:"dev"});$.name=K}let Q=M1.resolve(q,".fnet");if(!P.existsSync(Q))P.mkdirSync(Q);let Y=M1.resolve(Q,`${$.name}.fnet`),L=P.existsSync(Y),M=(await import("@fnet/object-from-schema")).default,J=await M({schema:Z,format:"yaml",ref:L?Y:void 0});P.writeFileSync(Y,J)}catch(W){console.error(W.message),process.exit(1)}}},H1=m1;import V from"node:path";import H from"node:fs";import d from"node:os";import{spawn as m}from"node:child_process";import U from"chalk";import A from"@fnet/prompt";import j from"chalk";import L1 from"@fnet/prompt";async function g1($){let{items:W,message:z,nameField:q="name",valueField:G="name",initialValue:Z=null,allowAbort:Q=!0}=$;if(!W||W.length===0)return console.log(j.yellow("No items available for selection.")),null;if(W.length===1&&!Q){let K=W[0],T=typeof K==="string"?K:K[G];return console.log(j.blue(`Only one option available: ${typeof K==="string"?K:K[q]}`)),T}let Y=W.map((K)=>{if(typeof K==="string")return{name:K,value:K,message:K};else return{name:K[G],value:K[G],message:K[q]||K[G]}});if(Q)Y.push({name:"cancel",value:null,message:j.yellow("Cancel")});let L=null;if(Z){let K=Y.findIndex((T)=>T.name===Z);if(K!==-1)L=K}let M="selectedItem",{[M]:J}=await L1({type:"select",name:M,message:z,choices:Y,initial:L});if(J==="cancel")return null;return J}async function h1($){let{items:W,message:z,nameField:q="name",valueField:G="name",initialValues:Z=[],allowAbort:Q=!0}=$;if(!W||W.length===0)return console.log(j.yellow("No items available for selection.")),null;let Y=W.map((K)=>{if(typeof K==="string")return{name:K,value:K,message:K};else return{name:K[G],value:K[G],message:K[q]||K[G]}}),L=[];if(Z&&Z.length>0)L=Y.map((K,T)=>Z.includes(K.name)?T:-1).filter((K)=>K!==-1);let M="selectedItems",J=await L1({type:"multiselect",name:M,message:z,choices:Y,initial:L,hint:"(Use space to select, enter to confirm)",validate:(K)=>{if(K.length===0&&!Q)return"Please select at least one item";return!0}});if(Q&&J[M].length===0)return null;return J[M]}var o={promptForSelection:g1,promptForMultipleSelection:h1};var X=V.join(d.homedir(),".fnet","express");async function V1($){$.command(["$0 [project-name]","create [project-name]"],"Create a new express project",(W)=>{return W.positional("project-name",{describe:"Name of the project",type:"string"}).option("yes",{alias:"y",describe:"Skip all prompts and use defaults",type:"boolean",default:!1}).option("runtime",{describe:"Runtime to use (node, python, bun)",type:"string",choices:["node","python","bun"],default:"node"})},async(W)=>{await l1(W)}).command("list","List express projects",(W)=>{return W.option("today",{describe:"Show only projects created today",type:"boolean",default:!1}).option("type",{describe:"Filter by project type (fnode or fnet)",type:"string",choices:["fnode","fnet"]}).option("all",{describe:"Show all projects regardless of type",type:"boolean",default:!1,alias:"a"}).option("name",{describe:"Filter by project name",type:"string"})},async(W)=>{await p1(W)}).command("open [project-name]","Open an express project",(W)=>{return W.positional("project-name",{describe:"Name of the project to open",type:"string"}).option("latest",{describe:"Open the most recent project",type:"boolean",default:!1})},async(W)=>{await n1(W)}).command("move [project-name] [destination]","Move an express project to a real project location",(W)=>{return W.positional("project-name",{describe:"Name of the project to move",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).option("latest",{describe:"Move the most recent project",type:"boolean",default:!1})},async(W)=>{await i1(W)}).command("remove [project-name]","Remove an express project",(W)=>{return W.positional("project-name",{describe:"Name of the project to remove",type:"string"}).option("latest",{describe:"Remove the most recent project",type:"boolean",default:!1}).option("yes",{alias:"y",describe:"Skip confirmation prompt",type:"boolean",default:!1})},async(W)=>{await o1(W)}).command("enter [project-name]","Enter the directory of an express project in the active terminal",(W)=>{return W.positional("project-name",{describe:"Name of the project to enter",type:"string"}).option("latest",{describe:"Enter the most recent project directory",type:"boolean",default:!1})},async(W)=>{await s1(W)}).demandCommand(1,"You need to specify a command").help()}async function l1($){try{if(!H.existsSync(X))H.mkdirSync(X,{recursive:!0});let W=new Date().toISOString().slice(0,10).replace(/-/g,""),z=V.join(X,W);if(!H.existsSync(z))H.mkdirSync(z,{recursive:!0});let q=$.projectName,G,Z=$.runtime;if(!$.yes){if(!q){let T=H.readdirSync(z).filter((F)=>F.startsWith("fnode-")).map((F)=>parseInt(F.replace("fnode-",""),10)).filter((F)=>!isNaN(F)),D=`fnode-${T.length>0?Math.max(...T)+1:1}`;q=(await A([{type:"input",name:"projectName",message:"Enter project name:",default:D}])).projectName}Z=(await A({type:"select",name:"runtime",message:"Select runtime:",choices:["node","python","bun"],initial:Z||"node"})).runtime}else{if(!q){let J=H.readdirSync(z).filter((T)=>T.startsWith("fnode-")).map((T)=>parseInt(T.replace("fnode-",""),10)).filter((T)=>!isNaN(T));q=`fnode-${J.length>0?Math.max(...J)+1:1}`}if(!Z)Z="node"}if(G=V.join(z,q),H.existsSync(G)){let J=1;while(H.existsSync(V.join(z,`${q}-${J}`)))J++;q=`${q}-${J}`,G=V.join(z,q)}if(!$.yes){if(!(await A([{type:"confirm",name:"proceed",message:`Create express project "${q}" in ${G}?`,default:!0}])).proceed){console.log(U.yellow("Project creation cancelled."));return}}console.log(U.blue(`Creating express project "${q}" in ${G}...`));let Q=V.dirname(G),L=["create","--name",V.basename(G)];if(L.push("--runtime",Z),$.yes)L.push("--yes");if(!H.existsSync(Q))H.mkdirSync(Q,{recursive:!0});let M=m("fnode",L,{stdio:"inherit",shell:!0,cwd:Q});return new Promise((J,K)=>{M.on("close",(T)=>{if(T===0)if(console.log(U.green(`
2
+ import{e as E}from"./index.9qgtmxq3.js";import{f as c}from"./index.05n3mvs9.js";import{i as k}from"./index.cvxrf34y.js";import q$ from"yargs";import w1 from"chalk";import{promisify as I1}from"node:util";import F1 from"tree-kill";var r=I1(F1),N=!1;async function n($,W){if(N)return;if(N=!0,!$.killed&&$.pid)try{if(await r($.pid,"SIGTERM").catch(()=>{}),await new Promise((q)=>setTimeout(q,500)),!$.killed)await r($.pid,"SIGKILL").catch(()=>{})}catch(q){}await new Promise((q)=>setTimeout(q,100));let z=W==="SIGINT"?130:W==="SIGTERM"?143:1;process.exit(z)}function S($){["SIGINT","SIGTERM","SIGQUIT"].forEach((W)=>{process.once(W,async()=>{await n($,W)})}),process.on("uncaughtException",async(W)=>{await n($)}),process.on("unhandledRejection",async(W)=>{await n($)}),$.on("close",(W)=>{if(!N)process.exit(W)})}function a(){process.on("uncaughtException",($)=>{if(!N)N=!0,setTimeout(()=>process.exit(1),500)}),process.on("unhandledRejection",($)=>{if(!N)N=!0,setTimeout(()=>process.exit(1),500)})}import x from"node:path";import{spawn as P}from"node:child_process";import u from"node:fs";import b from"chalk";import _1 from"@fnet/config";function C($,{name:W,bin:z,preArgs:q=[],createContext:G}){if(typeof z==="function")z=z();return $.command(`${W||z} [commands..]`,`${z} ${q.join(" ")}`,(Z)=>{return Z.help(!1).version(!1)},async(Z)=>{try{let Q=await G(Z),{projectDir:Y}=Q,L=(I)=>{if(!I.includes(" "))return I;if(process.platform==="win32")return`"${I.replace(/(["^])/g,"^$1")}"`;else return`"${I.replace(/(["\\$`])/g,"\\$1")}"`},M=process.argv.slice(3).map(L),J={...process.env},K=x.join(Y,"node_modules");J.NODE_PATH=K,J.NODE_PRESERVE_SYMLINKS=1;let T=P(z,[...q,...M],{cwd:Y,stdio:"inherit",shell:!0,detached:!0,env:J});S(T)}catch(Q){console.error(Q.message),process.exit(1)}})}function y($,{name:W,bin:z,preArgs:q=[],createContext:G}){return $.command(`${W||z} [commands..]`,`${z} ${q.join(" ")}`,(Z)=>{return Z.help(!1).version(!1)},async(Z)=>{try{let Q=await G(Z),{projectDir:Y}=Q,L=(K)=>{if(!K.includes(" "))return K;if(process.platform==="win32")return`"${K.replace(/(["^])/g,"^$1")}"`;else return`"${K.replace(/(["\\$`])/g,"\\$1")}"`},M=process.argv.slice(3).map(L);z=x.join(Y,".conda","bin",z||W);let J=P(z,[...q,...M],{cwd:Y,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:Y}});S(J)}catch(Q){console.error(Q.message),process.exit(1)}})}function t($,{name:W,createContext:z}){return $.command(`${W} <binary> [commands..]`,"Run a binary from conda environment",(q)=>{return q.positional("binary",{type:"string",describe:"Binary name to run from .conda/bin"}).help(!1).version(!1)},async(q)=>{try{let G=await z(q),{projectDir:Z}=G,Q=(K)=>{if(!K.includes(" "))return K;if(process.platform==="win32")return`"${K.replace(/(["^])/g,"^$1")}"`;else return`"${K.replace(/(["\\$`])/g,"\\$1")}"`},Y=q.binary,L=process.argv.slice(4).map(Q),M=x.join(Z,".conda","bin",Y),J=P(M,L,{cwd:Z,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:Z}});S(J)}catch(G){console.error(G.message),process.exit(1)}})}function e($,{name:W,preArgs:z=[],createContext:q}){return $.command(`${W} <config> <command> [options..]`,"Run a command with a config context",(G)=>{return G.positional("config",{type:"string"}).positional("command",{type:"string"}).help(!1).version(!1)},async(G)=>{try{let Z=await q(G),{projectDir:Q}=Z,Y=G.config,M=(await _1({name:Y,dir:Q,transferEnv:!1,optional:!0,tags:Z.tags}))?.data?.env||void 0,J=G.command,K=process.argv.slice(5),T=P(J,[...z,...K],{cwd:u.existsSync(Q)?Q:process.cwd(),stdio:"inherit",shell:!0,detached:!0,env:{...process.env,...M}});S(T)}catch(Z){console.error(Z.message),process.exit(1)}})}function $1($,{name:W,projectType:z="auto"}){return $.command(`${W} group [options..]`,"Run a command group.",(q)=>{return q.positional("group",{type:"string"}).option("ftag",{type:"array"}).help(!1).version(!1)},async(q)=>{try{let{runCommandGroup:G}=await import("./index.2pnjg6dc.js");await G({projectType:z,group:q.group,tags:q.ftag,args:q,argv:process.argv})}catch(G){console.error(G.message),process.exit(1)}})}function W1($,{name:W,createContext:z}){return $.command(`${W} [options]`,"Install the project as a binary",(q)=>{return q.option("name",{alias:"n",describe:"Name to use for the installed binary",type:"string"}).option("force",{alias:"f",describe:"Force overwrite if binary already exists",type:"boolean",default:!1}).option("yes",{alias:"y",describe:"Automatically answer yes to all prompts",type:"boolean",default:!1})},async(q)=>{try{let G=await z(q),{projectDir:Z}=G;console.log(b.blue("Compiling project..."));let Q=x.join(Z,".bin");if(!u.existsSync(Q))u.mkdirSync(Q,{recursive:!0});let Y=x.basename(x.dirname(Z)),L=G.project?.projectFileParsed?.features?.cli?.bin,M=q.name||L||Y;console.log(b.blue(`Using binary name: ${M}`));let J=x.join(Q,M),{spawn:K}=await import("child_process"),T=K("bun",["build","./dist/cli/esm/index.js","--compile",`--outfile=${J}`],{cwd:Z,stdio:"inherit",shell:!0});if(await new Promise((f,F)=>{T.on("close",(_)=>{if(_===0)f();else F(Error(`Compilation failed with code ${_}`))}),T.on("error",(_)=>{F(_)})}),process.platform!=="win32")u.chmodSync(J,493);console.log(b.green(`Binary compiled successfully: ${J}`)),console.log(b.blue("Installing binary..."));let I=["install",J];if(q.name)I.push("--name",q.name);if(q.force)I.push("--force");if(q.yes)I.push("--yes");let D=K("fbin",I,{stdio:"inherit",shell:!0});await new Promise((f,F)=>{D.on("close",(_)=>{if(_===0)f();else F(Error(`Installation failed with code ${_}`))}),D.on("error",(_)=>{F(_)})})}catch(G){console.error(b.red(`Failed to install binary: ${G.message}`)),process.exit(1)}})}import w from"node:path";import B from"node:fs";import q1 from"@fnet/yaml";import A1 from"yaml";async function O($){if($.id)return{id:$.id,buildId:$.buildId,mode:$.mode,protocol:$.protocol||"ac:",templateDir:E("./template/fnode/node"),projectDir:w.resolve(process.cwd(),`./.output/${$.id}`),tags:$.ftag,dev:$.dev,bpmn:$.bpmn===!0};else try{let W=await R1({tags:$.ftag}),z=W.runtime.type==="bun"?"node":W.runtime.type;return{buildId:$.buildId,mode:$.mode,protocol:$.protocol||"src:",templateDir:E(`./template/fnode/${z}`),projectDir:w.resolve(W.projectDir,"./.workspace"),projectSrcDir:w.resolve(W.projectDir,"./src"),projectSrcDirSymlink:w.resolve(W.projectDir,"./.workspace/src-core"),projectAppDir:w.resolve(W.projectDir,"./app"),projectAppDirSymlink:w.resolve(W.projectDir,"./.workspace/app"),projectCliDir:w.resolve(W.projectDir,"./cli"),projectCliDirSymlink:w.resolve(W.projectDir,"./.workspace/cli"),project:W,tags:$.ftag,dev:$.dev,bpmn:$.bpmn===!0}}catch(W){return console.warn(`Warning: Could not load project: ${W.message}`),{projectDir:process.cwd(),tags:$.ftag}}}async function R1({tags:$}){let W=N1(process.cwd());if(!B.existsSync(W))throw Error("fnode.yaml file not found in current directory.");let{raw:z,parsed:q}=await q1({file:W,tags:$}),G=w.dirname(W);q.features=q.features||{};let Z=q.features;if(Z.runtime=Z.runtime||{},Z.runtime.type=Z.runtime.type||"node",Z.runtime.type==="python")Z.runtime.template=Z.runtime.template||"python";else if(Z.runtime.type==="bun")Z.runtime.template=Z.runtime.template||"node";else Z.runtime.template=Z.runtime.template||"node";let Q={libraryAtom:{doc:{...q},fileName:"index"},projectDir:G,projectFilePath:W,projectFileContent:z,projectFileParsed:q,runtime:Z.runtime},Y=w.resolve(G,"fnet/targets.yaml");if(!B.existsSync(Y)){if(Y=w.resolve(G,"node.devops.yaml"),B.existsSync(Y)){let M=w.resolve(G,"fnet");if(!B.existsSync(M))B.mkdirSync(M);B.copyFileSync(Y,w.resolve(G,"fnet/targets.yaml")),B.unlinkSync(Y)}}if(B.existsSync(Y)){let{raw:M,parsed:J}=await q1({file:Y,tags:$}),K=A1.parseDocument(M);Q.devops={filePath:Y,fileContent:M,yamlDocument:K,doc:{...J},type:"library.deploy",save:async()=>{B.writeFileSync(Q.devops.filePath,K.toString())}}}let L=w.resolve(G,"readme.md");if(B.existsSync(L)){let M=B.readFileSync(L,"utf8");Q.readme={filePath:L,fileContent:M,doc:{content:M,"content-type":"markdown"},type:"wiki"}}return Q}function N1($){let W=w.resolve($,"node.yaml"),z=w.resolve($,"fnode.yaml");if(B.existsSync(z))return z;if(B.existsSync(W))try{let q=B.readFileSync(W,"utf8");return B.writeFileSync(z,q,"utf8"),B.unlinkSync(W),console.log(`Migrated node.yaml to fnode.yaml in ${$}`),z}catch(q){return console.error(`Error migrating node.yaml to fnode.yaml: ${q.message}`),W}return z}import x1 from"node:path";import z1 from"node:fs";import k1 from"node:os";import E1 from"@flownet/lib-render-templates-dir";import i from"@fnet/shelljs";var S1={command:"create",describe:"Create a new fnode project",builder:($)=>{return $.option("name",{type:"string",describe:"Project name",demandOption:!0}).option("vscode",{type:"boolean",default:!0,alias:"vs",describe:"Open in VS Code after creation"}).option("runtime",{type:"string",default:"node",choices:["node","python","bun"],describe:"Runtime environment"})},handler:async($)=>{try{let W=process.cwd(),z=E("./template/fnode/project"),q=x1.resolve(W,$.name);if(!z1.existsSync(q))z1.mkdirSync(q);await E1({dir:z,outDir:q,context:{name:$.name,runtime:$.runtime,platform:k1.platform()},copyUnmatchedAlso:!0});let G=await i("fnode build",{cwd:q});if(G.code!==0)throw Error("Failed to build project.");if(c("git")){if(G=await i("git init --initial-branch=main",{cwd:q}),G.code!==0)throw Error("Failed to initialize git.")}if(c("code")&&$.vscode){if(G=await i(`cd ${q} && code .`),G.code!==0)throw Error("Failed to open vscode.")}console.log("Creating project succeeded!"),process.exit(0)}catch(W){console.error("Initialization failed!",W.message),process.exit(1)}}},G1=S1;import b1 from"node:os";import y1 from"@flownet/lib-render-templates-dir";import D1 from"@fnet/shelljs";var f1={command:"project",describe:"Manage fnode project",builder:($)=>{return $.option("update",{type:"boolean",default:!1,alias:"-u",describe:"Update project files"})},handler:async($)=>{try{let W=E("./template/fnode/project"),z=process.cwd(),q=await O($);if($.update){if(await y1({dir:W,outDir:z,context:{name:q.project.projectFileParsed.name,runtime:q.project.runtime.type,platform:b1.platform()},copyUnmatchedAlso:!0}),(await D1("fnode build",{cwd:z})).code!==0)throw Error("Failed to build project.");console.log("Updating project succeeded!")}process.exit(0)}catch(W){console.error("Project failed.",W.message),process.exit(1)}}},Q1=f1;class Z1{static async createBuilder($){if(!$.project)return console.warn("No project provided, defaulting to node runtime"),new(await import("./index.k98v9acr.js")).default($);let W=$.project?.runtime?.type||"node";try{return new(await this.loadBuilderClass(W))($)}catch(z){throw Error(`Failed to create builder for runtime '${W}': ${z.message}`)}}static async loadBuilderClass($){switch($.toLowerCase()){case"node":case"bun":return(await import("./index.k98v9acr.js")).default;case"python":return(await import("./index.1nyzphey.js")).default;default:throw Error(`Unsupported runtime type: ${$}`)}}}var R=Z1;var u1={command:"build",describe:"Build fnode project",builder:($)=>{return $.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("mode",{type:"string",default:"build",choices:["all","file","build","deploy","bpmn"],describe:"Build mode"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}).option("dev",{type:"boolean",default:!1,describe:"Development mode"}).option("bpmn",{type:"boolean",default:!1,describe:"Generate BPMN diagram"})},handler:async($)=>{try{let W=await O($),z=await R.createBuilder(W);await z.init(),await z.build(),console.log("Building library succeeded!"),process.exit(0)}catch(W){console.error("Building library failed!",W.message),process.exit(1)}}},Y1=u1;var P1={command:"build:dev",describe:"Build fnode project",builder:($)=>{return $.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("mode",{type:"string",default:"build",choices:["all","file","build","deploy","bpmn"],describe:"Build mode"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}).option("dev",{type:"boolean",default:!1,describe:"Development mode"}).option("bpmn",{type:"boolean",default:!1,describe:"Generate BPMN diagram"})},handler:async($)=>{try{$.dev=!0;let W=await O($),z=await R.createBuilder(W);await z.init(),await z.build(),console.log("Building library succeeded!"),process.exit(0)}catch(W){console.error("Building library failed!",W.message),process.exit(1)}}},K1=P1;var v1={command:"deploy",describe:"Build and deploy fnode project",builder:($)=>{return $.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"})},handler:async($)=>{try{let W=await O({...$,mode:"all"}),z=await R.createBuilder(W);await z.init(),await z.build(),console.log("Building library succeeded!"),process.exit(0)}catch(W){console.error("Building library failed!",W.message),process.exit(1)}}},U1=v1;var j1={command:"file",describe:"Just create files",builder:($)=>{return $.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"})},handler:async($)=>{try{let W=await O({...$,mode:"file"}),z=await R.createBuilder(W);await z.init(),await z.build(),console.log("Building library succeeded!"),process.exit(0)}catch(W){console.error("Building library failed!",W.message),process.exit(1)}}},J1=j1;import M1 from"node:path";import v from"node:fs";import d1 from"@fnet/prompt";var m1={command:"input [name]",describe:"Create or modify an input config file",builder:($)=>{return $.positional("name",{type:"string",demandOption:!1,describe:"Input name"})},handler:async($)=>{try{let W=await O($),{project:z}=W,{projectDir:q,projectFileParsed:G}=z,Z=G.input;if(!Z)throw Error("Config schema not found in project file.");if(!Reflect.has($,"name")){let{inputName:K}=await d1({type:"input",name:"inputName",message:"Input name:",initial:"dev"});$.name=K}let Q=M1.resolve(q,".fnet");if(!v.existsSync(Q))v.mkdirSync(Q);let Y=M1.resolve(Q,`${$.name}.fnet`),L=v.existsSync(Y),M=(await import("@fnet/object-from-schema")).default,J=await M({schema:Z,format:"yaml",ref:L?Y:void 0});v.writeFileSync(Y,J)}catch(W){console.error(W.message),process.exit(1)}}},H1=m1;import V from"node:path";import H from"node:fs";import d from"node:os";import{spawn as m}from"node:child_process";import U from"chalk";import A from"@fnet/prompt";import j from"chalk";import L1 from"@fnet/prompt";async function g1($){let{items:W,message:z,nameField:q="name",valueField:G="name",initialValue:Z=null,allowAbort:Q=!0}=$;if(!W||W.length===0)return console.log(j.yellow("No items available for selection.")),null;if(W.length===1&&!Q){let K=W[0],T=typeof K==="string"?K:K[G];return console.log(j.blue(`Only one option available: ${typeof K==="string"?K:K[q]}`)),T}let Y=W.map((K)=>{if(typeof K==="string")return{name:K,value:K,message:K};else return{name:K[G],value:K[G],message:K[q]||K[G]}});if(Q)Y.push({name:"cancel",value:null,message:j.yellow("Cancel")});let L=null;if(Z){let K=Y.findIndex((T)=>T.name===Z);if(K!==-1)L=K}let M="selectedItem",{[M]:J}=await L1({type:"select",name:M,message:z,choices:Y,initial:L});if(J==="cancel")return null;return J}async function h1($){let{items:W,message:z,nameField:q="name",valueField:G="name",initialValues:Z=[],allowAbort:Q=!0}=$;if(!W||W.length===0)return console.log(j.yellow("No items available for selection.")),null;let Y=W.map((K)=>{if(typeof K==="string")return{name:K,value:K,message:K};else return{name:K[G],value:K[G],message:K[q]||K[G]}}),L=[];if(Z&&Z.length>0)L=Y.map((K,T)=>Z.includes(K.name)?T:-1).filter((K)=>K!==-1);let M="selectedItems",J=await L1({type:"multiselect",name:M,message:z,choices:Y,initial:L,hint:"(Use space to select, enter to confirm)",validate:(K)=>{if(K.length===0&&!Q)return"Please select at least one item";return!0}});if(Q&&J[M].length===0)return null;return J[M]}var o={promptForSelection:g1,promptForMultipleSelection:h1};var X=V.join(d.homedir(),".fnet","express");async function V1($){$.command(["$0 [project-name]","create [project-name]"],"Create a new express project",(W)=>{return W.positional("project-name",{describe:"Name of the project",type:"string"}).option("yes",{alias:"y",describe:"Skip all prompts and use defaults",type:"boolean",default:!1}).option("runtime",{describe:"Runtime to use (node, python, bun)",type:"string",choices:["node","python","bun"],default:"node"})},async(W)=>{await l1(W)}).command("list","List express projects",(W)=>{return W.option("today",{describe:"Show only projects created today",type:"boolean",default:!1}).option("type",{describe:"Filter by project type (fnode or fnet)",type:"string",choices:["fnode","fnet"]}).option("all",{describe:"Show all projects regardless of type",type:"boolean",default:!1,alias:"a"}).option("name",{describe:"Filter by project name",type:"string"})},async(W)=>{await p1(W)}).command("open [project-name]","Open an express project",(W)=>{return W.positional("project-name",{describe:"Name of the project to open",type:"string"}).option("latest",{describe:"Open the most recent project",type:"boolean",default:!1})},async(W)=>{await n1(W)}).command("move [project-name] [destination]","Move an express project to a real project location",(W)=>{return W.positional("project-name",{describe:"Name of the project to move",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).option("latest",{describe:"Move the most recent project",type:"boolean",default:!1})},async(W)=>{await i1(W)}).command("remove [project-name]","Remove an express project",(W)=>{return W.positional("project-name",{describe:"Name of the project to remove",type:"string"}).option("latest",{describe:"Remove the most recent project",type:"boolean",default:!1}).option("yes",{alias:"y",describe:"Skip confirmation prompt",type:"boolean",default:!1})},async(W)=>{await o1(W)}).command("enter [project-name]","Enter the directory of an express project in the active terminal",(W)=>{return W.positional("project-name",{describe:"Name of the project to enter",type:"string"}).option("latest",{describe:"Enter the most recent project directory",type:"boolean",default:!1})},async(W)=>{await s1(W)}).demandCommand(1,"You need to specify a command").help()}async function l1($){try{if(!H.existsSync(X))H.mkdirSync(X,{recursive:!0});let W=new Date().toISOString().slice(0,10).replace(/-/g,""),z=V.join(X,W);if(!H.existsSync(z))H.mkdirSync(z,{recursive:!0});let q=$.projectName,G,Z=$.runtime;if(!$.yes){if(!q){let T=H.readdirSync(z).filter((F)=>F.startsWith("fnode-")).map((F)=>parseInt(F.replace("fnode-",""),10)).filter((F)=>!isNaN(F)),D=`fnode-${T.length>0?Math.max(...T)+1:1}`;q=(await A([{type:"input",name:"projectName",message:"Enter project name:",default:D}])).projectName}Z=(await A({type:"select",name:"runtime",message:"Select runtime:",choices:["node","python","bun"],initial:Z||"node"})).runtime}else{if(!q){let J=H.readdirSync(z).filter((T)=>T.startsWith("fnode-")).map((T)=>parseInt(T.replace("fnode-",""),10)).filter((T)=>!isNaN(T));q=`fnode-${J.length>0?Math.max(...J)+1:1}`}if(!Z)Z="node"}if(G=V.join(z,q),H.existsSync(G)){let J=1;while(H.existsSync(V.join(z,`${q}-${J}`)))J++;q=`${q}-${J}`,G=V.join(z,q)}if(!$.yes){if(!(await A([{type:"confirm",name:"proceed",message:`Create express project "${q}" in ${G}?`,default:!0}])).proceed){console.log(U.yellow("Project creation cancelled."));return}}console.log(U.blue(`Creating express project "${q}" in ${G}...`));let Q=V.dirname(G),L=["create","--name",V.basename(G)];if(L.push("--runtime",Z),$.yes)L.push("--yes");if(!H.existsSync(Q))H.mkdirSync(Q,{recursive:!0});let M=m("fnode",L,{stdio:"inherit",shell:!0,cwd:Q});return new Promise((J,K)=>{M.on("close",(T)=>{if(T===0)if(console.log(U.green(`
3
3
  Express project "${q}" created successfully!`)),console.log(U.blue(`
4
4
  Project location: ${G}`)),!$.yes)c1(G);else J();else console.error(U.red(`
5
5
  Failed to create express project "${q}".`)),K(Error(`Process exited with code ${T}`))})})}catch(W){console.error(U.red(`Error creating express project: ${W.message}`)),process.exit(1)}}async function p1($){try{if(!H.existsSync(X)){console.log(U.yellow("No express projects found."));return}let W=H.readdirSync(X).filter((Q)=>/^\d{8}$/.test(Q)).sort((Q,Y)=>Y.localeCompare(Q));if($.today){let Q=new Date().toISOString().slice(0,10).replace(/-/g,""),Y=W.indexOf(Q);if(Y===-1){console.log(U.yellow("No express projects found for today."));return}W.splice(0,Y),W.splice(1)}let z=[];if(!$.type&&!$.all)$.type="fnode";for(let Q of W){let Y=V.join(X,Q),L=H.readdirSync(Y);for(let M of L){let J=V.join(Y,M),K=H.statSync(J),T="unknown";if(M.startsWith("fnode-")||H.existsSync(V.join(J,"fnode.yaml")))T="fnode";else if(M.startsWith("fnet-")||H.existsSync(V.join(J,"fnet.yaml")))T="fnet";if($.type&&T!==$.type)continue;if($.name&&!M.includes($.name))continue;let I=`${Q.slice(0,4)}-${Q.slice(4,6)}-${Q.slice(6,8)}`;z.push({name:M,type:T,date:I,path:J,created:K.birthtime})}}if(z.sort((Q,Y)=>Y.created-Q.created),z.length===0){console.log(U.yellow("No express projects found matching the criteria."));return}console.log(U.blue(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fnet/cli",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "files": [
5
5
  "dist",
6
6
  "template"