@mahameru/cli 0.0.23 → 0.0.25
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/cli.js +71 -64
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* ┌────────────────────────────────────────────┐
|
|
4
4
|
* │ │
|
|
5
5
|
* │ ▲ MahameruJS - CLI │
|
|
6
|
-
* │ Version: 0.0.
|
|
6
|
+
* │ Version: 0.0.25 │
|
|
7
7
|
* │ Built: 2026 │
|
|
8
8
|
* │ │
|
|
9
9
|
* │ Copyright (c) Bintan <hello@bintvn.co> │
|
|
@@ -20,10 +20,10 @@ f.generateRouteTypes)((0,c.join)(e,"src","routes"),(0,c.join)(o,"types","routes.
|
|
|
20
20
|
f.generateDataSourceTypes)((0,c.join)(e,"src","databases"),(0,c.join)(o,"types","dataSources.d.ts")),await(0,
|
|
21
21
|
f.generateTypesBarrel)((0,c.join)(o,"types","index.d.ts")),await(0,f.generateMahameruDts)((0,c.join)(e,"mahameru.d.ts"))
|
|
22
22
|
;const n="tsconfig.build.json",a=(0,c.join)(e,n),l=(0,c.join)(e,"tsconfig.json"),v=await(0,i.readFile)(l,"utf8")
|
|
23
|
-
;let
|
|
24
|
-
i.writeFile)(a,JSON.stringify(
|
|
25
|
-
const
|
|
26
|
-
d.deleteDirIfExists)(o),process.exit(
|
|
23
|
+
;let w=null;try{w=JSON.parse(v),w.compilerOptions.outDir=".mahameru",w.compilerOptions.rootDir="src",await(0,
|
|
24
|
+
i.writeFile)(a,JSON.stringify(w,null,2))}catch(e){console.error(`Error parsing ${l}: ${e}`),process.exit(1)}
|
|
25
|
+
const P=await(0,u.runNodeScript)(g,["--project",n],e);0!==P&&(r.fail(s.default.red(" Build failed!")),await(0,
|
|
26
|
+
d.deleteDirIfExists)(o),process.exit(P));const S=await(0,u.runNodeScript)(y,["--project",n],e)
|
|
27
27
|
;0!==S&&(r.fail(s.default.red(" tsc-alias failed.")),await(0,d.deleteDirIfExists)(o),process.exit(S));const $=(0,
|
|
28
28
|
p.findUnresolvedAliases)(o);if($.length>0){r.fail(s.default.red(" Build produced unresolved path aliases.")),
|
|
29
29
|
console.error(s.default.yellow("Please use tsconfig path aliases such as @/* and avoid package.json imports for app source files."))
|
|
@@ -31,17 +31,18 @@ console.error(s.default.yellow("Please use tsconfig path aliases such as @/* and
|
|
|
31
31
|
d.deleteDirIfExists)((0,c.join)(o,"types"));try{
|
|
32
32
|
const t=await(0,i.readFile)((0,c.join)(e,"package.json"),"utf-8"),r=JSON.parse(t)
|
|
33
33
|
;r.devDependencies&&delete r.devDependencies,await(0,i.writeFile)((0,c.join)(o,"package.json"),JSON.stringify(r,null,2))
|
|
34
|
-
}catch{}const
|
|
35
|
-
m.existsSync)(
|
|
36
|
-
c.join)(o,".env.production")):(0,m.existsSync)(
|
|
34
|
+
}catch{}const _=(0,c.join)(e,".env"),M=(0,c.join)(e,".env.development"),j=(0,c.join)(e,".env.production");(0,
|
|
35
|
+
m.existsSync)(_)&&await(0,i.copyFile)(_,(0,c.join)(o,".env")),(0,m.existsSync)(j)?await(0,i.copyFile)(j,(0,
|
|
36
|
+
c.join)(o,".env.production")):(0,m.existsSync)(M)&&await(0,i.copyFile)(M,(0,c.join)(o,".env.production")),await(0,
|
|
37
37
|
h.createZip)((0,c.join)(process.cwd(),t),(0,c.join)(process.cwd(),`${t}.zip`),!1),
|
|
38
38
|
r.succeed(s.default.green(" Build success."))}catch(e){r.fail(s.default.red(" Internal error.")),console.error(e),
|
|
39
39
|
process.exit(1)}}}
|
|
40
40
|
;const n=o(8330),s=r(o(5205)),a=r(o(8720)),i=o(1455),c=o(6760),l=o(242),d=o(5775),u=o(5412),p=o(5242),f=o(1855),m=o(3024),h=o(8419)
|
|
41
|
-
},7022(e,t,o){t.dev=function({version:e}){return async({host:t,port:o})=>{const i=(0,
|
|
42
|
-
s.printCliBanner)(e),o=await(0,r.freePortFinder)(o),await(0,a.startWatchedDevServer)({
|
|
43
|
-
port:o})}};const r=o(7209),n=o(242),s=o(1785),a=o(8320)},3674(e,t,o){
|
|
44
|
-
return e&&e.__esModule?e:{default:e}}
|
|
41
|
+
},7022(e,t,o){t.dev=function({version:e}){return async({host:t,port:o})=>{console.clear();const i=(0,
|
|
42
|
+
n.ensureDevEnvironment)();(0,s.printCliBanner)(e),o=await(0,r.freePortFinder)(o),await(0,a.startWatchedDevServer)({
|
|
43
|
+
version:e,environment:i,host:t,port:o})}};const r=o(7209),n=o(242),s=o(1785),a=o(8320)},3674(e,t,o){
|
|
44
|
+
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
45
|
+
;Object.defineProperty(t,"__esModule",{value:!0}),t.install=void 0
|
|
45
46
|
;const n=o(1421),s=o(3024),a=r(o(5205)),i=o(6760),c=o(6921),l=o(6718),d=o(6471),u=r(o(8720)),p=o(1455)
|
|
46
47
|
;t.install=e=>({host:t,port:o,cert:r,key:f})=>{const m="linux"===process.platform,h="win32"===process.platform;let g=""
|
|
47
48
|
;try{g=(0,l.getNodeModulesPath)()}catch(e){return void console.error(a.default.red(`❌ ${e.message}`))}const y=(0,
|
|
@@ -146,8 +147,11 @@ t.generateTypesBarrel=async function(e){await(0,n.mkdir)((0,s.dirname)(e),{recur
|
|
|
146
147
|
n.writeFile)(e,"export * from './dataSources';\nexport * from './routes';\n","utf-8")},
|
|
147
148
|
t.generateMahameruDts=async function(e){
|
|
148
149
|
await(0,n.writeFile)(e,'/// <reference path="./.mahameru/types/index.d.ts" />\n\n// Do not edit this file, it is generated by MahameruJS\n',"utf-8")
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
;try{const e=(0,s.join)(process.cwd(),"tsconfig.json"),t=JSON.parse(await(0,n.readFile)(e,"utf-8"))
|
|
151
|
+
;void 0===t.include?t.include=["mahameru.d.ts"]:t.include.includes("mahameru.d.ts")||t.include.push("mahameru.d.ts"),
|
|
152
|
+
await(0,n.writeFile)(e,JSON.stringify(t,null,2),"utf-8")}catch(e){console.error(e)}};const r=o(3024),n=o(1455),s=o(6760)
|
|
153
|
+
},1785(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
154
|
+
;Object.defineProperty(t,"__esModule",{value:!0}),t.printCliBanner=function(e){
|
|
151
155
|
console.log(`${n.default.bold(n.default.cyan("▲ Mahameru"))} ${n.default.dim(`CLI v${e}`)}\n`)};const n=r(o(5205))},
|
|
152
156
|
8235(e,t){t.printServerReady=function({mode:e,dev:t,host:o,port:r}){console.log("[32m Mahameru Server Ready![0m"),
|
|
153
157
|
console.log(` [1mMode:[22m [36m${e}[0m`),console.log(` [1mLocal:[22m [36mhttp://${o}:${r}[0m`),
|
|
@@ -158,18 +162,18 @@ return new Promise((n,s)=>{const a=(0,r.spawn)(process.execPath,[e,...t],{stdio:
|
|
|
158
162
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
159
163
|
;Object.defineProperty(t,"__esModule",{value:!0
|
|
160
164
|
}),t.startWatchedDevServer=async function({environment:e,host:t,port:o,version:r}){
|
|
161
|
-
let u,
|
|
165
|
+
let u,M=null,j=!1,x=null,E=!1,T=!0,A=!1,b=0;const D=new Set,O=new Set;await(0,p.generateRouteTypes)((0,
|
|
162
166
|
a.join)(m,"src","routes"),(0,a.join)(h,"types","routes.d.ts")),await(0,p.generateDataSourceTypes)((0,
|
|
163
167
|
a.join)(m,"src","databases"),(0,a.join)(h,"types","dataSources.d.ts")),await(0,p.generateTypesBarrel)((0,
|
|
164
168
|
a.join)(h,"types","index.d.ts")),await(0,p.generateMahameruDts)((0,a.join)(m,"mahameru.d.ts")),await(0,s.mkdir)(h,{
|
|
165
169
|
recursive:!0});const R=(0,i.default)({text:`${c.default.cyan("[Mahameru]")} Starting TypeScript watch...`,
|
|
166
170
|
spinner:"triangle"}).start(),k={dev:!0,host:t,port:o,rootPath:m};u=new d.App(k),
|
|
167
|
-
|
|
171
|
+
M=await async function({environment:e,spinner:t,onBuildStart:o,onBuildSuccess:r,onBuildFailure:i}){const l=(0,
|
|
168
172
|
a.resolve)((0,
|
|
169
|
-
a.join)(m,"node_modules","typescript")),{createWatchCompilerHost:d,createWatchProgram:u,formatDiagnosticsWithColorAndContext:p,formatDiagnostic:
|
|
173
|
+
a.join)(m,"node_modules","typescript")),{createWatchCompilerHost:d,createWatchProgram:u,formatDiagnosticsWithColorAndContext:p,formatDiagnostic:w,sys:S,createEmitAndSemanticDiagnosticsBuilderProgram:M}=f(l),j={
|
|
170
174
|
getCanonicalFileName:e=>e,getCurrentDirectory:()=>m,getNewLine:()=>S.newLine};let x=!1,E=!1,T=0
|
|
171
175
|
;const A=new Map,b=new Map;let D,O,R=Promise.resolve();const k=new Promise((e,t)=>{D=e,O=t}),C=d(v,{rootDir:y,outDir:h
|
|
172
|
-
},S,
|
|
176
|
+
},S,M,e=>{E=!0;const t=e.file?p([e],j):w(e,j);process.stderr.write(t.endsWith("\n")?t:`${t}\n`)},e=>{
|
|
173
177
|
const t=e.messageText.toString().trim();(function(e){
|
|
174
178
|
return e.includes("Starting compilation in watch mode...")||e.includes("File change detected. Starting incremental compilation...")
|
|
175
179
|
})(t)&&(T+=1,A.set(T,Date.now()),b.set(T,{emittedRuntimeFiles:new Set,changedRuntimeSourceFiles:new Set}),E=!1,o()),
|
|
@@ -186,12 +190,12 @@ console.error(c.default.red("[Mahameru Dev] Build lifecycle failed.")),console.e
|
|
|
186
190
|
changedRuntimeSourceFiles:new Set}
|
|
187
191
|
;if(E)return x||(x=!0,t.fail(`${c.default.red("[Mahameru]")} Initial TypeScript build failed.`),
|
|
188
192
|
O(new Error("Initial TypeScript build failed."))),b.delete(o),A.delete(o),void i();try{if(x)await async function(e){
|
|
189
|
-
if(0===e.length)return;const t=await async function(){if(!
|
|
190
|
-
a.join)(__dirname,"node_modules","tsc-alias")),{prepareSingleFileReplaceTscAliasPaths:t}=f(e);
|
|
191
|
-
})}return
|
|
193
|
+
if(0===e.length)return;const t=await async function(){if(!P){const e=(0,a.resolve)((0,
|
|
194
|
+
a.join)(__dirname,"node_modules","tsc-alias")),{prepareSingleFileReplaceTscAliasPaths:t}=f(e);P=t({configFile:v,outDir:h
|
|
195
|
+
})}return P}();for(const o of e){if(!(0,n.existsSync)(o))continue;const e=await(0,s.readFile)(o,"utf8"),r=t({
|
|
192
196
|
fileContents:e,filePath:o});r!==e&&await(0,s.writeFile)(o,r)}}([...d.emittedRuntimeFiles]);else{
|
|
193
|
-
await async function(e=3e4){const t=Date.now();for(;Date.now()-t<e;){if((0,n.existsSync)(g))return void await
|
|
194
|
-
;await
|
|
197
|
+
await async function(e=3e4){const t=Date.now();for(;Date.now()-t<e;){if((0,n.existsSync)(g))return void await _(200)
|
|
198
|
+
;await _(100)}throw new Error("Timed out waiting for emitted dev runtime artifacts.")}();const e=(0,a.resolve)((0,
|
|
195
199
|
a.join)(__dirname,"node_modules","tsc-alias")),{replaceTscAliasPaths:t}=f(e);await t({configFile:v,outDir:h})}}catch(e){
|
|
196
200
|
return console.error(c.default.red("[Mahameru Alias] Alias rewrite failed.")),console.error(e),x||(x=!0,
|
|
197
201
|
t.fail(`${c.default.red("[Mahameru]")} Initial alias rewrite failed.`),O(e instanceof Error?e:new Error(String(e)))),
|
|
@@ -209,7 +213,7 @@ onBuildSuccess:({durationMs:e,emittedRuntimeFiles:t,changedRuntimeSourceFiles:o,
|
|
|
209
213
|
for(const e of t)D.add(e);for(const e of o)O.add(e)}T||!u?.initialized||j||(E||A||0!==D.size)&&I()},onBuildFailure:()=>{
|
|
210
214
|
T=!1,b=0,A=!1,D.clear(),O.clear(),x&&(clearTimeout(x),x=null)}
|
|
211
215
|
}),R.succeed(`${c.default.green("[Mahameru]")} Initial build completed.\n`),await u.start()
|
|
212
|
-
;const C=new l.Watchman([h,
|
|
216
|
+
;const C=new l.Watchman([h,w]),N=new l.Watchman(y);let F=Promise.resolve();const I=()=>{x&&clearTimeout(x),
|
|
213
217
|
x=setTimeout(()=>{F=F.then(async()=>{if(j||!u)return;if(T)return void I();const e=[...D],t=[...O],o=A,r=E;if(E=!1,A=!1,
|
|
214
218
|
D.clear(),
|
|
215
219
|
O.clear(),x=null,r)return console.log(c.default.yellow("\n [Mahameru] Config file changed. Reloading server...\n")),
|
|
@@ -219,7 +223,7 @@ await u.stop(),u=new d.App(k),console.clear(),void await u.start();if(0===e.leng
|
|
|
219
223
|
a.relative)(m,s).replace(/\\/g,"/")} build: ${b}ms runtime: ${l}ms total: ${p}ms`)}).catch(e=>{
|
|
220
224
|
console.error(c.default.red("[Mahameru Dev] Hot reload failed.")),console.error(e)})},250)}
|
|
221
225
|
;C.on("all",({event:e,filePath:t})=>{const o=function(e){const t=(0,a.resolve)(e),o=$(t),r=$((0,a.resolve)(h)),n=$((0,
|
|
222
|
-
a.resolve)(g)),s=$((0,a.resolve)(
|
|
226
|
+
a.resolve)(g)),s=$((0,a.resolve)(w));if(!o.startsWith(`${r}/`)&&o!==s)return null
|
|
223
227
|
;if(o.endsWith(".d.ts")||o.endsWith(".map")||o.endsWith(".tsbuildinfo"))return null;if(o===s)return"config"
|
|
224
228
|
;if(!o.endsWith(".js"))return null;if(o.startsWith(`${n}/`))return"runtime";return null}(t)
|
|
225
229
|
;o&&("runtime"===o&&"delete"!==e&&"rename"!==e||((e,t)=>{"config"===e?E=!0:(D.add(t),O.add(S(t))),T||I()})(o,t))}),
|
|
@@ -231,12 +235,12 @@ const e=function(e){const t=(0,a.relative)(y,e);return(0,a.resolve)(g,t.replace(
|
|
|
231
235
|
s.rm)(e.replace(/\.js$/i,".d.ts"),{force:!0}).catch(()=>{}),(0,s.rm)(e.replace(/\.js$/i,".d.ts.map"),{force:!0
|
|
232
236
|
}).catch(()=>{})])}await(0,s.rm)((0,a.resolve)(g,o),{recursive:!0,force:!0}).catch(()=>{})}(r),A=!0,O.add((0,
|
|
233
237
|
a.resolve)(r)),T||I())}),await C.start(),await N.start();const H=async(e=0)=>{j||(j=!0,x&&(clearTimeout(x),x=null),
|
|
234
|
-
C.stop(),N.stop(),await u.stop(),
|
|
238
|
+
C.stop(),N.stop(),await u.stop(),M?.close(),process.exit(e))};process.once("SIGINT",()=>{H(0)}),
|
|
235
239
|
process.once("SIGTERM",()=>{H(0)}),await new Promise(()=>{})}
|
|
236
240
|
;const n=o(3024),s=o(1455),a=o(6760),i=r(o(8720)),c=r(o(5205)),l=o(6469),d=o(1205),u=o(8995),p=o(1855),f=(0,
|
|
237
241
|
u.createRequire)(__filename),m=process.cwd(),h=(0,a.join)(m,".mahameru"),g=h,y=(0,a.join)(m,"src"),v=(0,
|
|
238
|
-
a.join)(m,"tsconfig.json"),
|
|
239
|
-
;return(0,a.resolve)(y,t.replace(/\.js$/i,".ts"))}function $(e){return e.replace(/\\/g,"/")}function
|
|
242
|
+
a.join)(m,"tsconfig.json"),w=(0,a.join)(m,"mahameru.config.ts");let P=null;function S(e){const t=(0,a.relative)(g,e)
|
|
243
|
+
;return(0,a.resolve)(y,t.replace(/\.js$/i,".ts"))}function $(e){return e.replace(/\\/g,"/")}function _(e){
|
|
240
244
|
return new Promise(t=>{setTimeout(t,e)})}},5775(e,t,o){t.deleteDirIfExists=async function(e){return await(0,r.rm)(e,{
|
|
241
245
|
recursive:!0,force:!0})},t.parsePort=function(e){const t=parseInt(e,10);return isNaN(t)?void 0:t}
|
|
242
246
|
;const r=o(1455),n=o(8161)},6469(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{
|
|
@@ -276,23 +280,26 @@ const t=e.split("/"),o=[];for(const e of t){if(c.test(e))break;o.push(e)}
|
|
|
276
280
|
return 0===o.length?i.default.dirname(e):o.join("/")}normalizePath(e){return e.replace(/\\/g,"/")}}t.Watchman=l},
|
|
277
281
|
846(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
278
282
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.startFork=void 0
|
|
279
|
-
;const n=r(o(9278)),s=r(o(5205)),a=o(4813),i=o(7209),c=r(o(8720)),l=o(4830),d=o(3157),u=o(6921)
|
|
280
|
-
;t.startFork=({rootPath:e})=>async t=>{const o=(0,d.getWindowsElevatedWorkingDirectory)()??e,r=t.port,
|
|
283
|
+
;const n=r(o(9278)),s=r(o(5205)),a=o(4813),i=o(7209),c=r(o(8720)),l=o(4830),d=o(3157),u=o(6921),p=o(9896),f=o(6928),m=o(5317)
|
|
284
|
+
;t.startFork=({rootPath:e})=>async t=>{const o=(0,d.getWindowsElevatedWorkingDirectory)()??e,r=t.port,h=t.host;(0,
|
|
281
285
|
a.isMahameruProjectDir)(o)||(console.error(s.default.red(`\n${o} is not a Mahameru project directory.`)),
|
|
282
|
-
process.exit(1));const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
+
process.exit(1));const g=await(0,l.getProjectJson)(o);if(!(0,p.existsSync)((0,f.join)(o,"node_modules"))||!(0,
|
|
287
|
+
p.existsSync)((0,f.join)(o,"package-lock.json"))){const e=(0,c.default)("Installing dependencies...").start();(0,
|
|
288
|
+
m.execSync)("npm install",{stdio:"inherit",cwd:o}),e.succeed(s.default.green("\nDependencies installed."))}const y=(0,
|
|
289
|
+
c.default)("Checking available port...").start(),v=await(0,i.freePortFinder)(r)
|
|
290
|
+
;y.text="Connecting to MahameruJS PM Daemon...";const w=n.default.createConnection({path:u.IPC_SOCKET_PATH},()=>{
|
|
291
|
+
w.write(JSON.stringify({command:"FORK_PROJECT",payload:{name:g.name,description:g.description,version:g.version,
|
|
292
|
+
projectRoot:o,port:v,host:h}}))});w.on("data",e=>{
|
|
286
293
|
const t=JSON.parse(e.toString()),{success:o,message:r,data:n,mpmUrl:a}=t
|
|
287
294
|
;o?(!function({name:e,version:t,mode:o,host:r,port:n,pid:a,mpmUrl:i}){
|
|
288
295
|
const c=[`${s.default.bold("App:")} ${s.default.cyan(e)}`,`${s.default.bold("Version:")} ${t}`,`${s.default.bold("Mode:")} ${s.default.cyan(o)}`,`${s.default.bold("PID:")} ${a}`,`${s.default.bold("Local:")} ${s.default.cyan(`http://${r}:${n}`)}`]
|
|
289
296
|
;i&&c.push(`${s.default.bold("PM URL:")} ${s.default.cyan(i)}`),console.log(s.default.green("\n Project Started")),
|
|
290
297
|
c.forEach(e=>console.log(` ${e}`)),
|
|
291
|
-
console.log(`\n${s.default.dim("Use `mahameru status` to inspect this managed project.")}\n`)}({name:
|
|
292
|
-
version:
|
|
293
|
-
|
|
294
|
-
process.exit(0)}),
|
|
295
|
-
"ENOENT"===e.code||"ECONNREFUSED"===e.code?
|
|
298
|
+
console.log(`\n${s.default.dim("Use `mahameru status` to inspect this managed project.")}\n`)}({name:g.name,
|
|
299
|
+
version:g.version,mode:"production",host:n.host,port:n.port,pid:n.pid,mpmUrl:a}),
|
|
300
|
+
y.succeed(s.default.green(`\n${r}`))):(y.fail(s.default.red("Failed to start project!")),console.error(t)),w.end(),
|
|
301
|
+
process.exit(0)}),w.on("error",e=>{
|
|
302
|
+
"ENOENT"===e.code||"ECONNREFUSED"===e.code?y.fail(s.default.red(`\nMahameru PM Daemon is not running.\nCannot connect to Mahameru PM Daemon. Make sure you run ${s.default.bold("mahameru pm service install")} first.`)):"win32"===process.platform&&"EPERM"===e.code?function(e,t){
|
|
296
303
|
if(!(0,d.hasWindowsElevationRetry)()&&!(0,d.isWindowsProcessElevated)()){
|
|
297
304
|
e.warn(s.default.yellow("\nWindows blocked access to the Mahameru PM pipe. Requesting Administrator approval..."))
|
|
298
305
|
;const o=(0,d.relaunchCurrentProcessAsAdmin)(t)
|
|
@@ -305,7 +312,7 @@ process.exit(0))
|
|
|
305
312
|
o.errorText&&console.error(s.default.dim(o.errorText)),process.exit(1)}
|
|
306
313
|
e.fail(s.default.red(`\nAccess denied while connecting to Mahameru PM Daemon.\nThe daemon or Windows service is likely running elevated, and the elevated retry still could not access ${s.default.bold(u.IPC_SOCKET_PATH)}.`)),
|
|
307
314
|
console.log(s.default.dim("Check the visible Administrator PowerShell window for the detailed failure output.")),
|
|
308
|
-
process.exit(1)}(
|
|
315
|
+
process.exit(1)}(y,o):(y.fail(s.default.red(`\n${e.message}`)),console.error(e)),process.exit(1)})}},1471(e,t,o){
|
|
309
316
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
310
317
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.startService=void 0
|
|
311
318
|
;const n=o(6921),s=o(1421),a=o(3024),i=o(6760),c=r(o(5205));t.startService=e=>()=>{
|
|
@@ -461,17 +468,17 @@ s.execSync)(`sc stop "${e}"`)}catch(e){}
|
|
|
461
468
|
console.error(c.default.red("❌ Uninstallation failed:"),e.message)}}},8625(e,t,o){
|
|
462
469
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
463
470
|
;Object.defineProperty(t,"__esModule",{value:!0})
|
|
464
|
-
;const n=o(6858),s=r(o(5205)),a=o(8330),i=o(7022),c=o(545),l=o(5775),d=o(3674),u=o(6478),p=o(6571),f=o(1471),m=o(5019),h=o(7659),g=o(846),y=o(7695),v=o(2074),
|
|
471
|
+
;const n=o(6858),s=r(o(5205)),a=o(8330),i=o(7022),c=o(545),l=o(5775),d=o(3674),u=o(6478),p=o(6571),f=o(1471),m=o(5019),h=o(7659),g=o(846),y=o(7695),v=o(2074),w=new n.Command
|
|
465
472
|
;(async()=>{try{const e=process.cwd(),t="mahameru-pm"
|
|
466
|
-
;
|
|
467
|
-
|
|
468
|
-
i.dev)({version:a.version})),
|
|
473
|
+
;w.name("mahameru").description(`${s.default.bold(s.default.cyan("▲ MahameruJS"))} ${s.default.dim(`CLI v${a.version}`)}`).version(a.version,"-v, --version","Display help for command"),
|
|
474
|
+
w.command("dev").description("Start MahameruJS development server.").option("-p, --port <number>","Port to run the server on",l.parsePort,3e3).option("-H, --host <string>","Host to run the server on","127.0.0.1").action((0,
|
|
475
|
+
i.dev)({version:a.version})),w.command("build").description("Build MahameruJS production application.").action((0,
|
|
469
476
|
c.build)({rootPath:e
|
|
470
|
-
})),
|
|
471
|
-
g.startFork)({rootPath:e})),
|
|
472
|
-
v.stopFork)(e,a.version)),
|
|
477
|
+
})),w.command("start").description("Start MahameruJS production server.").option("-p, --port <number>","Port to run the server on",l.parsePort,8e3).option("-H, --host <string>","Host to run the server on","127.0.0.1").action((0,
|
|
478
|
+
g.startFork)({rootPath:e})),w.command("stop").description("Stop MahameruJS production server.").action((0,
|
|
479
|
+
v.stopFork)(e,a.version)),w.command("status").description("View MahameruJS production server status.").action((0,
|
|
473
480
|
y.projectStatus)(e,a.version))
|
|
474
|
-
;const o=
|
|
481
|
+
;const o=w.command("pm").description(`${s.default.bold(s.default.cyan("▲ MahameruJS"))} ${s.default.dim(`Process Manager v${a.version}`)}`)
|
|
475
482
|
;o.command("start").description("Start MahameruJS Process Manager.").option("-p, --port <number>","Port to run the server on",l.parsePort,8e3).option("-H, --host <string>","Host to run the server on","127.0.0.1").option("--cert <string>","Path to the SSL certificate file").option("--key <string>","Path to the SSL key file").option("-d, --daemon","Run as a daemon",!1).action((0,
|
|
476
483
|
u.pm)(a.version)),
|
|
477
484
|
o.command("status").description("Start MahameruJS Process Manager.").option("-p, --port <number>","Port to run the server on",l.parsePort,8e3).option("-H, --host <string>","Host to run the server on","127.0.0.1").option("-d, --daemon","Run as a daemon",!1).action(()=>{
|
|
@@ -487,7 +494,7 @@ p.uninstall)(t)),r.command("start").description("Start MahameruJS Process Manage
|
|
|
487
494
|
f.startService)(t)),
|
|
488
495
|
r.command("stop").description("Stop MahameruJS Process Manager service.").option("-g, --graceful","Gracefully stop the service.",!1).action((0,
|
|
489
496
|
m.stopService)(t)),r.command("status").description("Get MahameruJS Process Manager status.").action((0,
|
|
490
|
-
h.status)(t,a.version)),await
|
|
497
|
+
h.status)(t,a.version)),await w.parseAsync(process.argv)}catch(e){console.error(e),process.exit(1)}})()},6921(e,t,o){
|
|
491
498
|
t.IPC_SOCKET_PATH=t.MQ=t.PROJECTS_FILE_PATH=t.APPDATA_PATH=t.Ds=t.ig=t.vL=t.IS_WINDOWS=void 0;const r=o(6760)
|
|
492
499
|
;"darwin"===process.platform||"win32"===process.platform||process.platform,t.IS_WINDOWS="win32"===process.platform,
|
|
493
500
|
t.vL="darwin"===process.platform,t.ig="linux"===process.platform,t.Ds="mahameru",t.APPDATA_PATH=(()=>{
|
|
@@ -511,7 +518,7 @@ return r=Object.getOwnPropertyNames||function(e){var t=[]
|
|
|
511
518
|
if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o=r(e),a=0;a<o.length;a++)"default"!==o[a]&&n(t,e,o[a])
|
|
512
519
|
;return s(t,e),t}),i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
513
520
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.processManager=void 0
|
|
514
|
-
;const c=i(o(5205)),l=o(1421),d=o(6760),u=i(o(7030)),p=o(7067),f=o(4708),m=o(6921),h=o(5043),g=o(6929),y=o(7209),v=a(o(3024)),
|
|
521
|
+
;const c=i(o(5205)),l=o(1421),d=o(6760),u=i(o(7030)),p=o(7067),f=o(4708),m=o(6921),h=o(5043),g=o(6929),y=o(7209),v=a(o(3024)),w=o(4437),P=(0,
|
|
515
522
|
d.join)(__dirname,"mpm"),S={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",
|
|
516
523
|
".png":"image/png",".jpg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon"}
|
|
517
524
|
;t.processManager=async({host:e,port:t,daemon:r,cert:n,key:s},a)=>{try{const i=await(0,y.freePortFinder)(t),$=(e,t)=>{
|
|
@@ -520,22 +527,22 @@ t.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),
|
|
|
520
527
|
t.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization"),t.setHeader("X-Powered-By","MahameruJS"),
|
|
521
528
|
"OPTIONS"===e.method)return t.writeHead(204),t.end();if("/api/process"===e.url&&"GET"===e.method){t.writeHead(200,{
|
|
522
529
|
"Content-Type":"application/json"});const e=(0,h.getProjects)().map(g.parseProject);return t.end(JSON.stringify(e))}
|
|
523
|
-
if("GET"===e.method){const o="/"===e.url?"/index.html":e.url;let r=(0,d.join)(
|
|
524
|
-
;return r.startsWith(
|
|
530
|
+
if("GET"===e.method){const o="/"===e.url?"/index.html":e.url;let r=(0,d.join)(P,o)
|
|
531
|
+
;return r.startsWith(P)?void v.default.access(r,v.default.constants.F_OK,e=>{if(!e){const e=(0,
|
|
525
532
|
d.extname)(r).toLowerCase(),o=S[e]||"application/octet-stream";return t.writeHead(200,{"Content-Type":o}),
|
|
526
|
-
v.default.createReadStream(r).pipe(t)}{const e=(0,d.join)(
|
|
533
|
+
v.default.createReadStream(r).pipe(t)}{const e=(0,d.join)(P,"index.html")
|
|
527
534
|
;v.default.access(e,v.default.constants.F_OK,o=>o?(t.writeHead(404,{"Content-Type":"text/html"}),
|
|
528
535
|
t.end("<h1>404 - Frontend Build Not Found</h1>")):(t.writeHead(200,{"Content-Type":"text/html"}),
|
|
529
536
|
v.default.createReadStream(e).pipe(t)))}}):(t.writeHead(403,{"Content-Type":"text/plain"}),t.end("Forbidden"))}
|
|
530
537
|
return t.writeHead(404,{"Content-Type":"text/html"}),t.end("<h1>404 Not Found</h1>")
|
|
531
|
-
},
|
|
538
|
+
},_=()=>console.log("[MPM] HTTP server closed."),M=e=>console.log("[MPM] HTTP server error:",e),j=async()=>{
|
|
532
539
|
process.send||r||(console.clear(),
|
|
533
540
|
console.log(`${c.default.bold(c.default.cyan("▲ Mahameru"))} ${c.default.dim(`Process Manager v${a}`)}\n`)),
|
|
534
541
|
console.log(`Server listening on host ${e} and port ${t}.`),
|
|
535
542
|
process.send||r||console.log(` ${c.default.bold(c.default.green("PID"))}: ${process.pid}\n ${c.default.bold(c.default.green("URL"))}: ${x?"https":"http"}://${e}:${t}\n${c.default.bold(c.default.green("API Endpoint"))}: ${x?"https":"http"}://${e}:${t}/api/process\n\n${c.default.dim("Press Ctrl+C to stop the server")}\n`)
|
|
536
543
|
;const o=await(0,h.loadProjects)();for(const e of o)e.isLastStatusIsRunning&&await U(e)},x=n&&s,E=n&&s?(0,
|
|
537
544
|
f.createServer)({cert:v.default.readFileSync(n),key:v.default.readFileSync(s)
|
|
538
|
-
},$).on("close",
|
|
545
|
+
},$).on("close",_).on("error",M).listen(i,e,j):(0,p.createServer)($).on("close",_).on("error",M).listen(i,e,j)
|
|
539
546
|
;if(!m.IS_WINDOWS){const e=o(9896);e.existsSync(m.IPC_SOCKET_PATH)&&e.unlinkSync(m.IPC_SOCKET_PATH)}const T=e=>t=>{
|
|
540
547
|
const o=t.toString().trim();console.log(`[${e}] ${o}`)},A=e=>t=>{const o=t.toString().trim()
|
|
541
548
|
;console.error(`[${e} ERROR] ${o}`)},b=(o,r,n)=>({type:s,data:a})=>{if(o)if("ERROR"===s)o.write(JSON.stringify({
|
|
@@ -591,7 +598,7 @@ h.getProject)(t.name);if(r){const{child:t,...o}=r;e.write(JSON.stringify({succes
|
|
|
591
598
|
error:t.message}))}})});q.on("close",()=>{console.log("[MPM IPC SERVER] IPC Server closed")}),q.on("error",e=>{
|
|
592
599
|
"EADDRINUSE"===e.code?console.error(`[MPM IPC SERVER] IPC Server already running on ${m.IPC_SOCKET_PATH}`):console.error("[MPM IPC SERVER]",e),
|
|
593
600
|
process.exit(1)}),q.listen(m.IPC_SOCKET_PATH,()=>{
|
|
594
|
-
console.log(`[MPM IPC SERVER] IPC Server listening on ${m.IPC_SOCKET_PATH}`)});const z=new
|
|
601
|
+
console.log(`[MPM IPC SERVER] IPC Server listening on ${m.IPC_SOCKET_PATH}`)});const z=new w.Server(E,{cors:{origin:"*"
|
|
595
602
|
},path:"/ws",serveClient:!1});z.on("connection",e=>{(0,h.setSocket)(e);const t=(0,h.getProjects)().map(g.parseProject)
|
|
596
603
|
;e.emit("projects",t),e.on("getProjects",e=>e({success:!0,data:(0,h.getProjects)().map(g.parseProject)})),
|
|
597
604
|
e.on("start",(e,t)=>{const o=(0,h.getProject)(e)
|
|
@@ -654,11 +661,11 @@ e?r(new Error(`Extraction failed: ${e.message}`)):o(`Successfully extracted to $
|
|
|
654
661
|
e?a(new Error(`Zipping failed: ${e}`)):r(`Successfully created zip at ${t}`)})}catch(e){a(e)}})},4650(e){
|
|
655
662
|
e.exports=require("adm-zip")},6858(e){e.exports=require("commander")},6261(e){e.exports=require("events")},8720(e){
|
|
656
663
|
e.exports=require("ora")},5205(e){e.exports=require("picocolors")},6471(e){e.exports=require("porterman/string-helper")
|
|
657
|
-
},4437(e){e.exports=require("socket.io")},
|
|
658
|
-
|
|
659
|
-
e.exports=require("node:
|
|
660
|
-
|
|
661
|
-
e.exports=require("node:
|
|
662
|
-
e.exports=require("node:
|
|
663
|
-
;(function o(r){const n=t[r];if(void 0!==n)return n.exports
|
|
664
|
-
;return e[r].call(s.exports,s,s.exports,o),s.exports})(8625)})();
|
|
664
|
+
},4437(e){e.exports=require("socket.io")},5317(e){e.exports=require("child_process")},9896(e){e.exports=require("fs")},
|
|
665
|
+
1943(e){e.exports=require("fs/promises")},9278(e){e.exports=require("net")},1421(e){
|
|
666
|
+
e.exports=require("node:child_process")},139(e){e.exports=require("node:cluster")},3024(e){e.exports=require("node:fs")
|
|
667
|
+
},1455(e){e.exports=require("node:fs/promises")},7067(e){e.exports=require("node:http")},4708(e){
|
|
668
|
+
e.exports=require("node:https")},8995(e){e.exports=require("node:module")},7030(e){e.exports=require("node:net")},
|
|
669
|
+
8161(e){e.exports=require("node:os")},6760(e){e.exports=require("node:path")},6928(e){e.exports=require("path")},
|
|
670
|
+
8330(e){e.exports={version:"0.0.25"}}};const t={};(function o(r){const n=t[r];if(void 0!==n)return n.exports
|
|
671
|
+
;const s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,o),s.exports})(8625)})();
|