@minima-global/minima-cli
Version:
A Cli for managing your minidapp while in development.
4 lines • 4.22 kB
JavaScript
import{a as v,b as p,c as D,d as y,e as P,f as c}from"./chunk-72HLBJSM.js";import b from"chalk";import{Command as S}from"commander";import{readFileSync as m}from"fs";import d from"ora";import f from"chalk";var o={info:e=>{console.log(f.blue(e))},error:e=>{console.error(f.red(e))},success:e=>{console.log(f.green(e))},break:()=>{console.log("")}};import{existsSync as M,readFileSync as I}from"fs";import{resolve as E}from"path";function l(){try{let e={debug:!1,host:"127.0.0.1",mdsPort:9003,sessionId:""},r=E(process.cwd(),".env");if(!M(r))return o.error("No .env file found, using default values"),e;let i=I(r,"utf-8").split(`
`),n={};for(let a of i){let u=a.trim();if(!u||u.startsWith("#"))continue;let[g,...h]=u.split("=");g&&h.length>0&&(n[g]=h.join("="))}return{debug:n.VITE_DEBUG==="true",host:n.VITE_DEBUG_HOST||e.host,mdsPort:parseInt(n.VITE_DEBUG_MDS_PORT||String(e.mdsPort),10),sessionId:n.VITE_DEBUG_SESSION_ID||e.sessionId}}catch(e){return o.error(`Error reading environment variables: ${e}`),{debug:!1,host:"127.0.0.1",mdsPort:9003,sessionId:""}}}var s=new S,k=JSON.parse(m("./package.json","utf-8")).version;s.name("minima").description("CLI to manage Minima MiniDapps").version(k);s.command("zip").description("Build and zip the MiniDapp").option("-l, --logs","Debug logs",!1).action(async e=>{let r=d("Building MiniDapp...").start();try{let t=JSON.parse(m("./package.json","utf-8"));await p(e.logs),r.text="Zipping MiniDapp...";let i=`${t.name}-${t.version}.mds.zip`,n=v()?"build/":"./";e.logs&&(console.log("filePath",n),console.log("zipFileName",i)),await c(i,n,e.logs),setTimeout(()=>{r.succeed(b.green(`MiniDapp built and zipped successfully! ${i}`))},5e3)}catch(t){e.logs&&console.log("error",t),r.fail(b.red("Failed to build and zip MiniDapp")),process.exit(1)}});s.command("install").description("Install the MiniDapp").option("-p, --port <port>","rpcport number").action(async e=>{let r;try{let t=JSON.parse(m("./package.json","utf-8"));r=d("Installing MiniDapp...").start(),await p();let i=l();e.port||(i.mdsPort?e.port=i.mdsPort+2:e.port="9005");let n=`${t.name}-${t.version}.mds.zip`,a=t.template==="react-ts"?"build/":"./";await c(n,a),await D({port:parseInt(e.port),pathToFile:process.cwd(),miniDappName:t.name,miniDappVersion:t.version}),setTimeout(()=>{r?.succeed("MiniDapp installed successfully!")},2e3)}catch(t){r?.fail("Failed to install MiniDapp"),t instanceof Error?(o.info("Please check that you have RPC enabled on your Minima node and that the port is correct"),o.info("If you are using a custom port other than 9005, please use the -p option to specify the port")):o.error(String(t)),process.exit(1)}});s.command("uninstall").option("-p, --port <port>","port number").description("Uninstall the MiniDapp").action(async e=>{let r;try{let t=l();e.port||(t.mdsPort?e.port=t.mdsPort+2:e.port="9005"),r=d("Uninstalling MiniDapp...").start(),await y({port:parseInt(e.port)}),setTimeout(()=>{r?.succeed("MiniDapp uninstalled successfully!")},2e3)}catch(t){r?.fail("Failed to uninstall MiniDapp"),t instanceof Error?(o.error(t.message),o.info(`Port: ${e.port}`),o.info("Please check that you have RPC enabled on your Minima node and that the port is correct"),o.info("If you are using a custom port other than 9005, please use the -p option to specify the port")):o.error(String(t)),process.exit(1)}});s.command("update").description("Update the MiniDapp").option("-p, --port <port>","rpcport number").action(async e=>{let r;try{let t=JSON.parse(m("./package.json","utf-8"));r=d("Updating MiniDapp...").start(),await p();let i=`${t.name}-${t.version}.mds.zip`,n=t.template==="react-ts"?"build/":"./";await c(i,n);let a=l();e.port||(a.mdsPort?e.port=a.mdsPort+2:e.port="9005"),await P({port:parseInt(e.port)}),setTimeout(()=>{r?.succeed("MiniDapp updated successfully!")},2e3)}catch(t){r?.fail("Failed to update MiniDapp"),t instanceof Error?(o.error(t.message),o.info(`Port: ${e.port}`),o.info("Please check that you have RPC enabled on your Minima node and that the port is correct"),o.info("If you are using a custom port other than 9005, please use the -p option to specify the port")):o.error(String(t)),process.exit(1)}});s.parse();
//# sourceMappingURL=cli.js.map