@fnet/cli 1.0.12 → 1.0.13
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/fnode/index.js +9 -9
- package/package.json +1 -1
package/dist/fnode/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{e as S}from"./index.9qgtmxq3.js";import{f as o}from"./index.05n3mvs9.js";import{g as x,i as k}from"./index.cvxrf34y.js";import q$ from"yargs";import B1 from"chalk";import{promisify as I1}from"node:util";import F1 from"tree-kill";var a=I1(F1),N=!1;async function n($,W){if(N)return;if(N=!0,!$.killed&&$.pid)try{if(await a($.pid,"SIGTERM").catch(()=>{}),await new Promise((q)=>setTimeout(q,500)),!$.killed)await a($.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 u($){["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 t(){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 E from"node:path";import{spawn as i}from"node:child_process";import v 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,O=(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(O),J={...process.env},U=E.join(Y,"node_modules");J.NODE_PATH=U,J.NODE_PRESERVE_SYMLINKS=1;let T=i(z,[...q,...M],{cwd:Y,stdio:"inherit",shell:!0,detached:!0,env:J});u(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,O=(U)=>{if(!U.includes(" "))return U;if(process.platform==="win32")return`"${U.replace(/(["^])/g,"^$1")}"`;else return`"${U.replace(/(["\\$`])/g,"\\$1")}"`},M=process.argv.slice(3).map(O);z=E.join(Y,".conda","bin",z||W);let J=i(z,[...q,...M],{cwd:Y,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:Y}});u(J)}catch(Q){console.error(Q.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,U=process.argv.slice(5),T=i(J,[...z,...U],{cwd:v.existsSync(Q)?Q:process.cwd(),stdio:"inherit",shell:!0,detached:!0,env:{...process.env,...M}});u(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=E.join(Z,".bin");if(!v.existsSync(Q))v.mkdirSync(Q,{recursive:!0});let Y=E.basename(E.dirname(Z)),O=G.project?.projectFileParsed?.features?.cli?.bin,M=q.name||O||Y;console.log(b.blue(`Using binary name: ${M}`));let J=E.join(Q,M),{spawn:U}=await import("child_process"),T=U("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")v.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=U("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 B from"node:path";import w from"node:fs";import q1 from"@fnet/yaml";import A1 from"yaml";async function V($){if($.id)return{id:$.id,buildId:$.buildId,mode:$.mode,protocol:$.protocol||"ac:",templateDir:S("./template/fnode/node"),projectDir:B.resolve(process.cwd(),`./.output/${$.id}`),tags:$.ftag,dev:$.dev};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:S(`./template/fnode/${z}`),projectDir:B.resolve(W.projectDir,"./.workspace"),projectSrcDir:B.resolve(W.projectDir,"./src"),projectSrcDirSymlink:B.resolve(W.projectDir,"./.workspace/src-core"),projectAppDir:B.resolve(W.projectDir,"./app"),projectAppDirSymlink:B.resolve(W.projectDir,"./.workspace/app"),projectCliDir:B.resolve(W.projectDir,"./cli"),projectCliDirSymlink:B.resolve(W.projectDir,"./.workspace/cli"),project:W,tags:$.ftag,dev:$.dev}}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(!w.existsSync(W))throw Error("fnode.yaml file not found in current directory.");let{raw:z,parsed:q}=await q1({file:W,tags:$}),G=B.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=B.resolve(G,"fnet/targets.yaml");if(!w.existsSync(Y)){if(Y=B.resolve(G,"node.devops.yaml"),w.existsSync(Y)){let M=B.resolve(G,"fnet");if(!w.existsSync(M))w.mkdirSync(M);w.copyFileSync(Y,B.resolve(G,"fnet/targets.yaml")),w.unlinkSync(Y)}}if(w.existsSync(Y)){let{raw:M,parsed:J}=await q1({file:Y,tags:$}),U=A1.parseDocument(M);Q.devops={filePath:Y,fileContent:M,yamlDocument:U,doc:{...J},type:"library.deploy",save:async()=>{w.writeFileSync(Q.devops.filePath,U.toString())}}}let O=B.resolve(G,"readme.md");if(w.existsSync(O)){let M=w.readFileSync(O,"utf8");Q.readme={filePath:O,fileContent:M,doc:{content:M,"content-type":"markdown"},type:"wiki"}}return Q}function N1($){let W=B.resolve($,"node.yaml"),z=B.resolve($,"fnode.yaml");if(w.existsSync(z))return z;if(w.existsSync(W))try{let q=w.readFileSync(W,"utf8");return w.writeFileSync(z,q,"utf8"),w.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 S1 from"@flownet/lib-render-templates-dir";import c from"@fnet/shelljs";var E1={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=S("./template/fnode/project"),q=x1.resolve(W,$.name);if(!z1.existsSync(q))z1.mkdirSync(q);await S1({dir:z,outDir:q,context:{name:$.name,runtime:$.runtime,platform:k1.platform()},copyUnmatchedAlso:!0});let G=await c("fnode build",{cwd:q});if(G.code!==0)throw Error("Failed to build project.");if(o("git")){if(G=await c("git init --initial-branch=main",{cwd:q}),G.code!==0)throw Error("Failed to initialize git.")}if(o("code")&&$.vscode){if(G=await c(`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=E1;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=S("./template/fnode/project"),z=process.cwd(),q=await V($);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.kvedj83h.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.kvedj83h.js")).default;case"python":return(await import("./index.hv4s25f0.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"})},handler:async($)=>{try{let W=await V($),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("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"})},handler:async($)=>{try{$.dev=!0;let W=await V($),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("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 V({...$,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("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 V({...$,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)}}},H1=j1;import J1 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 V($),{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:U}=await d1({type:"input",name:"inputName",message:"Input name:",initial:"dev"});$.name=U}let Q=J1.resolve(q,".fnet");if(!P.existsSync(Q))P.mkdirSync(Q);let Y=J1.resolve(Q,`${$.name}.fnet`),O=P.existsSync(Y),M=(await import("@fnet/object-from-schema")).default,J=await M({schema:Z,format:"yaml",ref:O?Y:void 0});P.writeFileSync(Y,J)}catch(W){console.error(W.message),process.exit(1)}}},M1=m1;import L from"node:path";import H from"node:fs";import d from"node:os";import{spawn as m}from"node:child_process";import K 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 U=W[0],T=typeof U==="string"?U:U[G];return console.log(j.blue(`Only one option available: ${typeof U==="string"?U:U[q]}`)),T}let Y=W.map((U)=>{if(typeof U==="string")return{name:U,value:U,message:U};else return{name:U[G],value:U[G],message:U[q]||U[G]}});if(Q)Y.push({name:"cancel",value:null,message:j.yellow("Cancel")});let O=null;if(Z){let U=Y.findIndex((T)=>T.name===Z);if(U!==-1)O=U}let M="selectedItem",{[M]:J}=await L1({type:"select",name:M,message:z,choices:Y,initial:O});if(J==="cancel")return null;return J}async function l1($){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((U)=>{if(typeof U==="string")return{name:U,value:U,message:U};else return{name:U[G],value:U[G],message:U[q]||U[G]}}),O=[];if(Z&&Z.length>0)O=Y.map((U,T)=>Z.includes(U.name)?T:-1).filter((U)=>U!==-1);let M="selectedItems",J=await L1({type:"multiselect",name:M,message:z,choices:Y,initial:O,hint:"(Use space to select, enter to confirm)",validate:(U)=>{if(U.length===0&&!Q)return"Please select at least one item";return!0}});if(Q&&J[M].length===0)return null;return J[M]}var s={promptForSelection:g1,promptForMultipleSelection:l1};var X=L.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 h1(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 h1($){try{if(!H.existsSync(X))H.mkdirSync(X,{recursive:!0});let W=new Date().toISOString().slice(0,10).replace(/-/g,""),z=L.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=L.join(z,q),H.existsSync(G)){let J=1;while(H.existsSync(L.join(z,`${q}-${J}`)))J++;q=`${q}-${J}`,G=L.join(z,q)}if(!$.yes){if(!(await A([{type:"confirm",name:"proceed",message:`Create express project "${q}" in ${G}?`,default:!0}])).proceed){console.log(K.yellow("Project creation cancelled."));return}}console.log(K.blue(`Creating express project "${q}" in ${G}...`));let Q=L.dirname(G),O=["create","--name",L.basename(G)];if(O.push("--runtime",Z),$.yes)O.push("--yes");if(!H.existsSync(Q))H.mkdirSync(Q,{recursive:!0});let M=m("fnode",O,{stdio:"inherit",shell:!0,cwd:Q});return new Promise((J,U)=>{M.on("close",(T)=>{if(T===0)if(console.log(K.green(`
|
|
3
|
-
Express project "${q}" created successfully!`)),console.log(
|
|
4
|
-
Project location: ${G}`)),!$.yes)
|
|
5
|
-
Failed to create express project "${q}".`)),
|
|
6
|
-
Express Projects:`));let q=(await import("./index.bhapgrs7.js")).default,G=["NAME","TYPE","DATE","PATH"],Z=q.createTable(G,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});for(let Q of z){let Y=Q.path;if(Y.startsWith(
|
|
7
|
-
Total: ${z.length} projects`))}catch(W){console.error(
|
|
8
|
-
Project moved successfully to ${G}`)),(await A({type:"confirm",name:"deleteOriginal",message:"Delete the original express project?",initial:!1})).deleteOriginal)H.rmSync(q,{recursive:!0,force:!0}),console.log(
|
|
9
|
-
Opening a new shell in the project directory...`));let z=process.env.SHELL||"/bin/bash",q=
|
|
10
|
-
Returned from project directory.`)),G()})})}catch(W){console.error(
|
|
2
|
+
import{e as S}from"./index.9qgtmxq3.js";import{f as o}from"./index.05n3mvs9.js";import{g as k,i as E}from"./index.cvxrf34y.js";import z$ from"yargs";import I1 from"chalk";import{promisify as F1}from"node:util";import _1 from"tree-kill";var a=F1(_1),N=!1;async function i($,W){if(N)return;if(N=!0,!$.killed&&$.pid)try{if(await a($.pid,"SIGTERM").catch(()=>{}),await new Promise((q)=>setTimeout(q,500)),!$.killed)await a($.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 b($){["SIGINT","SIGTERM","SIGQUIT"].forEach((W)=>{process.once(W,async()=>{await i($,W)})}),process.on("uncaughtException",async(W)=>{await i($)}),process.on("unhandledRejection",async(W)=>{await i($)}),$.on("close",(W)=>{if(!N)process.exit(W)})}function t(){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 v from"node:fs";import y from"chalk";import A1 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});b(T)}catch(Q){console.error(Q.message),process.exit(1)}})}function D($,{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}});b(J)}catch(Q){console.error(Q.message),process.exit(1)}})}function e($,{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}});b(J)}catch(G){console.error(G.message),process.exit(1)}})}function $1($,{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 A1({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:v.existsSync(Q)?Q:process.cwd(),stdio:"inherit",shell:!0,detached:!0,env:{...process.env,...M}});b(T)}catch(Z){console.error(Z.message),process.exit(1)}})}function W1($,{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 q1($,{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(y.blue("Compiling project..."));let Q=x.join(Z,".bin");if(!v.existsSync(Q))v.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(y.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((u,F)=>{T.on("close",(_)=>{if(_===0)u();else F(Error(`Compilation failed with code ${_}`))}),T.on("error",(_)=>{F(_)})}),process.platform!=="win32")v.chmodSync(J,493);console.log(y.green(`Binary compiled successfully: ${J}`)),console.log(y.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 f=K("fbin",I,{stdio:"inherit",shell:!0});await new Promise((u,F)=>{f.on("close",(_)=>{if(_===0)u();else F(Error(`Installation failed with code ${_}`))}),f.on("error",(_)=>{F(_)})})}catch(G){console.error(y.red(`Failed to install binary: ${G.message}`)),process.exit(1)}})}import w from"node:path";import B from"node:fs";import z1 from"@fnet/yaml";import R1 from"yaml";async function O($){if($.id)return{id:$.id,buildId:$.buildId,mode:$.mode,protocol:$.protocol||"ac:",templateDir:S("./template/fnode/node"),projectDir:w.resolve(process.cwd(),`./.output/${$.id}`),tags:$.ftag,dev:$.dev};else try{let W=await N1({tags:$.ftag}),z=W.runtime.type==="bun"?"node":W.runtime.type;return{buildId:$.buildId,mode:$.mode,protocol:$.protocol||"src:",templateDir:S(`./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}}catch(W){return console.warn(`Warning: Could not load project: ${W.message}`),{projectDir:process.cwd(),tags:$.ftag}}}async function N1({tags:$}){let W=x1(process.cwd());if(!B.existsSync(W))throw Error("fnode.yaml file not found in current directory.");let{raw:z,parsed:q}=await z1({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 z1({file:Y,tags:$}),K=R1.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 x1($){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 k1 from"node:path";import G1 from"node:fs";import E1 from"node:os";import S1 from"@flownet/lib-render-templates-dir";import c from"@fnet/shelljs";var b1={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=S("./template/fnode/project"),q=k1.resolve(W,$.name);if(!G1.existsSync(q))G1.mkdirSync(q);await S1({dir:z,outDir:q,context:{name:$.name,runtime:$.runtime,platform:E1.platform()},copyUnmatchedAlso:!0});let G=await c("fnode build",{cwd:q});if(G.code!==0)throw Error("Failed to build project.");if(o("git")){if(G=await c("git init --initial-branch=main",{cwd:q}),G.code!==0)throw Error("Failed to initialize git.")}if(o("code")&&$.vscode){if(G=await c(`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)}}},Q1=b1;import y1 from"node:os";import D1 from"@flownet/lib-render-templates-dir";import f1 from"@fnet/shelljs";var u1={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=S("./template/fnode/project"),z=process.cwd(),q=await O($);if($.update){if(await D1({dir:W,outDir:z,context:{name:q.project.projectFileParsed.name,runtime:q.project.runtime.type,platform:y1.platform()},copyUnmatchedAlso:!0}),(await f1("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)}}},Z1=u1;class Y1{static async createBuilder($){if(!$.project)return console.warn("No project provided, defaulting to node runtime"),new(await import("./index.kvedj83h.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.kvedj83h.js")).default;case"python":return(await import("./index.hv4s25f0.js")).default;default:throw Error(`Unsupported runtime type: ${$}`)}}}var R=Y1;var v1={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"})},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)}}},K1=v1;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"})},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)}}},U1=P1;var j1={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)}}},J1=j1;var d1={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)}}},M1=d1;import H1 from"node:path";import j from"node:fs";import m1 from"@fnet/prompt";var g1={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 m1({type:"input",name:"inputName",message:"Input name:",initial:"dev"});$.name=K}let Q=H1.resolve(q,".fnet");if(!j.existsSync(Q))j.mkdirSync(Q);let Y=H1.resolve(Q,`${$.name}.fnet`),L=j.existsSync(Y),M=(await import("@fnet/object-from-schema")).default,J=await M({schema:Z,format:"yaml",ref:L?Y:void 0});j.writeFileSync(Y,J)}catch(W){console.error(W.message),process.exit(1)}}},L1=g1;import V from"node:path";import H from"node:fs";import m from"node:os";import{spawn as g}from"node:child_process";import U from"chalk";import A from"@fnet/prompt";import d from"chalk";import O1 from"@fnet/prompt";async function h1($){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(d.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(d.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:d.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 O1({type:"select",name:M,message:z,choices:Y,initial:L});if(J==="cancel")return null;return J}async function l1($){let{items:W,message:z,nameField:q="name",valueField:G="name",initialValues:Z=[],allowAbort:Q=!0}=$;if(!W||W.length===0)return console.log(d.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 O1({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 s={promptForSelection:h1,promptForMultipleSelection:l1};var X=V.join(m.homedir(),".fnet","express");async function T1($){$.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 p1(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 n1(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 i1(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 c1(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 s1(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 r1(W)}).demandCommand(1,"You need to specify a command").help()}async function p1($){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)),f=`fnode-${T.length>0?Math.max(...T)+1:1}`;q=(await A([{type:"input",name:"projectName",message:"Enter project name:",default:f}])).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=g("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
|
+
Express project "${q}" created successfully!`)),console.log(U.blue(`
|
|
4
|
+
Project location: ${G}`)),!$.yes)o1(G);else J();else console.error(U.red(`
|
|
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 n1($){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(`
|
|
6
|
+
Express Projects:`));let q=(await import("./index.bhapgrs7.js")).default,G=["NAME","TYPE","DATE","PATH"],Z=q.createTable(G,{chars:{mid:"","mid-mid":"","left-mid":"","right-mid":""}});for(let Q of z){let Y=Q.path;if(Y.startsWith(m.homedir()))Y="~"+Y.substring(m.homedir().length);Z.push([U.white(Q.name),Q.type==="fnet"?U.cyan(Q.type):Q.type==="fnode"?U.green(Q.type):Q.type,Q.date,Y])}console.log(Z.toString()),console.log(U.green("Projects: ")+U.yellow(z.filter((Q)=>Q.type==="fnode").length+" fnode, ")+U.cyan(z.filter((Q)=>Q.type==="fnet").length+" fnet")),console.log(U.blue(`
|
|
7
|
+
Total: ${z.length} projects`))}catch(W){console.error(U.red(`Error listing express projects: ${W.message}`)),process.exit(1)}}async function i1($){try{if(!H.existsSync(X)){console.log(U.yellow("No express projects found."));return}let W;if($.latest){if(W=await h(),!W){console.log(U.yellow("No express projects found."));return}}else if($.projectName){if(W=await l($.projectName),!W){console.log(U.yellow(`Project "${$.projectName}" not found.`));return}}else{let z=await p();if(!z){console.log(U.yellow("No project selected."));return}W=V.join(X,z)}await r(W)}catch(W){console.error(U.red(`Error opening express project: ${W.message}`)),process.exit(1)}}async function c1($){try{let W=process.cwd(),z=W.includes(X),q;if(z)q=W,console.log(U.blue(`Using current express project: ${V.basename(q)}`));else if($.latest){if(q=await h(),!q){console.log(U.yellow("No express projects found."));return}}else if($.projectName){if(q=await l($.projectName),!q){console.log(U.yellow(`Project "${$.projectName}" not found.`));return}}else{let Q=await p();if(!Q){console.log(U.yellow("No project selected."));return}q=V.join(X,Q)}let G=$.destination;if(!G)G=(await A({type:"input",name:"destination",message:"Enter destination directory:",initial:V.join(process.cwd(),V.basename(q))})).destination;if(G.startsWith("~"))G=V.join(m.homedir(),G.slice(1));if(G=V.resolve(G),G.startsWith(q+V.sep)||G===q){console.log(U.red("Destination cannot be inside the source directory."));return}if(H.existsSync(G)){if(!H.statSync(G).isDirectory()){console.log(U.red(`Destination "${G}" is not a directory.`));return}if(H.readdirSync(G).length>0){if(!(await A({type:"confirm",name:"overwrite",message:`Destination "${G}" is not empty. Continue anyway?`,initial:!1})).overwrite){console.log(U.yellow("Project move cancelled."));return}}}else H.mkdirSync(G,{recursive:!0});if(console.log(U.blue(`Moving project from ${q} to ${G}...`)),X1(q,G),console.log(U.green(`
|
|
8
|
+
Project moved successfully to ${G}`)),(await A({type:"confirm",name:"deleteOriginal",message:"Delete the original express project?",initial:!1})).deleteOriginal)H.rmSync(q,{recursive:!0,force:!0}),console.log(U.green("Original project deleted."));await r(G)}catch(W){console.error(U.red(`Error moving express project: ${W.message}`)),process.exit(1)}}async function h(){let $=H.readdirSync(X).filter((Q)=>/^\d{8}$/.test(Q)).sort((Q,Y)=>Y.localeCompare(Q));if($.length===0)return null;let W=$[0],z=V.join(X,W),q=H.readdirSync(z);if(q.length===0)return null;let G=null,Z=0;for(let Q of q){let Y=V.join(z,Q),L=H.statSync(Y);if(L.birthtimeMs>Z)Z=L.birthtimeMs,G=Y}return G}async function l($){let W=H.readdirSync(X).filter((z)=>/^\d{8}$/.test(z)).sort((z,q)=>q.localeCompare(z));for(let z of W){let q=V.join(X,z),G=H.readdirSync(q);if(G.includes($))return V.join(q,$);let Z=G.filter((Q)=>Q.includes($));if(Z.length>0)if(Z.length===1)return V.join(q,Z[0]);else{let Q=Z.map((L)=>({name:V.join(q,L),value:V.join(q,L),message:`${L} (${z})`})),Y=await s.promptForSelection({items:Q,message:`Multiple projects match "${$}". Please select one:`,nameField:"message",valueField:"value",allowAbort:!0});if(Y===null)return console.log(U.yellow("Operation cancelled.")),null;return Y}}return null}async function p(){let $=[],W=H.readdirSync(X).filter((q)=>/^\d{8}$/.test(q)).sort((q,G)=>G.localeCompare(q));for(let q of W){let G=V.join(X,q),Z=H.readdirSync(G);for(let Q of Z){let Y=V.join(G,Q),L=H.statSync(Y),M=`${q}/${Q}`;$.push({name:M,value:M,message:`${Q} (${q})`,created:L.birthtime})}}if($.sort((q,G)=>G.created-q.created),$.length===0)return null;let z=await s.promptForSelection({items:$,message:"Select a project:",nameField:"message",valueField:"value",allowAbort:!0});if(z===null)return console.log(U.yellow("Operation cancelled.")),null;return z}async function o1($){try{if((await A({type:"confirm",name:"openIDE",message:"Would you like to open the project in an IDE?",initial:!0})).openIDE)await r($)}catch(W){console.error(U.red(`Error opening IDE: ${W.message}`))}}async function r($){let W=await V1("code --version"),z=await V1("code-insiders --version"),q=null;if(W&&z)q=(await A({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(W)q="code";else if(z)q="code-insiders";else{console.log(U.yellow("No supported IDE found. Please open the project manually.")),console.log(U.blue(`Project path: ${$}`));return}console.log(U.blue(`Opening project in ${q}...`)),console.log(U.blue(`Project path: ${$}`));let G=g(q,[$],{stdio:"inherit",shell:!0});return new Promise((Z,Q)=>{G.on("close",(Y)=>{if(Y===0)console.log(U.green(`Project opened in ${q}.`)),Z();else console.error(U.red(`Failed to open project in ${q}.`)),Q(Error(`Process exited with code ${Y}`))})})}async function V1($){return new Promise((W)=>{g($,{shell:!0,stdio:"ignore"}).on("close",(q)=>{W(q===0)})})}function X1($,W){if(!H.existsSync(W))H.mkdirSync(W,{recursive:!0});let z=H.readdirSync($,{withFileTypes:!0});for(let q of z){let G=V.join($,q.name),Z=V.join(W,q.name);if(q.isDirectory()){if(q.name===".git"||q.name===".workspace")continue;X1(G,Z)}else H.copyFileSync(G,Z)}}async function s1($){try{if(!H.existsSync(X)){console.log(U.yellow("No express projects found."));return}let W;if($.latest){if(W=await h(),!W){console.log(U.yellow("No express projects found."));return}}else if($.projectName){if(W=await l($.projectName),!W){console.log(U.yellow(`Project "${$.projectName}" not found.`));return}}else{let q=await p();if(!q){console.log(U.yellow("No project selected."));return}W=V.join(X,q)}let z=V.basename(W);if(!$.yes){if(!(await A({type:"confirm",name:"confirm",message:`Are you sure you want to remove project "${z}"?`,initial:!1})).confirm){console.log(U.yellow("Project removal cancelled."));return}}console.log(U.blue(`Removing project "${z}"...`)),H.rmSync(W,{recursive:!0,force:!0}),console.log(U.green(`Project "${z}" removed successfully.`))}catch(W){console.error(U.red(`Error removing express project: ${W.message}`)),process.exit(1)}}async function r1($){try{if(!H.existsSync(X)){console.log(U.yellow("No express projects found."));return}let W;if($.latest){if(W=await h(),!W){console.log(U.yellow("No express projects found."));return}}else if($.projectName){if(W=await l($.projectName),!W){console.log(U.yellow(`Project "${$.projectName}" not found.`));return}}else{let G=await p();if(!G){console.log(U.yellow("No project selected."));return}W=V.join(X,G)}console.log(U.blue(`Entering project directory: ${W}`)),console.log(U.yellow(`
|
|
9
|
+
Opening a new shell in the project directory...`));let z=process.env.SHELL||"/bin/bash",q=g(z,[],{stdio:"inherit",cwd:W,shell:!0});return new Promise((G)=>{q.on("close",()=>{console.log(U.green(`
|
|
10
|
+
Returned from project directory.`)),G()})})}catch(W){console.error(U.red(`Error entering express project directory: ${W.message}`)),process.exit(1)}}import B1 from"node:path";import{fileURLToPath as W$}from"node:url";import a1 from"node:fs";import n from"node:path";import{fileURLToPath as t1}from"node:url";var e1=n.dirname(t1(import.meta.url));function $$({baseDir:$}){$=$||e1;let W=$;while(W!==n.parse(W).root){let z=n.join(W,"node_modules");if(a1.existsSync(z))return z;W=n.dirname(W)}return null}var C1=$$;var q$=B1.dirname(W$(import.meta.url));function w1(){let $=C1({baseDir:q$}),W=process.platform==="win32"?";":":";if($)process.env.PATH=`${B1.join($,"/.bin")}${W}${process.env.PATH}`}t();w1();async function G$(){try{let $=z$(process.argv.slice(2)).usage("Usage: $0 <command> [options]").command(Q1).command(Z1).command(K1).command(U1).command(J1).command(M1).command(L1).command("express","Create and manage express projects",T1);$=C($,{bin:"npm",createContext:O}),$=C($,{bin:"node",createContext:O}),$=C($,{bin:"bun",createContext:O}),$=C($,{name:"serve",bin:"bun",preArgs:["run","serve","--"],createContext:O}),$=C($,{name:"watch",bin:"bun",preArgs:["run","watch","--"],createContext:O}),$=C($,{name:"app",bin:"bun",preArgs:["run","app","--"],createContext:O}),$=C($,{name:"cli",bin:"bun",preArgs:["run","cli","--"],createContext:O}),$=C($,{name:"cli:dev",bin:"bun",preArgs:["run","cli:dev","--"],createContext:O}),$=C($,{name:"cli:compile",bin:"bun",preArgs:["run","cli:compile","--"],createContext:O}),$=C($,{name:"cli:compile:dev",bin:"bun",preArgs:["run","cli:compile:dev","--"],createContext:O}),$=C($,{name:"cli:install",bin:"bun",preArgs:["run","cli:install","--"],createContext:O}),$=C($,{name:"compile",bin:"bun",preArgs:["run","compile","--"],createContext:O}),$=q1($,{name:"install",createContext:O}),$=C($,{bin:"npx",createContext:O}),$=C($,{bin:"cdk",createContext:O}),$=C($,{bin:"aws",createContext:O}),$=$1($,{name:"with",createContext:O}),$=W1($,{name:"run",projectType:"fnode"}),$=D($,{name:"python",createContext:O}),$=D($,{name:"python3",createContext:O}),$=D($,{name:"pip",createContext:O}),$=D($,{name:"pip3",createContext:O}),$=e($,{name:"bin",createContext:O}),$.demandCommand(1,"You need at least one command before moving on").help().version().argv}catch($){console.error(I1.red(`Fatal error: ${$.message}`)),process.exit(1)}}G$().catch(($)=>{console.error(I1.red(`Fatal error: ${$.message}`)),process.exit(1)});
|