@dataramen/cli 0.0.60 → 0.0.61-beta.2
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/bin/app.js +5 -0
- package/dist/code/cli.js +3 -3
- package/dist/package.json +1 -1
- package/package.json +3 -4
- package/bin/run.js +0 -5
package/bin/app.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var ee=Object.create;var P=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var se=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of re(t))!oe.call(e,r)&&r!==o&&P(e,r,{get:()=>t[r],enumerable:!(a=te(t,r))||a.enumerable});return e};var c=(e,t,o)=>(o=e!=null?ee(ne(e)):{},se(t||!e||!e.__esModule?P(o,"default",{value:e,enumerable:!0}):o,e));var Z=require("commander");var b=c(require("fs-extra")),R=require("node:path");var _=require("node:os"),C=require("node:path"),ie=(0,_.homedir)(),m="@dataramen/server",i=(0,C.join)(ie,".dataramen",".runtime","server");function V(e){let t;function o(){try{return t||(t=b.readJsonSync(e)),t}catch{return}}return o}var N=V((0,R.join)(__dirname,"..","package.json")),A=V((0,R.join)(i,"package.json"));var p=c(require("fs-extra")),f=require("node:path"),k=require("node:child_process"),M=require("node:util"),g=c(require("yocto-spinner")),d=(0,M.promisify)(k.exec);function O(){try{let e=A();if(!e)return!0;let t=p.readJsonSync((0,f.join)(__dirname,"..","dist","package.json"));return e.version!==t.version}catch{return!0}}async function W(){let e=(0,g.default)({text:"Checking if PM2 is installed"}).start();try{return await d("pm2 -v"),e.success("PM2 already installed"),!0}catch{return e.warning("PM2 not installed"),!1}}async function j(){let e=(0,g.default)({text:"Installing PM2"}).start();try{await d("npm i -g pm2"),e.success("Installed PM2")}catch{e.error("Failed to install PM2"),process.exit(1)}}async function E(){let e=(0,g.default)({text:"Stop running instances of "+m}).start();try{await d(`pm2 stop "${m}"`),e.warning("Stopped "+m)}catch{e.success("No running instances of "+m+" found")}}async function I(){let e=(0,g.default)({text:"Create local server"}).start();p.removeSync((0,f.join)(i,"code")),p.copySync((0,f.join)(__dirname,"..","dist","code"),(0,f.join)(i,"code")),p.copySync((0,f.join)(__dirname,"..","dist","package.json"),(0,f.join)(i,"package.json")),e.text="Install local server dependencies",await d("npm i",{cwd:i}),e.success("Local server installed")}var v=c(require("node:crypto"));var S=require("fs-extra"),T=require("node:path");function ae(e){try{return(0,S.readFileSync)((0,T.join)(i,e),"utf-8")}catch{return}}function me(e){let t={},o=ae(e);if(o){let a=o.split(`
|
|
3
|
+
`);for(let r of a){let s=r.trim();if(!s||s.startsWith("#"))continue;let u=s.indexOf("=");if(u===-1)continue;let w=s.slice(0,u).trim(),l=s.slice(u+1).trim();(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'"))&&(l=l.slice(1,-1)),t[w]=l}}return t}function ce(){let e={customValues:{},fileName:".env"};function t(){e.customValues=me(e.fileName)}function o(){let s=Object.entries(e.customValues).map(([u,w])=>`${u}=${w}`).join(`
|
|
4
|
+
`)+`
|
|
5
|
+
`;(0,S.writeFileSync)((0,T.join)(i,e.fileName),s,{encoding:"utf8"})}function a(r){if(e.customValues[r])return e.customValues[r]}return t(),{getNumber:r=>le(a(r)),getString:r=>fe(a(r)),getBoolean:r=>pe(a(r)),flush:o,set:(r,s)=>{e.customValues[r]=s},unset:r=>{delete e.customValues[r]}}}function le(e){if(!e)return;let t=Number(e);if(!isNaN(t)&&e.trim()!=="")return t;throw new Error("Wrong env value type")}function fe(e){if(e){if(typeof e=="string")return e;throw new Error("Wrong env value type")}}function pe(e){if(!e)return;let t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;throw new Error("Wrong env value type")}var n=ce();function J(){let e=!1;if(!n.getString("SYMM_ENCRYPTION_KEY")){let t=v.randomBytes(32).toString("hex");n.set("SYMM_ENCRYPTION_KEY",t),console.log("Generated random SYMM_ENCRYPTION_KEY"),e=!0}if(!n.getString("JWT_SECRET")){let t=v.randomBytes(32).toString("hex");n.set("JWT_SECRET",t),console.log("Generated random JWT_SECRET"),e=!0}if(!n.getString("JWT_REFRESH_SECRET")){let t=v.randomBytes(32).toString("hex");n.set("JWT_REFRESH_SECRET",t),console.log("Generated random JWT_REFRESH_SECRET"),e=!0}e&&n.flush()}var $=require("node:net");async function H(e){return new Promise(t=>{let o=(0,$.createServer)().once("error",()=>{t(!1)}).once("listening",()=>{o.close()}).once("close",()=>t(!0)).listen(e,"127.0.0.1")})}var x=c(require("yocto-spinner"));var L=c(require("fs-extra")),Y=require("node:path");var ue=async e=>{try{return(await fetch(e,{method:"GET",signal:AbortSignal.timeout(5e3)})).status===200}catch{return!1}},F=async(e,t,o)=>{let a=Date.now();for(;Date.now()-a<t;){if(await ue(e))return!0;await new Promise(s=>setTimeout(s,o))}return!1};var K=c(require("open")),Ee={command:"start",description:"Start local server, restarts if already running",handler:async()=>{await W()||await j(),await E();try{O()&&await I(),J();let t=n.getNumber("PORT")||4466;if(!t)throw new Error("PORT env variable not found");if(!await H(t))throw new Error(`Port ${t} is occupied by another process`);let a=(0,x.default)({text:"Starting new instance of "+m}).start(),r=L.readJsonSync((0,Y.join)(i,"package.json"));await d(`pm2 start "${r.main}" --name "${m}" --no-autorestart -- "${i}/.env"`,{cwd:i}),a.success("Local server will be available in a couple of seconds");let s=(0,x.default)({text:"Waiting for the server to become available"}).start();await F(`http://localhost:${t}/api/status`,3e4,1e3)?(await(0,K.default)(`http://localhost:${t}`),s.success(`App is running at http://localhost:${t}`)):s.error("Server failed to become available in time")}catch(t){console.error("Failed to start local server",t)}}},h=Ee;var D=require("node:child_process");var Se={command:"logs",description:"Listen for logs",handler:async()=>{(0,D.execSync)(`pm2 logs ${m}`,{stdio:"inherit"})}},B=Se;var ve={command:"stop",description:"Stop the server",handler:E},G=ve;var U=c(require("open")),he={command:"open",description:"Open webapp",handler:async()=>{let e=n.getNumber("PORT");await(0,U.default)(`http://localhost:${e}`)}},Q=he;var ye={command:"set <prop> <value>",description:"Set env value",handler:async(e,t)=>{n.set(e,t),n.flush(),console.log(`Environment property set: ${e}`)}},q=ye;var we={command:"unset <prop>",description:"Remove env value",handler:async e=>{n.unset(e),n.flush(),console.log(`Environment property unset: ${e}`)}},z=we;var X=[h,B,G,Q,q,z];var y=new Z.Command;y.name("dataramen").description("A cozy web GUI for MySQL and PostgreSQL - built for developers who like to move fast and stay focused.").version(N().version,"-v, --version","Show version");y.command("default",{hidden:!0,isDefault:!0}).action(h.handler);X.forEach(e=>{y.command(e.command).description(e.description).action(e.handler)});y.parse();
|
package/dist/code/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var G=Object.create;var
|
|
3
|
-
`);for(let n of a){let s=n.trim();if(!s||s.startsWith("#"))continue;let d=s.indexOf("=");if(d===-1)continue;let
|
|
2
|
+
var G=Object.create;var V=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var X=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Q(t))!z.call(e,n)&&n!==r&&V(e,n,{get:()=>t[n],enumerable:!(a=U(t,n))||a.enumerable});return e};var u=(e,t,r)=>(r=e!=null?G(q(e)):{},X(t||!e||!e.__esModule?V(r,"default",{value:e,enumerable:!0}):r,e));var B=require("commander");var C=require("node:os"),N=require("node:path"),Z=(0,C.homedir)(),c="@dataramen/server",i=(0,N.join)(Z,".dataramen",".runtime","server");var Y=require("node:path"),D=u(require("fs-extra")),K=require("node:child_process");var k=u(require("fs-extra")),P=require("node:path");function A(e){let t;function r(){try{return t||(t=k.readJsonSync(e)),t}catch{return}}return r}var v=A((0,P.join)(__dirname,"..","package.json")),S=A((0,P.join)(i,"package.json"));var p=u(require("fs-extra")),f=require("node:path"),M=require("node:child_process"),$=require("node:util"),E=u(require("yocto-spinner")),g=(0,$.promisify)(M.exec);function I(){try{let e=S();if(!e)return!0;let t=p.readJsonSync((0,f.join)(__dirname,"..","dist","package.json"));return e.version!==t.version}catch{return!0}}async function W(){let e=(0,E.default)({text:"Checking if PM2 is installed"}).start();try{return await g("pm2 -v"),e.success("PM2 already installed"),!0}catch{return e.warning("PM2 not installed"),!1}}async function j(){let e=(0,E.default)({text:"Installing PM2"}).start();try{await g("npm i -g pm2"),e.success("Installed PM2")}catch{e.error("Failed to install PM2"),process.exit(1)}}async function b(){let e=(0,E.default)({text:"Stop running instances of "+c}).start();try{await g(`pm2 stop "${c}"`),e.warning("Stopped "+c)}catch{e.success("No running instances of "+c+" found")}}async function J(){let e=(0,E.default)({text:"Create local server"}).start();p.removeSync((0,f.join)(i,"code")),p.copySync((0,f.join)(__dirname,"..","dist","code"),(0,f.join)(i,"code")),p.copySync((0,f.join)(__dirname,"..","dist","package.json"),(0,f.join)(i,"package.json")),e.text="Install local server dependencies",await g("npm i",{cwd:i}),e.success("Local server installed")}var x=u(require("yocto-spinner")),T=u(require("open"));var H=require("node:net");async function O(e){return new Promise(t=>{let r=(0,H.createServer)().once("error",()=>{t(!1)}).once("listening",()=>{r.close()}).once("close",()=>t(!0)).listen(e,"127.0.0.1")})}var y=u(require("node:crypto"));var h=require("fs-extra"),_=require("node:path");function ee(e){try{return(0,h.readFileSync)((0,_.join)(i,e),"utf-8")}catch{return}}function te(e){let t={},r=ee(e);if(r){let a=r.split(`
|
|
3
|
+
`);for(let n of a){let s=n.trim();if(!s||s.startsWith("#"))continue;let d=s.indexOf("=");if(d===-1)continue;let R=s.slice(0,d).trim(),m=s.slice(d+1).trim();(m.startsWith('"')&&m.endsWith('"')||m.startsWith("'")&&m.endsWith("'"))&&(m=m.slice(1,-1)),t[R]=m}}return t}function ne(){let e={customValues:{},fileName:".env"};function t(){e.customValues=te(e.fileName)}function r(){let s=Object.entries(e.customValues).map(([d,R])=>`${d}=${R}`).join(`
|
|
4
4
|
`)+`
|
|
5
|
-
`;(0,
|
|
5
|
+
`;(0,h.writeFileSync)((0,_.join)(i,e.fileName),s,{encoding:"utf8"})}function a(n){if(e.customValues[n])return e.customValues[n]}return t(),{getNumber:n=>re(a(n)),getString:n=>oe(a(n)),getBoolean:n=>se(a(n)),flush:r,set:(n,s)=>{e.customValues[n]=s},unset:n=>{delete e.customValues[n]}}}function re(e){if(!e)return;let t=Number(e);if(!isNaN(t)&&e.trim()!=="")return t;throw new Error("Wrong env value type")}function oe(e){if(e){if(typeof e=="string")return e;throw new Error("Wrong env value type")}}function se(e){if(!e)return;let t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;throw new Error("Wrong env value type")}var o=ne();function F(){let e=!1;if(!o.getString("SYMM_ENCRYPTION_KEY")){let t=y.randomBytes(32).toString("hex");o.set("SYMM_ENCRYPTION_KEY",t),console.log("Generated random SYMM_ENCRYPTION_KEY"),e=!0}if(!o.getString("JWT_SECRET")){let t=y.randomBytes(32).toString("hex");o.set("JWT_SECRET",t),console.log("Generated random JWT_SECRET"),e=!0}if(!o.getString("JWT_REFRESH_SECRET")){let t=y.randomBytes(32).toString("hex");o.set("JWT_REFRESH_SECRET",t),console.log("Generated random JWT_REFRESH_SECRET"),e=!0}e&&o.flush()}var ie=async e=>{try{return(await fetch(e,{method:"GET",signal:AbortSignal.timeout(5e3)})).status===200}catch{return!1}},L=async(e,t,r)=>{let a=Date.now();for(;Date.now()-a<t;){if(await ie(e))return!0;await new Promise(s=>setTimeout(s,r))}return!1};async function le(){await W()||await j(),await b();try{I()&&await J(),F();let t=o.getNumber("PORT")||4466;if(!t)throw new Error("PORT env variable not found");if(!await O(t))throw new Error(`Port ${t} is occupied by another process`);let a=(0,x.default)({text:"Starting new instance of "+c}).start(),n=D.readJsonSync((0,Y.join)(i,"package.json"));await g(`pm2 start "${n.main}" --name "${c}" --no-autorestart -- "${i}/.env"`,{cwd:i}),a.success("Local server will be available in a couple of seconds");let s=(0,x.default)({text:"Waiting for the server to become available"}).start();await L(`http://localhost:${t}/api/status`,3e4,1e3)?(await(0,T.default)(`http://localhost:${t}`),s.success(`App is running at http://localhost:${t}`)):s.error("Server failed to become available in time")}catch(t){console.error("Failed to start local server",t)}}async function me(){(0,K.execSync)(`pm2 logs ${c}`,{stdio:"inherit"})}async function ue(){await b()}function fe(){console.log(`DataRamen CLI version: ${v().version}`),console.log(`DataRamen local server version: ${S().version}`)}async function pe(){let e=o.getNumber("PORT");await(0,T.default)(`http://localhost:${e}`)}function de(e,t){o.set(e,t),o.flush(),console.log(`Environment property set: ${e}`)}function ge(e){o.unset(e),o.flush(),console.log(`Environment property unset: ${e}`)}var l={start:le,logs:me,stop:ue,version:fe,open:pe,setEnvVariable:de,unsetEnvVariable:ge};var w=new B.Command,Ee=[{command:"start",description:"Start local server, restarts if already running",handler:l.start},{command:"logs",description:"Listen for logs",handler:l.logs},{command:"stop",description:"Stop the server",handler:l.stop},{command:"open",description:"Stop the server",handler:l.open},{command:"set <prop> <value>",description:"Set env value",handler:l.setEnvVariable},{command:"unset <prop>",description:"Remove env value",handler:l.unsetEnvVariable}];w.name("dataramen").description("A cozy web GUI for MySQL and PostgreSQL - built for developers who like to move fast and stay focused.").version(v().version,"-v, --version","Show version");w.command("default",{hidden:!0,isDefault:!0}).action(l.start);Ee.forEach(e=>{w.command(e.command).description(e.description).action(e.handler)});w.parse();
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@dataramen/server","version":"0.0.
|
|
1
|
+
{"name":"@dataramen/server","version":"0.0.84-beta.2","license":"MIT","main":"code/server.js","dependencies":{"@fastify/cors":"^11.0.1","@fastify/static":"^8.2.0","@fastify/cookie":"^11.0.2","dotenv":"^16.5.0","fast-glob":"^3.3.3","fastify":"^5.3.2","mysql2":"^3.14.1","pg":"^8.15.6","sqlite3":"^5.1.7","typeorm":"^0.3.27","bcryptjs":"^3.0.2","jose":"^6.0.12","reflect-metadata":"^0.2.2","qs":"^6.14.0"},"devDependencies":{"fs-extra":"^11.3.0","open":"^10.2.0","commander":"^14.0.2","yocto-spinner":"^1.0.0"}}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataramen/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61-beta.2",
|
|
4
4
|
"repository": "https://github.com/OleksandrDemian/dataramen.git",
|
|
5
5
|
"author": "Oleksandr Demian <oleksandrovsky@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
8
|
-
"dataramen": "bin/
|
|
8
|
+
"dataramen": "bin/app.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "node build.mjs"
|
|
@@ -13,12 +13,11 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"fs-extra": "^11.3.0",
|
|
15
15
|
"open": "^10.2.0",
|
|
16
|
-
"
|
|
16
|
+
"commander": "^14.0.2",
|
|
17
17
|
"yocto-spinner": "^1.0.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/fs-extra": "^11.0.3",
|
|
21
|
-
"@types/yargs": "^17.0.33",
|
|
22
21
|
"esbuild": "^0.25.5"
|
|
23
22
|
},
|
|
24
23
|
"files": [
|
package/bin/run.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var G=Object.create;var x=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var X=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of q(t))!Q.call(e,n)&&n!==r&&x(e,n,{get:()=>t[n],enumerable:!(a=U(t,n))||a.enumerable});return e};var l=(e,t,r)=>(r=e!=null?G(z(e)):{},X(t||!e||!e.__esModule?x(r,"default",{value:e,enumerable:!0}):r,e));var D=l(require("yargs")),B=require("yargs/helpers");var T=require("node:os"),V=require("node:path"),Z=(0,T.homedir)(),c="@dataramen/server",i=(0,V.join)(Z,".dataramen",".runtime","server");var Y=require("node:path"),K=l(require("fs-extra")),L=require("node:child_process");var C=l(require("fs-extra")),w=require("node:path");function A(e){let t;function r(){try{return t||(t=C.readJsonSync(e)),t}catch{return}}return r}var N=A((0,w.join)(__dirname,"..","package.json")),v=A((0,w.join)(i,"package.json"));var f=l(require("fs-extra")),p=require("node:path"),k=require("node:child_process"),M=require("node:util"),E=l(require("yocto-spinner")),g=(0,M.promisify)(k.exec);function $(){try{let e=v();if(!e)return!0;let t=f.readJsonSync((0,p.join)(__dirname,"..","dist","package.json"));return e.version!==t.version}catch{return!0}}async function W(){let e=(0,E.default)({text:"Checking if PM2 is installed"}).start();try{return await g("pm2 -v"),e.success("PM2 already installed"),!0}catch{return e.warning("PM2 not installed"),!1}}async function j(){let e=(0,E.default)({text:"Installing PM2"}).start();try{await g("npm i -g pm2"),e.success("Installed PM2")}catch{e.error("Failed to install PM2"),process.exit(1)}}async function R(){let e=(0,E.default)({text:"Stop running instances of "+c}).start();try{await g(`pm2 stop "${c}"`),e.warning("Stopped "+c)}catch{e.success("No running instances of "+c+" found")}}async function I(){let e=(0,E.default)({text:"Create local server"}).start();f.removeSync((0,p.join)(i,"code")),f.copySync((0,p.join)(__dirname,"..","dist","code"),(0,p.join)(i,"code")),f.copySync((0,p.join)(__dirname,"..","dist","package.json"),(0,p.join)(i,"package.json")),e.text="Install local server dependencies",await g("npm i",{cwd:i}),e.success("Local server installed")}var P=l(require("yocto-spinner")),_=l(require("open"));var J=require("node:net");async function H(e){return new Promise(t=>{let r=(0,J.createServer)().once("error",()=>{t(!1)}).once("listening",()=>{r.close()}).once("close",()=>t(!0)).listen(e,"127.0.0.1")})}var h=l(require("node:crypto"));var S=require("fs-extra"),b=require("node:path");function ee(e){try{return(0,S.readFileSync)((0,b.join)(i,e),"utf-8")}catch{return}}function te(e){let t={},r=ee(e);if(r){let a=r.split(`
|
|
3
|
-
`);for(let n of a){let s=n.trim();if(!s||s.startsWith("#"))continue;let d=s.indexOf("=");if(d===-1)continue;let y=s.slice(0,d).trim(),u=s.slice(d+1).trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),t[y]=u}}return t}function ne(){let e={customValues:{},fileName:".env"};function t(){e.customValues=te(e.fileName)}function r(){let s=Object.entries(e.customValues).map(([d,y])=>`${d}=${y}`).join(`
|
|
4
|
-
`)+`
|
|
5
|
-
`;(0,S.writeFileSync)((0,b.join)(i,e.fileName),s,{encoding:"utf8"})}function a(n){if(e.customValues[n])return e.customValues[n]}return t(),{getNumber:n=>re(a(n)),getString:n=>oe(a(n)),getBoolean:n=>se(a(n)),flush:r,set:(n,s)=>{e.customValues[n]=s},unset:n=>{delete e.customValues[n]}}}function re(e){if(!e)return;let t=Number(e);if(!isNaN(t)&&e.trim()!=="")return t;throw new Error("Wrong env value type")}function oe(e){if(e){if(typeof e=="string")return e;throw new Error("Wrong env value type")}}function se(e){if(!e)return;let t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;throw new Error("Wrong env value type")}var o=ne();function O(){let e=!1;if(!o.getString("SYMM_ENCRYPTION_KEY")){let t=h.randomBytes(32).toString("hex");o.set("SYMM_ENCRYPTION_KEY",t),console.log("Generated random SYMM_ENCRYPTION_KEY"),e=!0}if(!o.getString("JWT_SECRET")){let t=h.randomBytes(32).toString("hex");o.set("JWT_SECRET",t),console.log("Generated random JWT_SECRET"),e=!0}if(!o.getString("JWT_REFRESH_SECRET")){let t=h.randomBytes(32).toString("hex");o.set("JWT_REFRESH_SECRET",t),console.log("Generated random JWT_REFRESH_SECRET"),e=!0}e&&o.flush()}var ie=async e=>{try{return(await fetch(e,{method:"GET",signal:AbortSignal.timeout(5e3)})).status===200}catch{return!1}},F=async(e,t,r)=>{let a=Date.now();for(;Date.now()-a<t;){if(await ie(e))return!0;await new Promise(s=>setTimeout(s,r))}return!1};async function le(){await W()||await j(),await R();try{$()&&await I(),O();let t=o.getNumber("PORT")||4466;if(!t)throw new Error("PORT env variable not found");if(!await H(t))throw new Error(`Port ${t} is occupied by another process`);let a=(0,P.default)({text:"Starting new instance of "+c}).start(),n=K.readJsonSync((0,Y.join)(i,"package.json"));await g(`pm2 start "${n.main}" --name "${c}" --no-autorestart -- "${i}/.env"`,{cwd:i}),a.success("Local server will be available in a couple of seconds");let s=(0,P.default)({text:"Waiting for the server to become available"}).start();await F(`http://localhost:${t}/api/status`,3e4,1e3)?(await(0,_.default)(`http://localhost:${t}`),s.success(`App is running at http://localhost:${t}`)):s.error("Server failed to become available in time")}catch(t){console.error("Failed to start local server",t)}}async function me(){(0,L.execSync)(`pm2 logs ${c}`,{stdio:"inherit"})}async function ue(){await R()}function pe(){console.log(`DataRamen CLI version: ${N().version}`),console.log(`DataRamen local server version: ${v().version}`)}async function fe(){let e=o.getNumber("PORT");await(0,_.default)(`http://localhost:${e}`)}function de(e){o.set(e.prop,e.value),o.flush(),console.log(`Environment property set: ${e.prop}`)}function ge(e){o.unset(e.prop),o.flush(),console.log(`Environment property unset: ${e.prop}`)}var m={start:le,logs:me,stop:ue,version:pe,open:fe,setEnvVariable:de,unsetEnvVariable:ge};(0,D.default)((0,B.hideBin)(process.argv)).command({command:"start",describe:"Start local server, restarts if already running",handler:m.start}).command({command:"logs",describe:"Listen for logs",handler:m.logs}).command({command:"stop",describe:"Stop the server",handler:m.stop}).command({command:"open",describe:"Stop the server",handler:m.open}).command({command:"set [prop] [value]",describe:"Set env value",handler:m.setEnvVariable}).command({command:"unset [prop]",describe:"Remove env value",handler:m.unsetEnvVariable}).command({command:"version",describe:"Show version",handler:m.version}).parse();
|