@mahameru/cli 0.0.21 → 0.0.22
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 +375 -364
- package/package.json +2 -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.22 │
|
|
7
7
|
* │ Built: 2026 │
|
|
8
8
|
* │ │
|
|
9
9
|
* │ Copyright (c) Bintan <hello@bintvn.co> │
|
|
@@ -13,308 +13,312 @@
|
|
|
13
13
|
*/(()=>{"use strict";var e={545(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{
|
|
14
14
|
default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.build=function({rootPath:e}){return async()=>{
|
|
15
15
|
const t=".mahameru";const o=(0,c.join)(e,t)
|
|
16
|
-
;console.log(`${
|
|
17
|
-
|
|
18
|
-
l.ensureDevEnvironment)();try{r.text=
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
a.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
;0!==
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
;
|
|
29
|
-
|
|
16
|
+
;console.log(`${s.default.bold(s.default.cyan("▲ Mahameru"))} ${s.default.dim(`CLI v${n.version}`)}\n`);const r=(0,
|
|
17
|
+
a.default)(s.default.cyan(" Checking environment...")).start(),{tscJsPath:g,tscAliasJsPath:y}=(0,
|
|
18
|
+
l.ensureDevEnvironment)();try{r.text=s.default.cyan(" Starting build...\n"),await(0,d.deleteDirIfExists)(o),await(0,
|
|
19
|
+
f.generateRouteTypes)((0,c.join)(e,"src","routes"),(0,c.join)(o,"types","routes.d.ts")),await(0,
|
|
20
|
+
f.generateDataSourceTypes)((0,c.join)(e,"src","databases"),(0,c.join)(o,"types","dataSources.d.ts")),await(0,
|
|
21
|
+
f.generateTypesBarrel)((0,c.join)(o,"types","index.d.ts")),await(0,f.generateMahameruDts)((0,c.join)(e,"mahameru.d.ts"))
|
|
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 P=null;try{P=JSON.parse(v),P.compilerOptions.outDir=".mahameru",P.compilerOptions.rootDir="src",await(0,
|
|
24
|
+
i.writeFile)(a,JSON.stringify(P,null,2))}catch(e){console.error(`Error parsing ${l}: ${e}`),process.exit(1)}
|
|
25
|
+
const w=await(0,u.runNodeScript)(g,["--project",n],e);0!==w&&(r.fail(s.default.red(" Build failed!")),await(0,
|
|
26
|
+
d.deleteDirIfExists)(o),process.exit(w));const S=await(0,u.runNodeScript)(y,["--project",n],e)
|
|
27
|
+
;0!==S&&(r.fail(s.default.red(" tsc-alias failed.")),await(0,d.deleteDirIfExists)(o),process.exit(S));const $=(0,
|
|
28
|
+
p.findUnresolvedAliases)(o);if($.length>0){r.fail(s.default.red(" Build produced unresolved path aliases.")),
|
|
29
|
+
console.error(s.default.yellow("Please use tsconfig path aliases such as @/* and avoid package.json imports for app source files."))
|
|
30
|
+
;for(const e of $)console.error(s.default.red(` - ${e}`));process.exit(1)}await(0,d.deleteDirIfExists)(a),await(0,
|
|
31
|
+
d.deleteDirIfExists)((0,c.join)(o,"types"));try{
|
|
32
|
+
const t=await(0,i.readFile)((0,c.join)(e,"package.json"),"utf-8"),r=JSON.parse(t)
|
|
33
|
+
;r.devDependencies&&delete r.devDependencies,await(0,i.writeFile)((0,c.join)(o,"package.json"),JSON.stringify(r,null,2))
|
|
34
|
+
}catch{}const M=(0,c.join)(e,".env"),_=(0,c.join)(e,".env.development"),j=(0,c.join)(e,".env.production");(0,
|
|
35
|
+
m.existsSync)(M)&&await(0,i.copyFile)(M,(0,c.join)(o,".env")),(0,m.existsSync)(j)?await(0,i.copyFile)(j,(0,
|
|
36
|
+
c.join)(o,".env.production")):(0,m.existsSync)(_)&&await(0,i.copyFile)(_,(0,c.join)(o,".env.production")),await(0,
|
|
37
|
+
h.createZip)((0,c.join)(process.cwd(),t),(0,c.join)(process.cwd(),`${t}.zip`),!1),
|
|
38
|
+
r.succeed(s.default.green(" Build success."))}catch(e){r.fail(s.default.red(" Internal error.")),console.error(e),
|
|
30
39
|
process.exit(1)}}}
|
|
31
|
-
;const
|
|
32
|
-
},7022(e,t,o){t.dev=function({version:e}){return async({host:t,port:o})=>{const
|
|
33
|
-
|
|
34
|
-
port:o})}};const r=o(7209),
|
|
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,n.ensureDevEnvironment)();(0,
|
|
42
|
+
s.printCliBanner)(e),o=await(0,r.freePortFinder)(o),await(0,a.startWatchedDevServer)({version:e,environment:i,host:t,
|
|
43
|
+
port:o})}};const r=o(7209),n=o(242),s=o(1785),a=o(8320)},3674(e,t,o){var r=this&&this.__importDefault||function(e){
|
|
35
44
|
return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.install=void 0
|
|
36
|
-
;const
|
|
37
|
-
;t.install=e=>({host:t,port:o,cert:r,key:
|
|
38
|
-
;try{
|
|
39
|
-
|
|
40
|
-
if(!(0,
|
|
41
|
-
;if(
|
|
45
|
+
;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
|
+
;t.install=e=>({host:t,port:o,cert:r,key:f})=>{const m="linux"===process.platform,h="win32"===process.platform;let g=""
|
|
47
|
+
;try{g=(0,l.getNodeModulesPath)()}catch(e){return void console.error(a.default.red(`❌ ${e.message}`))}const y=(0,
|
|
48
|
+
i.join)(g,"@mahameru","cli");try{
|
|
49
|
+
if(!(0,s.existsSync)(y))throw new Error("Mahameru is not installed on your system.\nPlease install it by running: `npm install -g @mahameru/cli`")
|
|
50
|
+
;if(m){
|
|
42
51
|
if(process.getuid&&0!==process.getuid())throw new Error("This action requires root privileges. Please run with sudo.")
|
|
43
|
-
;let c="";try{c=(0,
|
|
52
|
+
;let c="";try{c=(0,n.execSync)("which mahameru",{stdio:["ignore","pipe","ignore"]}).toString().trim()}catch{
|
|
44
53
|
throw new Error('Executable "mahameru" not found in PATH. Make sure it is installed globally.')}
|
|
45
54
|
!function({serviceName:e,appPath:t,mahameruInstalationPath:o,host:r,port:c,cert:l,key:u}){
|
|
46
55
|
const p=`/etc/systemd/system/${e}.service`;try{
|
|
47
|
-
if((0,
|
|
48
|
-
;(0,
|
|
56
|
+
if((0,s.existsSync)(p))throw new Error(`Service "${e}" is already registered on this system. Please run uninstall command first if you want to update it.`)
|
|
57
|
+
;(0,s.mkdirSync)((0,i.join)(o,"logs"),{recursive:!0});const f=process.execPath,m=`[Unit]\nDescription=${(0,
|
|
49
58
|
d.toTitleCase)(e)}\nAfter=network.target\n\n[Service]\nType=simple\nUser=root\nWorkingDirectory=${o}\nExecStart=${f} ${t} pm start -d${r?` --host ${r}`:""}${c?` --port ${c}`:""}${l?` --cert ${l}`:""}${u?` --key ${u}`:""}\nRestart=always\nEnvironment=NODE_ENV=production\nStandardOutput=append:${o}/logs/out.log\nStandardError=append:${o}/logs/error.log\n\n[Install]\nWantedBy=multi-user.target\n`
|
|
50
|
-
;console.log(
|
|
51
|
-
console.log(
|
|
52
|
-
|
|
53
|
-
}catch{}(0,
|
|
59
|
+
;console.log(a.default.cyan(`⏳ Writing service configuration to ${p}...`)),(0,s.writeFileSync)(p,m),
|
|
60
|
+
console.log(a.default.cyan("🔄 Reloading systemd daemon & enabling service...")),(0,
|
|
61
|
+
n.execSync)("systemctl daemon-reload"),(0,n.execSync)(`systemctl enable ${e}`);try{(0,n.execSync)(`systemctl stop ${e}`)
|
|
62
|
+
}catch{}(0,n.execSync)(`systemctl start ${e}`),console.log(a.default.green(`\n🚀 ${(0,
|
|
54
63
|
d.toTitleCase)(e)} successfully registered as a service!`)),
|
|
55
64
|
console.log(`🌍 Mahameru Process Manager running at ${l&&u?"https":"http"}://${r}:${c}`),
|
|
56
|
-
console.log(`📝 To check service status, run: ${
|
|
57
|
-
console.error(
|
|
58
|
-
mahameruInstalationPath:
|
|
65
|
+
console.log(`📝 To check service status, run: ${a.default.bold("mahameru pm service status")}`)}catch(e){
|
|
66
|
+
console.error(a.default.red("❌ Failed to register service:"),e.message)}}({serviceName:e,appPath:c,
|
|
67
|
+
mahameruInstalationPath:y,host:t,port:o,cert:r,key:f})}else if(h){let l="";try{l=(0,n.execSync)("where mahameru",{
|
|
59
68
|
stdio:["ignore","pipe","ignore"]}).toString().trim(),l.includes("\n")&&(l=l.split(/\r?\n/)[0]),
|
|
60
|
-
async function({serviceName:e,appPath:t,host:o,port:r,cert:l,key:
|
|
69
|
+
async function({serviceName:e,appPath:t,host:o,port:r,cert:l,key:f}){const m=(0,
|
|
61
70
|
u.default)(`Installing ${e} service...`).start();try{t+=".cmd"
|
|
62
|
-
;const u=(0,
|
|
63
|
-
|
|
71
|
+
;const u=(0,i.join)(c.APPDATA_PATH,"winsw",`${e}.exe`),h=(0,i.join)(c.APPDATA_PATH,"winsw",`${e}.xml`);if(await(0,
|
|
72
|
+
p.mkdir)((0,i.dirname)(u),{recursive:!0}),!(0,s.existsSync)(u)){m.text="Downloading assets..."
|
|
64
73
|
;const e="https://github.com/winsw/winsw/releases/download/v2.12.0/WinSW-x64.exe",t=await fetch(e,{method:"GET",
|
|
65
74
|
headers:{Accept:"*/*",
|
|
66
75
|
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36"
|
|
67
76
|
}});if(!t.ok)throw new Error(`Failed to download WinSW from ${e}. Status code: ${t.status}`)
|
|
68
|
-
;const o=await t.arrayBuffer();(0,
|
|
69
|
-
const
|
|
77
|
+
;const o=await t.arrayBuffer();(0,s.writeFileSync)(u,Buffer.from(o)),m.succeed("Downloading WinSW binary... Done")}
|
|
78
|
+
const g=`pm start -d${o?` --host ${o}`:""}${r?` --port ${r}`:""} ${l?` --cert ${l}`:""}${f?` --key ${f}`:""}`,y=`<service>\n <id>mahameru-pm</id>\n <name>${(0,
|
|
70
79
|
d.toTitleCase)(e)}</name>\n <description>${(0,
|
|
71
|
-
d.toTitleCase)(e)}</description>\n <executable>cmd.exe</executable>\n <arguments>/c "${t}" ${
|
|
80
|
+
d.toTitleCase)(e)}</description>\n <executable>cmd.exe</executable>\n <arguments>/c "${t}" ${g}</arguments>\n <log mode="roll"></log>\n </service>`
|
|
72
81
|
;(0,
|
|
73
|
-
|
|
74
|
-
cwd:c.APPDATA_PATH}),
|
|
75
|
-
console.log(`🌍 ${(0,d.toTitleCase)(e)} running at ${l&&
|
|
76
|
-
console.log(`📝 To check service status, run:\n - ${
|
|
77
|
-
console.error(
|
|
78
|
-
|
|
79
|
-
key:
|
|
80
|
-
console.error(
|
|
81
|
-
;t.pm=e=>async({host:t,port:o,daemon:
|
|
82
|
+
s.writeFileSync)(h,y,"utf8"),m.text="Registering windows service...",(0,n.execSync)(`"${u}" install && "${u}" start`,{
|
|
83
|
+
cwd:c.APPDATA_PATH}),m.succeed(`\n🚀 ${(0,d.toTitleCase)(e)} successfully registered as a service!`),
|
|
84
|
+
console.log(`🌍 ${(0,d.toTitleCase)(e)} running at ${l&&f?"https":"http"}://${o}:${r}`),
|
|
85
|
+
console.log(`📝 To check service status, run:\n - ${a.default.bold("mahameru pm service status")}`)}catch(e){
|
|
86
|
+
console.error(a.default.red(`❌ Error: ${e.message}`)),
|
|
87
|
+
m.fail("Make sure you are running CMD/PowerShell as an Administrator.")}}({serviceName:e,appPath:l,host:t,port:o,cert:r,
|
|
88
|
+
key:f})}catch{throw new Error('Executable "mahameru" not found in PATH.')}}}catch(e){
|
|
89
|
+
console.error(a.default.red(`❌ Error: ${e.message}`))}}},6478(e,t,o){t.pm=void 0;const r=o(5043)
|
|
90
|
+
;t.pm=e=>async({host:t,port:o,daemon:n,cert:s,key:a})=>await(0,r.processManager)({host:t,port:o,daemon:n,cert:s,key:a
|
|
82
91
|
},e)},1205(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
83
|
-
;Object.defineProperty(t,"__esModule",{value:!0}),t.App=void 0
|
|
84
|
-
;t.App=class{initialized=!1;options;worker;appEnv
|
|
85
|
-
this.appEnv=this.buildAppEnv(),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
;Object.defineProperty(t,"__esModule",{value:!0}),t.App=void 0
|
|
93
|
+
;const n=r(o(139)),s=o(8235),a=r(o(5205)),i=o(3024),c=o(6760);t.App=class{initialized=!1;options;worker;appEnv
|
|
94
|
+
;handleOnExit;constructor(e){this.options=e,this.appEnv=this.buildAppEnv();const t=(0,
|
|
95
|
+
c.join)(this.options.rootPath,"node_modules","mahameru","server.js")
|
|
96
|
+
;if(!(0,i.existsSync)(t))throw new Error("Cannot find Mahameru worker.");n.default.setupPrimary({exec:t,
|
|
97
|
+
cwd:this.options.rootPath,stdio:["inherit","inherit","inherit","ipc"]})}async start(){
|
|
98
|
+
if(this.initialized)throw new Error("App has already been started.");this.worker=n.default.fork(this.appEnv),
|
|
89
99
|
this.initialized=!0,this.setupListeners()}stop(){return new Promise(e=>{
|
|
90
100
|
if(!this.worker||this.worker.isDead()||!this.initialized)return this.initialized=!1,void e()
|
|
91
101
|
;this.handleOnExit&&this.worker.removeListener("exit",this.handleOnExit);let t=null;this.worker.once("message",o=>{
|
|
92
102
|
"SHUTDOWN_DONE"===o.type&&(t&&clearTimeout(t),this.initialized=!1,this.worker=void 0,e())}),this.worker.send({
|
|
93
103
|
type:"SHUTDOWN"
|
|
94
104
|
}),void 0!==this.options.gracefulShutdownTimeout&&this.options.gracefulShutdownTimeout>0&&(t=setTimeout(()=>{
|
|
95
|
-
this.worker&&!this.worker.isDead()&&(console.warn(
|
|
105
|
+
this.worker&&!this.worker.isDead()&&(console.warn(a.default.yellow("[Mahameru] Graceful shutdown timed out, killing worker.")),
|
|
96
106
|
this.worker.disconnect(),this.worker.kill(),e())},this.options.gracefulShutdownTimeout))})}async devHRM(e){
|
|
97
|
-
this.worker&&this.worker.send({type:"DEV_HRM",data:{changedFile:e}})}
|
|
98
|
-
this.
|
|
99
|
-
type:"GENERATE_ROUTE_TYPES"})):t(new Error("Worker is not initialized."))})}setupListeners(){if(!this.worker)return
|
|
100
|
-
;const e=this.options.onMessage?this.options.onMessage:e=>{switch(e.type){case"READY":(0,n.printServerReady)({
|
|
107
|
+
this.worker&&this.worker.send({type:"DEV_HRM",data:{changedFile:e}})}setupListeners(){if(!this.worker)return
|
|
108
|
+
;const e=this.options.onMessage?this.options.onMessage:e=>{switch(e.type){case"READY":(0,s.printServerReady)({
|
|
101
109
|
dev:this.options.dev??!1,mode:this.options.dev?"development":"production",host:e.data?.host??"localhost",
|
|
102
110
|
port:e.data?.port??3e3});break;case"ERROR":
|
|
103
|
-
console.error(
|
|
111
|
+
console.error(a.default.red("\n[Mahameru]"),e.data.message,e.data.stack??"",e.data.code??"");break;case"LOG":
|
|
104
112
|
console.log(e.data)}},t=this.options.onError?this.options.onError:e=>console.error(e)
|
|
105
113
|
;this.handleOnExit=this.options.onExit?this.options.onExit:e=>{
|
|
106
|
-
console.error(
|
|
114
|
+
console.error(a.default.red(`[Mahameru] Dev server exited with code ${Number(e)}.`)),0!==e&&process.exit(e)},
|
|
107
115
|
this.worker.on("message",e),this.worker.on("error",t),this.worker.on("exit",this.handleOnExit)}buildAppEnv(){return{
|
|
108
116
|
MAHAMERU__ROOT_PATH:this.options.rootPath,...this.options.dev?{MAHAMERU__MODE:"development"}:{
|
|
109
|
-
MAHAMERU__MODE:"production"},...this.options.
|
|
110
|
-
|
|
111
|
-
MAHAMERU__HTTP_LISTEN_PORT:this.options.port.toString().trim()}:{}}}}},760(e,t,o){t.buildConfigJson=async function(){
|
|
112
|
-
const e=(0,
|
|
113
|
-
r.createRequire)(__filename),{mahameruDefaultConfig:t}=e((0,n.join)(process.cwd(),"node_modules","mahameru","dist","mahameru.js")),o=e((0,
|
|
114
|
-
n.join)(process.cwd(),"mahameru.config.ts")).default,i=await o(t),a=JSON.stringify(i),c=(0,
|
|
115
|
-
n.join)(process.cwd(),".mahameru",".mahameru.config.json");return await(0,s.mkdir)((0,n.dirname)(c),{recursive:!0}),
|
|
116
|
-
await(0,s.writeFile)(c,a,"utf-8"),o};const r=o(3339),s=o(1455),n=o(6760)},242(e,t,o){
|
|
117
|
+
MAHAMERU__MODE:"production"},...this.options.host?{MAHAMERU__HTTP_LISTEN_HOST:this.options.host.trim()}:{},
|
|
118
|
+
...this.options.port?{MAHAMERU__HTTP_LISTEN_PORT:this.options.port.toString().trim()}:{}}}}},242(e,t,o){
|
|
117
119
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
118
120
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.ensureDevEnvironment=function(){const e=process.cwd(),t=(0,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
;(0,
|
|
123
|
-
process.exit(1));(0,
|
|
124
|
-
console.error(
|
|
125
|
-
|
|
126
|
-
console.error(
|
|
127
|
-
|
|
128
|
-
console.error(
|
|
129
|
-
rootPath:e,tsxJsPath:t,tscJsPath:r,tscAliasJsPath:o}};const
|
|
121
|
+
s.join)(__dirname,"node_modules","tsx","dist","cli.mjs"),o=(0,
|
|
122
|
+
s.join)(__dirname,"node_modules","tsc-alias","dist","bin","index.js"),r=(0,
|
|
123
|
+
s.join)(e,"node_modules","typescript","bin","tsc")
|
|
124
|
+
;(0,i.isMahameruProjectDir)(e)||(console.error(n.default.red("Current directory is not a MahameruJs project.")),
|
|
125
|
+
process.exit(1));(0,a.existsSync)(t)||(console.error(n.default.red("Error: Runner 'tsx' is not installed.")),
|
|
126
|
+
console.error(n.default.yellow("Please install it by running: npm install -D tsx")),process.exit(1));(0,
|
|
127
|
+
a.existsSync)(o)||(console.error(n.default.red("Error: tsc-alias not installed.")),
|
|
128
|
+
console.error(n.default.yellow("Please install it by running: npm install -D tsc-alias")),process.exit(1));(0,
|
|
129
|
+
a.existsSync)(r)||(console.error(n.default.red("Error: TypeScript compiler (tsc) is not installed in this project.")),
|
|
130
|
+
console.error(n.default.yellow("Please install it by running: npm install -D typescript")),process.exit(1));return{
|
|
131
|
+
rootPath:e,tsxJsPath:t,tscJsPath:r,tscAliasJsPath:o}};const n=r(o(5205)),s=o(6760),a=o(3024),i=o(4813)},5242(e,t,o){
|
|
130
132
|
t.findUnresolvedAliases=function(e){if(!(0,r.existsSync)(e))return[];const t=[e],o=new Set;for(;t.length>0;){
|
|
131
|
-
const e=t.pop();for(const
|
|
132
|
-
t.push(
|
|
133
|
-
;(
|
|
134
|
-
t.generateRouteTypes=async function(e,t){const o=[];await async function e(t,
|
|
135
|
-
;const
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
;
|
|
139
|
-
|
|
140
|
-
s.
|
|
141
|
-
|
|
142
|
-
|
|
133
|
+
const e=t.pop();for(const s of(0,r.readdirSync)(e)){const a=(0,n.join)(e,s);if((0,r.statSync)(a).isDirectory()){
|
|
134
|
+
t.push(a);continue}if(!a.endsWith(".js"))continue;const i=(0,r.readFileSync)(a,"utf8")
|
|
135
|
+
;(i.includes("'@/")||i.includes('"@/'))&&o.add(a)}}return[...o]};const r=o(3024),n=o(6760)},1855(e,t,o){
|
|
136
|
+
t.generateRouteTypes=async function(e,t){const o=[];await async function e(t,a=""){if(!(0,r.existsSync)(t))return
|
|
137
|
+
;const i=await(0,n.readdir)(t);for(const r of i){const i=(0,s.join)(t,r);(await(0,
|
|
138
|
+
n.stat)(i)).isDirectory()?await e(i,`${a}/${r}`):"route.ts"!==r&&"route.js"!==r||o.push(""===a?"/":a)}}(e)
|
|
139
|
+
;const a=`// Do not edit this file, it is generated by MahameruJS\n\nimport { RouteObject } from 'mahameru';\n\ntype MahameruGeneratedRoutes = ${o.map(e=>`'${e}'`).join(" | ")||"string"};\n\ndeclare module 'mahameru' {\n\texport interface RegisterRoutes {\n\t\troutes: MahameruGeneratedRoutes | RouteObject<MahameruGeneratedRoutes>;\n\t}\n}\n`
|
|
140
|
+
;await(0,n.mkdir)((0,s.dirname)(t),{recursive:!0}),await(0,n.writeFile)(t,a.trim(),"utf-8")},
|
|
141
|
+
t.generateDataSourceTypes=async function(e,t){const o=[];if((0,r.existsSync)(e)){const t=await(0,n.readdir)(e)
|
|
142
|
+
;for(const r of t){const t=(0,s.join)(e,r);(await(0,n.stat)(t)).isDirectory()&&o.push(r)}}
|
|
143
|
+
const a=o.length>0?`// Do not edit this file, it is generated by MahameruJS\n\nimport type { DataSource } from "typeorm";\n\ndeclare module 'mahameru' {\n\texport interface DataSources {\n${o.map(e=>`\t\t${e}: DataSource;`).join("\n")}\n\t}\n\n\texport interface PreInitContext {\n\t\tdataSources: DataSources;\n\t}\n}\n`:"// Do not edit this file, it is generated by MahameruJS\n\ndeclare module 'mahameru' {}\n"
|
|
144
|
+
;await(0,n.mkdir)((0,s.dirname)(t),{recursive:!0}),await(0,n.writeFile)(t,a.trim(),"utf-8")},
|
|
145
|
+
t.generateTypesBarrel=async function(e){await(0,n.mkdir)((0,s.dirname)(e),{recursive:!0}),await(0,
|
|
146
|
+
n.writeFile)(e,"export * from './dataSources';\nexport * from './routes';\n","utf-8")},
|
|
147
|
+
t.generateMahameruDts=async function(e){
|
|
148
|
+
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
|
+
};const r=o(3024),n=o(1455),s=o(6760)},1785(e,t,o){var r=this&&this.__importDefault||function(e){
|
|
143
150
|
return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.printCliBanner=function(e){
|
|
144
|
-
console.log(`${
|
|
151
|
+
console.log(`${n.default.bold(n.default.cyan("▲ Mahameru"))} ${n.default.dim(`CLI v${e}`)}\n`)};const n=r(o(5205))},
|
|
145
152
|
8235(e,t){t.printServerReady=function({mode:e,dev:t,host:o,port:r}){console.log("[32m Mahameru Server Ready![0m"),
|
|
146
153
|
console.log(` [1mMode:[22m [36m${e}[0m`),console.log(` [1mLocal:[22m [36mhttp://${o}:${r}[0m`),
|
|
147
154
|
console.log(` [1mHost:[22m ${o}`),console.log(` [1mPort:[22m ${r}\n`),
|
|
148
155
|
console.log("[90mPress Ctrl+C to stop the server[0m\n")}},5412(e,t,o){t.runNodeScript=function(e,t,o){
|
|
149
|
-
return new Promise((s
|
|
150
|
-
;
|
|
156
|
+
return new Promise((n,s)=>{const a=(0,r.spawn)(process.execPath,[e,...t],{stdio:"inherit",cwd:o})
|
|
157
|
+
;a.on("message",e=>console.log(e)),a.on("close",e=>n(e??1)),a.on("error",s)})};const r=o(1421)},8320(e,t,o){
|
|
151
158
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
152
159
|
;Object.defineProperty(t,"__esModule",{value:!0
|
|
153
160
|
}),t.startWatchedDevServer=async function({environment:e,host:t,port:o,version:r}){
|
|
154
|
-
let
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
i.join)(m,"node_modules","typescript")),{createWatchCompilerHost:d,createWatchProgram:u,formatDiagnosticsWithColorAndContext:p,formatDiagnostic:P,sys:S,createEmitAndSemanticDiagnosticsBuilderProgram:M}=f(l),E={
|
|
164
|
-
getCanonicalFileName:e=>e,getCurrentDirectory:()=>m,getNewLine:()=>S.newLine};let j=!1,x=!1,T=0
|
|
165
|
-
;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
|
|
166
|
-
},S,M,e=>{x=!0;const t=e.file?p([e],E):P(e,E);process.stderr.write(t.endsWith("\n")?t:`${t}\n`)},e=>{
|
|
161
|
+
let $,M=null,_=!1,j=null,x=!1,E=!0,T=!1,A=0;const b=new Set,D=new Set;await(0,s.mkdir)(f,{recursive:!0});const O=(0,
|
|
162
|
+
i.default)({text:`${c.default.cyan("[Mahameru]")} Starting TypeScript watch...`,spinner:"triangle"}).start(),R={dev:!0,
|
|
163
|
+
host:t,port:o,rootPath:p}
|
|
164
|
+
;$=new d.App(R),M=await async function({environment:e,spinner:t,onBuildStart:o,onBuildSuccess:r,onBuildFailure:i}){
|
|
165
|
+
const l=(0,
|
|
166
|
+
a.resolve)((0,a.join)(p,"node_modules","typescript")),{createWatchCompilerHost:d,createWatchProgram:y,formatDiagnosticsWithColorAndContext:P,formatDiagnostic:$,sys:M,createEmitAndSemanticDiagnosticsBuilderProgram:_}=u(l),j={
|
|
167
|
+
getCanonicalFileName:e=>e,getCurrentDirectory:()=>p,getNewLine:()=>M.newLine};let x=!1,E=!1,T=0
|
|
168
|
+
;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(g,{rootDir:h,outDir:f
|
|
169
|
+
},M,_,e=>{E=!0;const t=e.file?P([e],j):$(e,j);process.stderr.write(t.endsWith("\n")?t:`${t}\n`)},e=>{
|
|
167
170
|
const t=e.messageText.toString().trim();(function(e){
|
|
168
171
|
return e.includes("Starting compilation in watch mode...")||e.includes("File change detected. Starting incremental compilation...")
|
|
169
|
-
})(t)&&(T+=1,A.set(T,Date.now()),b.set(T,{emittedRuntimeFiles:new Set,changedRuntimeSourceFiles:new Set}),
|
|
172
|
+
})(t)&&(T+=1,A.set(T,Date.now()),b.set(T,{emittedRuntimeFiles:new Set,changedRuntimeSourceFiles:new Set}),E=!1,o()),
|
|
170
173
|
function(e){
|
|
171
174
|
return["Starting compilation in watch mode...","File change detected. Starting incremental compilation...","Found 0 errors. Watching for file changes.","Watching for file changes."].some(t=>e.includes(t))
|
|
172
|
-
}(t)||console.log(`${c.default.yellow("[Mahameru TSC]")} ${t}`)}),N
|
|
173
|
-
const t
|
|
174
|
-
;
|
|
175
|
-
;H&&(C.watchDirectory=(e,t,o,r)=>
|
|
176
|
-
;W.writeFile=(e,t,o,r,s
|
|
175
|
+
}(t)||console.log(`${c.default.yellow("[Mahameru TSC]")} ${t}`)}),N=w((0,a.resolve)((0,a.join)(f,"types"))),F=e=>{
|
|
176
|
+
const t=w((0,a.resolve)(e));return t===N||t.startsWith(`${N}/`)},I=C.watchFile?.bind(C)
|
|
177
|
+
;I&&(C.watchFile=(e,t,o,r)=>F(e)?{close(){}}:I(e,t,o,r));const H=C.watchDirectory?.bind(C)
|
|
178
|
+
;H&&(C.watchDirectory=(e,t,o,r)=>F(e)?{close(){}}:H(e,t,o,r));const W=C,J=W.writeFile?.bind(W)??M.writeFile.bind(M)
|
|
179
|
+
;W.writeFile=(e,t,o,r,n,s)=>{J?.(e,t,o,r,n,s),q(e,n)};const U=C.afterProgramCreate;C.afterProgramCreate=e=>{U?.(e)
|
|
177
180
|
;const t=0===T?1:T;T=t,R=R.then(()=>B(e,t)).catch(e=>{
|
|
178
|
-
console.error(c.default.red("[Mahameru Dev] Build lifecycle failed.")),console.error(e)})};const L=
|
|
181
|
+
console.error(c.default.red("[Mahameru Dev] Build lifecycle failed.")),console.error(e)})};const L=y(C)
|
|
179
182
|
;async function B(e,o){const l=A.get(o)??Date.now(),d=b.get(o)??{emittedRuntimeFiles:new Set,
|
|
180
183
|
changedRuntimeSourceFiles:new Set}
|
|
181
|
-
;if(
|
|
182
|
-
O(new Error("Initial TypeScript build failed."))),b.delete(o),A.delete(o),void
|
|
183
|
-
if(0===e.length)return;const t=await async function(){if(!
|
|
184
|
-
|
|
185
|
-
})}return
|
|
186
|
-
fileContents:e,filePath:o});r!==e&&await(0,
|
|
187
|
-
await async function(e=3e4){const t=Date.now();for(;Date.now()-t<e;){if((0,
|
|
188
|
-
;await
|
|
189
|
-
|
|
190
|
-
return console.error(c.default.red("[Mahameru Alias] Alias rewrite failed.")),console.error(e),
|
|
184
|
+
;if(E)return x||(x=!0,t.fail(`${c.default.red("[Mahameru]")} Initial TypeScript build failed.`),
|
|
185
|
+
O(new Error("Initial TypeScript build failed."))),b.delete(o),A.delete(o),void i();try{if(x)await async function(e){
|
|
186
|
+
if(0===e.length)return;const t=await async function(){if(!v){const e=(0,a.resolve)((0,
|
|
187
|
+
a.join)(__dirname,"node_modules","tsc-alias")),{prepareSingleFileReplaceTscAliasPaths:t}=u(e);v=t({configFile:g,outDir:f
|
|
188
|
+
})}return v}();for(const o of e){if(!(0,n.existsSync)(o))continue;const e=await(0,s.readFile)(o,"utf8"),r=t({
|
|
189
|
+
fileContents:e,filePath:o});r!==e&&await(0,s.writeFile)(o,r)}}([...d.emittedRuntimeFiles]);else{
|
|
190
|
+
await async function(e=3e4){const t=Date.now();for(;Date.now()-t<e;){if((0,n.existsSync)(m))return void await S(200)
|
|
191
|
+
;await S(100)}throw new Error("Timed out waiting for emitted dev runtime artifacts.")}();const e=(0,a.resolve)((0,
|
|
192
|
+
a.join)(__dirname,"node_modules","tsc-alias")),{replaceTscAliasPaths:t}=u(e);await t({configFile:g,outDir:f})}}catch(e){
|
|
193
|
+
return console.error(c.default.red("[Mahameru Alias] Alias rewrite failed.")),console.error(e),x||(x=!0,
|
|
191
194
|
t.fail(`${c.default.red("[Mahameru]")} Initial alias rewrite failed.`),O(e instanceof Error?e:new Error(String(e)))),
|
|
192
|
-
b.delete(o),A.delete(o),void
|
|
195
|
+
b.delete(o),A.delete(o),void i()}const p=Date.now()-l;try{await r({durationMs:p,
|
|
193
196
|
emittedRuntimeFiles:[...d.emittedRuntimeFiles],changedRuntimeSourceFiles:[...d.changedRuntimeSourceFiles],
|
|
194
|
-
initialBuild:!
|
|
195
|
-
console.error(e),void
|
|
196
|
-
|
|
197
|
-
;return e.startsWith(t)&&e.endsWith(".js")&&!e.endsWith(".d.ts")&&!e.endsWith(".map")}(r)){
|
|
198
|
-
;for(const e of function(e){if(!e)return[];const t=`${
|
|
199
|
-
|
|
200
|
-
}(t))
|
|
201
|
-
onBuildStart:()=>{
|
|
202
|
-
onBuildSuccess:({durationMs:e,emittedRuntimeFiles:t,changedRuntimeSourceFiles:o,initialBuild:r})=>{if(
|
|
203
|
-
for(const e of t)
|
|
204
|
-
|
|
205
|
-
}),
|
|
206
|
-
;const
|
|
207
|
-
j=setTimeout(()=>{
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
await
|
|
211
|
-
;const
|
|
212
|
-
;const l=Date.now()-
|
|
213
|
-
|
|
197
|
+
initialBuild:!x})}catch(e){return console.error(c.default.red("[Mahameru Alias] Alias rewrite failed.")),
|
|
198
|
+
console.error(e),void i()}finally{b.delete(o),A.delete(o)}x||(x=!0,D())}function q(e,t){const o=(0,
|
|
199
|
+
a.resolve)(e),r=w(o),n=b.get(T);if(n&&function(e){const t=`${w((0,a.resolve)(m))}/`
|
|
200
|
+
;return e.startsWith(t)&&e.endsWith(".js")&&!e.endsWith(".d.ts")&&!e.endsWith(".map")}(r)){n.emittedRuntimeFiles.add(o)
|
|
201
|
+
;for(const e of function(e){if(!e)return[];const t=`${w((0,a.resolve)(h))}/`;return e.map(e=>(0,
|
|
202
|
+
a.resolve)(e.fileName)).filter(e=>{const o=w(e);return o.startsWith(t)&&o.endsWith(".ts")&&!o.endsWith(".d.ts")})
|
|
203
|
+
}(t))n.changedRuntimeSourceFiles.add(e)}}try{return await k,L}catch(e){throw L.close(),e}}({environment:e,spinner:O,
|
|
204
|
+
onBuildStart:()=>{E=!0},
|
|
205
|
+
onBuildSuccess:({durationMs:e,emittedRuntimeFiles:t,changedRuntimeSourceFiles:o,initialBuild:r})=>{if(A=e,E=!1,!r){
|
|
206
|
+
for(const e of t)b.add(e);for(const e of o)D.add(e)}E||!$?.initialized||_||(x||T||0!==b.size)&&F()},onBuildFailure:()=>{
|
|
207
|
+
E=!1,A=0,T=!1,b.clear(),D.clear(),j&&(clearTimeout(j),j=null)}
|
|
208
|
+
}),O.succeed(`${c.default.green("[Mahameru]")} Initial build completed.\n`),await $.start()
|
|
209
|
+
;const k=new l.Watchman([f,y]),C=new l.Watchman(h);let N=Promise.resolve();const F=()=>{j&&clearTimeout(j),
|
|
210
|
+
j=setTimeout(()=>{N=N.then(async()=>{if(_||!$)return;if(E)return void F();const e=[...b],t=[...D],o=T,r=x;if(x=!1,T=!1,
|
|
211
|
+
b.clear(),
|
|
212
|
+
D.clear(),j=null,r)return console.log(c.default.yellow("\n [Mahameru] Config file changed. Reloading server...\n")),
|
|
213
|
+
await $.stop(),$=new d.App(R),console.clear(),void await $.start();if(0===e.length&&!o)return
|
|
214
|
+
;const n=e[e.length-1],s=t[t.length-1]??(n?P(n):(0,a.resolve)(h)),i=Date.now();o?await $.devHRM():await $.devHRM(n)
|
|
215
|
+
;const l=Date.now()-i,u=A+l;console.log(`${c.default.green("[Mahameru Dev]")} Rebuilt ${(0,
|
|
216
|
+
a.relative)(p,s).replace(/\\/g,"/")} build: ${A}ms runtime: ${l}ms total: ${u}ms`)}).catch(e=>{
|
|
214
217
|
console.error(c.default.red("[Mahameru Dev] Hot reload failed.")),console.error(e)})},250)}
|
|
215
|
-
;
|
|
216
|
-
|
|
217
|
-
;if(o.endsWith(".d.ts")||o.endsWith(".map")||o.endsWith(".tsbuildinfo"))return null;if(o===
|
|
218
|
-
;if(!o.endsWith(".js"))return null;if(o.startsWith(`${
|
|
219
|
-
;o&&("runtime"===o&&"delete"!==e&&"rename"!==e||((e,t)=>{"config"===e?x=!0:(
|
|
220
|
-
|
|
221
|
-
;(function(e){const t=`${
|
|
222
|
-
const t=(0,
|
|
223
|
-
const e=function(e){const t=(0,
|
|
224
|
-
;return void await Promise.all([(0,
|
|
225
|
-
|
|
226
|
-
}).catch(()=>{})])}await(0,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
process.once("SIGTERM",()=>{
|
|
230
|
-
;const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
;return(0,
|
|
218
|
+
;k.on("all",({event:e,filePath:t})=>{const o=function(e){const t=(0,a.resolve)(e),o=w(t),r=w((0,a.resolve)(f)),n=w((0,
|
|
219
|
+
a.resolve)(m)),s=w((0,a.resolve)(y));if(!o.startsWith(`${r}/`)&&o!==s)return null
|
|
220
|
+
;if(o.endsWith(".d.ts")||o.endsWith(".map")||o.endsWith(".tsbuildinfo"))return null;if(o===s)return"config"
|
|
221
|
+
;if(!o.endsWith(".js"))return null;if(o.startsWith(`${n}/`))return"runtime";return null}(t)
|
|
222
|
+
;o&&("runtime"===o&&"delete"!==e&&"rename"!==e||((e,t)=>{"config"===e?x=!0:(b.add(t),D.add(P(t))),E||F()})(o,t))}),
|
|
223
|
+
C.on("all",async({event:e,filePath:t,oldFilePath:o})=>{if("delete"!==e&&"rename"!==e)return;const r="rename"===e&&o?o:t
|
|
224
|
+
;(function(e){const t=`${w((0,a.resolve)(h))}/`;return w((0,a.resolve)(e)).startsWith(t)})(r)&&(await async function(e){
|
|
225
|
+
const t=(0,a.resolve)(e),o=(0,a.relative)(h,t);if(o.startsWith(".."))return;if(/\.[^\\/]+$/.test(o)){
|
|
226
|
+
const e=function(e){const t=(0,a.relative)(h,e);return(0,a.resolve)(m,t.replace(/\.ts$/i,".js"))}(t)
|
|
227
|
+
;return void await Promise.all([(0,s.rm)(e,{force:!0}).catch(()=>{}),(0,s.rm)(`${e}.map`,{force:!0}).catch(()=>{}),(0,
|
|
228
|
+
s.rm)(e.replace(/\.js$/i,".d.ts"),{force:!0}).catch(()=>{}),(0,s.rm)(e.replace(/\.js$/i,".d.ts.map"),{force:!0
|
|
229
|
+
}).catch(()=>{})])}await(0,s.rm)((0,a.resolve)(m,o),{recursive:!0,force:!0}).catch(()=>{})}(r),T=!0,D.add((0,
|
|
230
|
+
a.resolve)(r)),E||F())}),await k.start(),await C.start();const I=async(e=0)=>{_||(_=!0,j&&(clearTimeout(j),j=null),
|
|
231
|
+
k.stop(),C.stop(),await $.stop(),M?.close(),process.exit(e))};process.once("SIGINT",()=>{I(0)}),
|
|
232
|
+
process.once("SIGTERM",()=>{I(0)}),await new Promise(()=>{})}
|
|
233
|
+
;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=(0,
|
|
234
|
+
o(8995).createRequire)(__filename),p=process.cwd(),f=(0,a.join)(p,".mahameru"),m=f,h=(0,a.join)(p,"src"),g=(0,
|
|
235
|
+
a.join)(p,"tsconfig.json"),y=(0,a.join)(p,"mahameru.config.ts");let v=null;function P(e){const t=(0,a.relative)(m,e)
|
|
236
|
+
;return(0,a.resolve)(h,t.replace(/\.js$/i,".ts"))}function w(e){return e.replace(/\\/g,"/")}function S(e){
|
|
234
237
|
return new Promise(t=>{setTimeout(t,e)})}},5775(e,t,o){t.deleteDirIfExists=async function(e){return await(0,r.rm)(e,{
|
|
235
238
|
recursive:!0,force:!0})},t.parsePort=function(e){const t=parseInt(e,10);return isNaN(t)?void 0:t}
|
|
236
|
-
;const r=o(1455),
|
|
239
|
+
;const r=o(1455),n=o(8161)},6469(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{
|
|
237
240
|
default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Watchman=void 0
|
|
238
|
-
;const
|
|
241
|
+
;const n=o(6261),s=o(9896),a=o(1943),i=r(o(6928)),c=/[*?[\]{}]/;class l extends n.EventEmitter{targets
|
|
239
242
|
;abortControllers=[];renameBuffer=[];bufferTimeout=null;recentEvents=new Map;constructor(e){super()
|
|
240
243
|
;const t=Array.isArray(e)?e:[e];this.targets=t.map(e=>this.createTarget(e))}async start(){this.stop()
|
|
241
244
|
;const e=this.resolveWatchRoots();if(0!==e.length)for(const t of e){const e=new AbortController
|
|
242
|
-
;this.abortControllers.push(e);const{signal:o}=e;(async()=>{try{const e=(0,
|
|
245
|
+
;this.abortControllers.push(e);const{signal:o}=e;(async()=>{try{const e=(0,a.watch)(t.watchPath,{recursive:t.recursive,
|
|
243
246
|
signal:o});for await(const o of e){const{eventType:e,filename:r}=o;if(!r)continue
|
|
244
|
-
;const
|
|
245
|
-
;this.matchesTarget(
|
|
246
|
-
event:"change",filePath:
|
|
247
|
+
;const n=i.default.resolve(t.watchPath,r)
|
|
248
|
+
;this.matchesTarget(n)&&("change"!==e?"rename"===e&&this.handleRenameEvent(r,t.watchPath):this.emitEvent({
|
|
249
|
+
event:"change",filePath:n}))}}catch(e){
|
|
247
250
|
"AbortError"!==e.name&&console.error(`[Watchman] Watch error at ${t.watchPath}:`,e)}})()
|
|
248
251
|
}else console.warn("[Watchman] No files or directories matched the configured watch targets.")}stop(){
|
|
249
252
|
for(const e of this.abortControllers)e.abort();this.abortControllers=[],this.recentEvents.clear(),
|
|
250
253
|
this.bufferTimeout&&(clearTimeout(this.bufferTimeout),this.bufferTimeout=null),this.renameBuffer=[]}createTarget(e){
|
|
251
|
-
const t=this.normalizePath(e),o=
|
|
252
|
-
;return{original:e,normalized:t,absolute:o,kind:(0,
|
|
254
|
+
const t=this.normalizePath(e),o=i.default.resolve(e);if(c.test(t))return{original:e,normalized:t,absolute:o,kind:"glob"}
|
|
255
|
+
;return{original:e,normalized:t,absolute:o,kind:(0,s.existsSync)(o)&&(0,s.statSync)(o).isDirectory()?"directory":"file"}
|
|
253
256
|
}resolveWatchRoots(){const e=new Map;for(const t of this.targets){
|
|
254
|
-
const o="glob"===t.kind?this.getGlobBasePath(t.normalized):"directory"===t.kind?t.absolute:
|
|
255
|
-
;(0,
|
|
256
|
-
const t=this.normalizePath(
|
|
257
|
-
;return this.targets.some(e=>"directory"===e.kind?t===e.normalized||t.startsWith(`${e.normalized}/`):"file"===e.kind?t===e.normalized:
|
|
257
|
+
const o="glob"===t.kind?this.getGlobBasePath(t.normalized):"directory"===t.kind?t.absolute:i.default.dirname(t.absolute),r=i.default.resolve(o),n="file"!==t.kind,a=`${r}::${n}`
|
|
258
|
+
;(0,s.existsSync)(r)&&(e.has(a)||e.set(a,{watchPath:r,recursive:n}))}return Array.from(e.values())}matchesTarget(e){
|
|
259
|
+
const t=this.normalizePath(i.default.resolve(e))
|
|
260
|
+
;return this.targets.some(e=>"directory"===e.kind?t===e.normalized||t.startsWith(`${e.normalized}/`):"file"===e.kind?t===e.normalized:i.default.matchesGlob(t,e.normalized))
|
|
258
261
|
}emitEvent(e){this.shouldDeduplicate(e)||(this.emit(e.event,e),this.emit("all",e))}shouldDeduplicate(e){
|
|
259
|
-
const t=this.normalizePath(
|
|
262
|
+
const t=this.normalizePath(i.default.resolve(e.filePath)),o=`${e.event}:${t}:${e.oldFilePath?this.normalizePath(i.default.resolve(e.oldFilePath)):""}`,r=Date.now(),n=this.recentEvents.get(o)
|
|
260
263
|
;this.recentEvents.set(o,r);for(const[e,t]of this.recentEvents)r-t>80&&this.recentEvents.delete(e)
|
|
261
|
-
;return"number"==typeof
|
|
264
|
+
;return"number"==typeof n&&r-n<=80}handleRenameEvent(e,t){this.renameBuffer.push({filename:e,timestamp:Date.now(),
|
|
262
265
|
watcherRoot:t}),this.bufferTimeout&&clearTimeout(this.bufferTimeout),this.bufferTimeout=setTimeout(()=>{
|
|
263
266
|
this.processRenameBuffer(),this.renameBuffer=[]},20)}processRenameBuffer(){const e=this.renameBuffer.map(e=>({...e,
|
|
264
|
-
fullPath:
|
|
265
|
-
const[t,o]=e,r=(0,
|
|
266
|
-
event:"rename",oldFilePath:t.fullPath,filePath:o.fullPath});if(r&&!
|
|
267
|
-
oldFilePath:o.fullPath,filePath:t.fullPath})}for(const t of e)(0,
|
|
267
|
+
fullPath:i.default.resolve(e.watcherRoot,e.filename)})).filter(e=>this.matchesTarget(e.fullPath));if(2===e.length){
|
|
268
|
+
const[t,o]=e,r=(0,s.existsSync)(t.fullPath),n=(0,s.existsSync)(o.fullPath);if(!r&&n)return void this.emitEvent({
|
|
269
|
+
event:"rename",oldFilePath:t.fullPath,filePath:o.fullPath});if(r&&!n)return void this.emitEvent({event:"rename",
|
|
270
|
+
oldFilePath:o.fullPath,filePath:t.fullPath})}for(const t of e)(0,s.existsSync)(t.fullPath)?this.emitEvent({
|
|
268
271
|
event:"create",filePath:t.fullPath}):this.emitEvent({event:"delete",filePath:t.fullPath})}getGlobBasePath(e){
|
|
269
272
|
const t=e.split("/"),o=[];for(const e of t){if(c.test(e))break;o.push(e)}
|
|
270
|
-
return 0===o.length?
|
|
273
|
+
return 0===o.length?i.default.dirname(e):o.join("/")}normalizePath(e){return e.replace(/\\/g,"/")}}t.Watchman=l},
|
|
271
274
|
846(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
272
275
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.startFork=void 0
|
|
273
|
-
;const
|
|
276
|
+
;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)
|
|
274
277
|
;t.startFork=({rootPath:e})=>async t=>{const o=(0,d.getWindowsElevatedWorkingDirectory)()??e,r=t.port,p=t.host;(0,
|
|
275
|
-
|
|
278
|
+
a.isMahameruProjectDir)(o)||(console.error(s.default.red(`\n${o} is not a Mahameru project directory.`)),
|
|
276
279
|
process.exit(1));const f=await(0,l.getProjectJson)(o),m=(0,c.default)("Checking available port...").start(),h=await(0,
|
|
277
|
-
|
|
280
|
+
i.freePortFinder)(r);m.text="Connecting to MahameruJS PM Daemon...";const g=n.default.createConnection({
|
|
278
281
|
path:u.IPC_SOCKET_PATH},()=>{g.write(JSON.stringify({command:"FORK_PROJECT",payload:{name:f.name,
|
|
279
282
|
description:f.description,version:f.version,projectRoot:o,port:h,host:p}}))});g.on("data",e=>{
|
|
280
|
-
const t=JSON.parse(e.toString()),{success:o,message:r,data:
|
|
281
|
-
;o?(!function({name:e,version:t,mode:o,host:r,port:
|
|
282
|
-
const c=[`${
|
|
283
|
-
;
|
|
283
|
+
const t=JSON.parse(e.toString()),{success:o,message:r,data:n,mpmUrl:a}=t
|
|
284
|
+
;o?(!function({name:e,version:t,mode:o,host:r,port:n,pid:a,mpmUrl:i}){
|
|
285
|
+
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}`)}`]
|
|
286
|
+
;i&&c.push(`${s.default.bold("PM URL:")} ${s.default.cyan(i)}`),console.log(s.default.green("\n Project Started")),
|
|
284
287
|
c.forEach(e=>console.log(` ${e}`)),
|
|
285
|
-
console.log(`\n${
|
|
286
|
-
version:f.version,mode:"production",host:
|
|
287
|
-
m.succeed(
|
|
288
|
-
|
|
288
|
+
console.log(`\n${s.default.dim("Use `mahameru status` to inspect this managed project.")}\n`)}({name:f.name,
|
|
289
|
+
version:f.version,mode:"production",host:n.host,port:n.port,pid:n.pid,mpmUrl:a}),
|
|
290
|
+
m.succeed(s.default.green(`\n${r}`))):(m.fail(s.default.red("Failed to start project!")),console.error(t)),g.end(),
|
|
291
|
+
process.exit(0)}),g.on("error",e=>{
|
|
292
|
+
"ENOENT"===e.code||"ECONNREFUSED"===e.code?m.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){
|
|
289
293
|
if(!(0,d.hasWindowsElevationRetry)()&&!(0,d.isWindowsProcessElevated)()){
|
|
290
|
-
e.warn(
|
|
294
|
+
e.warn(s.default.yellow("\nWindows blocked access to the Mahameru PM pipe. Requesting Administrator approval..."))
|
|
291
295
|
;const o=(0,d.relaunchCurrentProcessAsAdmin)(t)
|
|
292
|
-
;o.ok&&(console.log(
|
|
293
|
-
console.log(
|
|
294
|
-
console.log(
|
|
296
|
+
;o.ok&&(console.log(s.default.cyan("An Administrator PowerShell window has been launched for the elevated retry.")),
|
|
297
|
+
console.log(s.default.dim(`The elevated retry will run from: ${t}`)),
|
|
298
|
+
console.log(s.default.dim("Keep that window open to see whether `mahameru start` succeeds or why it fails.")),
|
|
295
299
|
process.exit(0))
|
|
296
300
|
;const r="user-cancelled"===o.reason?"UAC request was cancelled.":"Unable to launch an elevated Mahameru process."
|
|
297
|
-
;e.fail(
|
|
298
|
-
o.errorText&&console.error(
|
|
299
|
-
e.fail(
|
|
300
|
-
console.log(
|
|
301
|
-
process.exit(1)}(m,o):(m.fail(
|
|
301
|
+
;e.fail(s.default.red(`\n${r}\nMahameru PM Daemon is likely running with Administrator privileges, so ${s.default.bold("mahameru start")} also needs admin approval to connect.`)),
|
|
302
|
+
o.errorText&&console.error(s.default.dim(o.errorText)),process.exit(1)}
|
|
303
|
+
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)}.`)),
|
|
304
|
+
console.log(s.default.dim("Check the visible Administrator PowerShell window for the detailed failure output.")),
|
|
305
|
+
process.exit(1)}(m,o):(m.fail(s.default.red(`\n${e.message}`)),console.error(e)),process.exit(1)})}},1471(e,t,o){
|
|
302
306
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
303
307
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.startService=void 0
|
|
304
|
-
;const
|
|
308
|
+
;const n=o(6921),s=o(1421),a=o(3024),i=o(6760),c=r(o(5205));t.startService=e=>()=>{
|
|
305
309
|
const t="linux"===process.platform,o="win32"===process.platform,r=`/etc/systemd/system/${e}.service`;try{if(t){
|
|
306
310
|
if(process.getuid&&0!==process.getuid())throw new Error("This action requires root privileges. Please run with sudo.")
|
|
307
311
|
;if(!(0,
|
|
308
|
-
|
|
312
|
+
a.existsSync)(r))throw new Error(`Service "${e}" is not registered on this system. Please run "mahameru pm service install" first.`)
|
|
309
313
|
;console.log(c.default.cyan(`🔍 Checking status for service: ${e}...`));let t=!1;try{"active"===(0,
|
|
310
|
-
|
|
314
|
+
s.execSync)(`systemctl is-active ${e}`,{stdio:["ignore","pipe","ignore"]}).toString().trim()&&(t=!0)}catch{t=!1}
|
|
311
315
|
t?console.log(c.default.yellow(`⚠️ Service "${e}" is already running.`)):(console.log(c.default.cyan(`🚀 Starting ${e}...`)),
|
|
312
|
-
(0,
|
|
316
|
+
(0,s.execSync)(`systemctl start ${e}`),console.log(c.default.green(`\n🚀 ${e} has been successfully started.`)),
|
|
313
317
|
console.log(`📝 To check service status, run: ${c.default.bold(`systemctl status ${e}`)}`))
|
|
314
318
|
}else o?function({serviceName:e}){try{console.log(`Attempting to start service: ${c.default.cyan(e)}...`);const t=(0,
|
|
315
|
-
|
|
316
|
-
cwd:
|
|
317
|
-
;console.log(c.default.yellow("WinSW binary not found. Falling back to sc.exe...")),(0,
|
|
319
|
+
i.join)(n.APPDATA_PATH," winsw",`${e}.exe`);if((0,a.existsSync)(t))return(0,s.execSync)(`"${t}" start`,{
|
|
320
|
+
cwd:n.APPDATA_PATH}),void console.log(c.default.green(`✔ Success: Service "${e}" has been started.`))
|
|
321
|
+
;console.log(c.default.yellow("WinSW binary not found. Falling back to sc.exe...")),(0,s.execSync)(`sc start "${e}"`),
|
|
318
322
|
console.log(c.default.green(`✔ Success: Service "${e}" has been started via sc.exe.`))}catch(e){
|
|
319
323
|
console.error(c.default.red(`❌ Error: Failed to start service: ${e.message}`)),
|
|
320
324
|
console.error("Make sure you are running CMD/PowerShell as an Administrator and the service is installed.")}}({
|
|
@@ -322,73 +326,73 @@ serviceName:e}):console.log(c.default.red("❌ Unsupported platform."))}catch(e)
|
|
|
322
326
|
console.error(c.default.red("❌ Failed to start service:"),e.message)}}},7695(e,t,o){
|
|
323
327
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
324
328
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.projectStatus=void 0
|
|
325
|
-
;const
|
|
329
|
+
;const n=r(o(7030)),s=o(4830),a=r(o(8720)),i=r(o(5205)),c=o(3157),l=o(6921)
|
|
326
330
|
;t.projectStatus=(e,t)=>async({host:o,port:r})=>{try{
|
|
327
|
-
console.log(`${
|
|
331
|
+
console.log(`${i.default.bold(i.default.cyan("▲ Mahameru"))} ${i.default.dim(`CLI v${t}`)}\n`);const o=(0,
|
|
328
332
|
c.getWindowsElevatedWorkingDirectory)()??e,r=await(0,
|
|
329
|
-
|
|
333
|
+
s.getProjectJson)(o),d=(0,a.default)("Checking available port...").start(),u=n.default.createConnection({
|
|
330
334
|
path:l.IPC_SOCKET_PATH},()=>{u.write(JSON.stringify({command:"STATUS",payload:{name:r.name}}))});u.on("data",e=>{
|
|
331
335
|
const{success:t,error:o,data:r}=JSON.parse(e.toString())
|
|
332
|
-
;t?(d.succeed(
|
|
333
|
-
const t=`http://${e.host}:${e.port}`,o="running"===e.status?
|
|
334
|
-
;console.log(
|
|
335
|
-
console.log(`\n${
|
|
336
|
+
;t?(d.succeed(i.default.green("\nManaged project status loaded.")),function(e){
|
|
337
|
+
const t=`http://${e.host}:${e.port}`,o="running"===e.status?i.default.green:"stopped"===e.status?i.default.yellow:i.default.red,r=[`${i.default.bold("App:")} ${i.default.cyan(e.name)}`,`${i.default.bold("Version:")} ${e.version}`,`${i.default.bold("Mode:")} ${i.default.cyan(e.mode)}`,`${i.default.bold("Status:")} ${o(e.status)}`,`${i.default.bold("PID:")} ${"number"==typeof e.pid?e.pid:i.default.dim("-")}`,`${i.default.bold("Host:")} ${e.host}`,`${i.default.bold("Port:")} ${e.port}`,`${i.default.bold("Local:")} ${i.default.cyan(t)}`,`${i.default.bold("Root Path:")} ${e.rootPath}`]
|
|
338
|
+
;console.log(i.default.cyan("\n Project Status")),r.forEach(e=>console.log(` ${e}`)),
|
|
339
|
+
console.log(`\n${i.default.dim(`Created at: ${e.createdAt}`)}\n`)}(r)):d.fail(`${i.default.red("[Mahameru]")} ${o}`),
|
|
336
340
|
process.exit(0)}),u.on("error",e=>{"win32"===process.platform&&"EPERM"===e.code?function(e,t){if(!(0,
|
|
337
341
|
c.hasWindowsElevationRetry)()&&!(0,c.isWindowsProcessElevated)()){
|
|
338
|
-
e.warn(
|
|
342
|
+
e.warn(i.default.yellow("\nWindows blocked access to the Mahameru PM pipe. Requesting Administrator approval..."))
|
|
339
343
|
;const o=(0,c.relaunchCurrentProcessAsAdmin)(t)
|
|
340
|
-
;o.ok&&(console.log(
|
|
341
|
-
console.log(
|
|
342
|
-
console.log(
|
|
344
|
+
;o.ok&&(console.log(i.default.cyan("An Administrator PowerShell window has been launched for the elevated retry.")),
|
|
345
|
+
console.log(i.default.dim(`The elevated retry will run from: ${t}`)),
|
|
346
|
+
console.log(i.default.dim("Keep that window open to see the managed project status or why it failed.")),process.exit(0))
|
|
343
347
|
;const r="user-cancelled"===o.reason?"UAC request was cancelled.":"Unable to launch an elevated Mahameru process."
|
|
344
|
-
;e.fail(
|
|
345
|
-
o.errorText&&console.error(
|
|
346
|
-
e.fail(
|
|
347
|
-
console.log(
|
|
348
|
+
;e.fail(i.default.red(`\n${r}\nMahameru PM Daemon is likely running with Administrator privileges, so ${i.default.bold("mahameru status")} also needs admin approval to connect.`)),
|
|
349
|
+
o.errorText&&console.error(i.default.dim(o.errorText)),process.exit(1)}
|
|
350
|
+
e.fail(i.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 ${i.default.bold(l.IPC_SOCKET_PATH)}.`)),
|
|
351
|
+
console.log(i.default.dim("Check the visible Administrator PowerShell window for the detailed failure output.")),
|
|
348
352
|
process.exit(1)
|
|
349
|
-
}(d,o):"ENOENT"===e.code||"ECONNREFUSED"===e.code?d.fail(
|
|
353
|
+
}(d,o):"ENOENT"===e.code||"ECONNREFUSED"===e.code?d.fail(i.default.red("\nMahameru PM Daemon is not running.")):(d.fail(i.default.red(`\n${e.message}`)),
|
|
350
354
|
console.error(e)),process.exit(1)})}catch(e){console.error(e),process.exit(1)}}},7659(e,t,o){
|
|
351
355
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
352
356
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.status=void 0
|
|
353
|
-
;const
|
|
357
|
+
;const n=o(6921),s=o(6718),a=o(1421),i=o(3024),c=o(6760),l=r(o(5205));function d(e,t){
|
|
354
358
|
console.log(`${l.default.bold(l.default.cyan("▲ Mahameru"))} ${l.default.dim(`Process Manager Status v${t}`)}`),
|
|
355
359
|
console.log("---------------+---------------------------------------------------");for(const[t,o]of Object.entries(e)){
|
|
356
360
|
const e=t.padEnd(14," ");console.log(` ${e} | ${o}`)}
|
|
357
361
|
console.log("---------------+---------------------------------------------------")}t.status=(e,t)=>()=>{
|
|
358
362
|
const o="linux"===process.platform,r="win32"===process.platform,u=`/etc/systemd/system/${e}.service`;let p="";try{p=(0,
|
|
359
|
-
|
|
363
|
+
s.getNodeModulesPath)()}catch(e){return void console.error(l.default.red(`❌ ${e.message}`))}const f=(0,
|
|
360
364
|
c.join)(p,"@mahameru","cli");try{if(o){const o={"Service Name":e,Installed:"No",State:"Stopped","Main Process":"N/A",
|
|
361
|
-
"Memory Usage":"N/A","CPU Usage":"N/A"};if(!(0,
|
|
365
|
+
"Memory Usage":"N/A","CPU Usage":"N/A"};if(!(0,i.existsSync)(u))return o.Installed=l.default.red("Not Installed"),
|
|
362
366
|
o.State=l.default.red("N/A"),void d(o,t);o.Installed=l.default.green("Yes");try{const t=(0,
|
|
363
|
-
|
|
364
|
-
}).toString().trim().split("=")[1],r=(0,
|
|
367
|
+
a.execSync)(`systemctl show ${e} --property=ActiveState`,{stdio:["ignore","pipe","ignore"]
|
|
368
|
+
}).toString().trim().split("=")[1],r=(0,a.execSync)(`systemctl show ${e} --property=SubState`,{
|
|
365
369
|
stdio:["ignore","pipe","ignore"]
|
|
366
|
-
}).toString().trim().split("=")[1],
|
|
370
|
+
}).toString().trim().split("=")[1],n=(0,a.execSync)(`systemctl show ${e} --property=MainPID`,{
|
|
367
371
|
stdio:["ignore","pipe","ignore"]}).toString().trim().split("=")[1];if("active"===t){
|
|
368
|
-
o.State=l.default.green(`${t} (${r})`),o["Main Process"]=
|
|
369
|
-
|
|
372
|
+
o.State=l.default.green(`${t} (${r})`),o["Main Process"]=n&&"0"!==n?n:"N/A";try{const t=(0,
|
|
373
|
+
a.execSync)(`systemctl show ${e} --property=MemoryCurrent`,{stdio:["ignore","pipe","ignore"]
|
|
370
374
|
}).toString().trim().split("=")[1];if(t&&"[not set]"!==t){const e=(parseInt(t,10)/1024/1024).toFixed(2)
|
|
371
|
-
;o["Memory Usage"]=`${e} MB`}}catch{}try{const e=(0,
|
|
375
|
+
;o["Memory Usage"]=`${e} MB`}}catch{}try{const e=(0,a.execSync)(`ps -p ${n} -o %cpu`,{stdio:["ignore","pipe","ignore"]
|
|
372
376
|
}).toString().trim().split("\n")[1];e&&(o["CPU Usage"]=`${e.trim()}%`)}catch{}
|
|
373
377
|
}else o.State="failed"===t?l.default.red(`${t} (${r})`):l.default.yellow(`${t} (${r})`)}catch(e){
|
|
374
378
|
o.State=l.default.red("Unknown (Error reading systemctl)")}d(o,t),function(e){try{const t=(0,
|
|
375
|
-
|
|
379
|
+
i.readFileSync)(e,"utf-8").match(/StandardError=append:(.+)/);if(t&&t[1]){const e=t[1].trim();if((0,i.existsSync)(e)){
|
|
376
380
|
console.log(l.default.bold(l.default.yellow(`\n📝 Last 3 lines from error log (${e}):`)));const t=(0,
|
|
377
|
-
|
|
381
|
+
i.readFileSync)(e,"utf-8").trim().split("\n").slice(-3)
|
|
378
382
|
;t.length>0&&""!==t[0]?t.forEach(e=>console.log(` ${l.default.dim(e)}`)):console.log(l.default.dim(" (Log file is empty)")),
|
|
379
383
|
console.log()}}}catch{}}(u)}else r?function({serviceName:e,mahameruInstalationPath:t,version:o}){
|
|
380
|
-
if("win32"===process.platform)try{const r=(0,c.join)(
|
|
381
|
-
c.join)(
|
|
382
|
-
|
|
384
|
+
if("win32"===process.platform)try{const r=(0,c.join)(n.APPDATA_PATH,"winsw",`${e}.exe`),s=(0,
|
|
385
|
+
c.join)(n.APPDATA_PATH,"winsw",`${e}.xml`);let d=null,u=null;if((0,i.existsSync)(s))try{const e=(0,
|
|
386
|
+
i.readFileSync)(s,"utf8"),t=e.match(/--host\s+([^\s"<]+)/),o=e.match(/--port\s+([^\s"<]+)/);t&&(d=t[1]),o&&(u=o[1])
|
|
383
387
|
}catch(e){}const p=()=>{d&&console.log(`Host : ${l.default.cyan(d)}`),
|
|
384
388
|
u&&console.log(`Port : ${l.default.cyan(u)}`),
|
|
385
|
-
u&&d&&console.log(`URL : ${l.default.cyan(`http://${d}:${u}`)}`)};if((0,
|
|
386
|
-
|
|
389
|
+
u&&d&&console.log(`URL : ${l.default.cyan(`http://${d}:${u}`)}`)};if((0,i.existsSync)(r))try{const e=(0,
|
|
390
|
+
a.execSync)(`"${r}" status`,{cwd:t}).toString().trim()
|
|
387
391
|
;return console.log(`\n${l.default.bold(l.default.cyan("▲ Mahameru"))} ${l.default.dim(`Process Manager Status v${o}`)}\n`),
|
|
388
392
|
void("NonExistent"===e?(console.log(`Installation status : ${l.default.red("Not Installed (NonExistent)")}`),
|
|
389
393
|
console.log(`Service Status : ${l.default.red("-")}`)):(console.log(`Installation status : ${l.default.green("Installed")}`),
|
|
390
394
|
"Started"===e?console.log(`Service Status : ${l.default.green("● Started (Running)")}`):"Stopped"===e?console.log(`Service Status : ${l.default.yellow("○ Stopped")}`):console.log(`Service Status : ${l.default.gray(e)}`),
|
|
391
|
-
p()))}catch(e){}try{const t=(0,
|
|
395
|
+
p()))}catch(e){}try{const t=(0,a.execSync)(`sc query "${e}"`,{stdio:["pipe","pipe","ignore"]}).toString()
|
|
392
396
|
;console.log(`\n${l.default.bold(l.default.cyan("▲ Mahameru"))} ${l.default.dim(`Process Manager Status v${o}`)}\n`),
|
|
393
397
|
console.log(`Installation status : ${l.default.green("Installed")}`),
|
|
394
398
|
t.includes("RUNNING")?console.log(`Service Status : ${l.default.green("● Started (Running)")}`):t.includes("STOPPED")?console.log(`Service Status : ${l.default.yellow("○ Stopped")}`):console.log(`Service Status : ${l.default.gray("Unknown")}`),
|
|
@@ -402,29 +406,29 @@ mahameruInstalationPath:f,version:t}):console.log(l.default.red("❌ Unsupported
|
|
|
402
406
|
console.error(l.default.red("❌ Failed to retrieve service status:"),e.message)}}},2074(e,t,o){
|
|
403
407
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
404
408
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.stopFork=void 0
|
|
405
|
-
;const
|
|
406
|
-
console.log(`${
|
|
407
|
-
|
|
409
|
+
;const n=r(o(7030)),s=o(4830),a=r(o(8720)),i=r(o(5205)),c=o(6921);t.stopFork=(e,t)=>async({host:o,port:r})=>{try{
|
|
410
|
+
console.log(`${i.default.bold(i.default.cyan("▲ Mahameru"))} ${i.default.dim(`CLI v${t}`)}\n`);const o=await(0,
|
|
411
|
+
s.getProjectJson)(e),r=(0,a.default)("Checking available port...").start(),l=n.default.createConnection({
|
|
408
412
|
path:c.IPC_SOCKET_PATH},()=>{l.write(JSON.stringify({command:"STOP",payload:{name:o.name}}))});l.on("data",e=>{
|
|
409
|
-
const{success:t,message:o,data:
|
|
410
|
-
;t?console.log(
|
|
413
|
+
const{success:t,message:o,data:n}=JSON.parse(e.toString())
|
|
414
|
+
;t?console.log(n):r.fail(`${i.default.red("[Mahameru]")} ${o}`),process.exit(0)})}catch(e){console.error(e),
|
|
411
415
|
process.exit(1)}}},5019(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
412
416
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.stopService=void 0
|
|
413
|
-
;const
|
|
417
|
+
;const n=o(6921),s=o(6718),a=o(1421),i=o(3024),c=o(6760),l=r(o(5205));t.stopService=e=>({gracefull:t})=>{
|
|
414
418
|
const o="linux"===process.platform,r="win32"===process.platform,d=`/etc/systemd/system/${e}.service`;let u="";try{u=(0,
|
|
415
|
-
|
|
419
|
+
s.getNodeModulesPath)()}catch(e){return void console.error(l.default.red(`❌ ${e.message}`))}const p=(0,
|
|
416
420
|
c.join)(u,"@mahameru","cli");try{if(o){
|
|
417
421
|
if(process.getuid&&0!==process.getuid())throw new Error("This action requires root privileges. Please run with sudo.")
|
|
418
|
-
;if(!(0,
|
|
422
|
+
;if(!(0,i.existsSync)(d))throw new Error(`Service "${e}" is not registered on this system.`)
|
|
419
423
|
;console.log(l.default.cyan(`🔍 Checking status for service: ${e}...`));let t=!1;try{"active"===(0,
|
|
420
|
-
|
|
421
|
-
t?(console.log(l.default.yellow(`🛑 Service is active. Stopping ${e}...`)),(0,
|
|
424
|
+
a.execSync)(`systemctl is-active ${e}`,{stdio:["ignore","pipe","ignore"]}).toString().trim()&&(t=!0)}catch{t=!1}
|
|
425
|
+
t?(console.log(l.default.yellow(`🛑 Service is active. Stopping ${e}...`)),(0,a.execSync)(`systemctl stop ${e}`),
|
|
422
426
|
console.log(l.default.green(`\n🛑 ${e} has been successfully stopped.`))):console.log(l.default.yellow(`⚠️ Service "${e}" is already stopped.`))
|
|
423
427
|
}else r?function({serviceName:e,mahameruInstalationPath:t}){try{
|
|
424
|
-
console.log(`Attempting to stop service: ${l.default.cyan(e)}...`);const o=(0,c.join)(
|
|
425
|
-
;if((0,
|
|
428
|
+
console.log(`Attempting to stop service: ${l.default.cyan(e)}...`);const o=(0,c.join)(n.APPDATA_PATH,"winsw",`${e}.exe`)
|
|
429
|
+
;if((0,i.existsSync)(o))return(0,a.execSync)(`"${o}" stop`,{cwd:t
|
|
426
430
|
}),void console.log(l.default.green(`✔ Success: Service "${e}" has been stopped.`))
|
|
427
|
-
;console.log(l.default.yellow("WinSW binary not found. Falling back to sc.exe...")),(0,
|
|
431
|
+
;console.log(l.default.yellow("WinSW binary not found. Falling back to sc.exe...")),(0,a.execSync)(`sc stop "${e}"`),
|
|
428
432
|
console.log(l.default.green(`✔ Success: Service "${e}" has been stopped via sc.exe.`))}catch(e){
|
|
429
433
|
console.error(l.default.red(`❌ Error: Failed to stop service: ${e.message}`)),
|
|
430
434
|
console.error("Make sure you are running CMD/PowerShell as an Administrator.")}}({serviceName:e,
|
|
@@ -432,47 +436,47 @@ mahameruInstalationPath:p}):console.log(l.default.red("❌ Unsupported platform.
|
|
|
432
436
|
console.error(l.default.red("❌ Failed to stop service:"),e.message)}}},6571(e,t,o){
|
|
433
437
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
434
438
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.uninstall=void 0
|
|
435
|
-
;const
|
|
439
|
+
;const n=o(6921),s=o(1421),a=o(3024),i=o(6760),c=r(o(5205));t.uninstall=e=>()=>{
|
|
436
440
|
const t="linux"===process.platform,o="win32"===process.platform,r=`/etc/systemd/system/${e}.service`;try{if(t){
|
|
437
441
|
if(process.getuid&&0!==process.getuid())throw new Error("This action requires root privileges. Please run with sudo.")
|
|
438
|
-
;if(!(0,
|
|
442
|
+
;if(!(0,a.existsSync)(r))throw new Error(`Service "${e}" was not found or is not registered on this system.`)
|
|
439
443
|
;console.log(c.default.cyan(`🔍 Checking status for service: ${e}...`));let t=!1;try{"active"===(0,
|
|
440
|
-
|
|
441
|
-
t&&(console.log(c.default.yellow(`🛑 Service is running. Stopping ${e}...`)),(0,
|
|
442
|
-
console.log(c.default.cyan("🔄 Disabling service..."));try{(0,
|
|
444
|
+
s.execSync)(`systemctl is-active ${e}`,{stdio:["ignore","pipe","ignore"]}).toString().trim()&&(t=!0)}catch{t=!1}
|
|
445
|
+
t&&(console.log(c.default.yellow(`🛑 Service is running. Stopping ${e}...`)),(0,s.execSync)(`systemctl stop ${e}`)),
|
|
446
|
+
console.log(c.default.cyan("🔄 Disabling service..."));try{(0,s.execSync)(`systemctl disable ${e}`,{
|
|
443
447
|
stdio:["ignore","pipe","ignore"]})}catch{}console.log(c.default.cyan(`🗑️ Removing service file from ${r}...`)),(0,
|
|
444
|
-
|
|
448
|
+
s.execSync)(`rm ${r}`),(0,s.execSync)("systemctl daemon-reload"),(0,s.execSync)("systemctl reset-failed"),
|
|
445
449
|
console.log(c.default.green(`\n🚀 ${e} successfully uninstalled!`))}else if(o){
|
|
446
|
-
console.log("Deleting Windows Service...");const t=(0,
|
|
447
|
-
|
|
448
|
-
cwd:
|
|
450
|
+
console.log("Deleting Windows Service...");const t=(0,i.join)(n.APPDATA_PATH,"winsw",`${e}.exe`);if((0,
|
|
451
|
+
a.existsSync)(t)){try{(0,s.execSync)(`"${t}" stop`,{cwd:n.APPDATA_PATH})}catch(e){}(0,s.execSync)(`"${t}" uninstall`,{
|
|
452
|
+
cwd:n.APPDATA_PATH}),console.log(`Sukses: Service "${e}" berhasil di-uninstall.`),
|
|
449
453
|
console.log(c.default.green("✔ Mahameru Process Manager successfully uninstalled."))}else{
|
|
450
454
|
console.log(c.default.yellow("Cannot found WinSW binary. Fallback to sc delete..."));try{(0,
|
|
451
|
-
|
|
452
|
-
(0,
|
|
455
|
+
s.execSync)(`sc stop "${e}"`)}catch(e){}
|
|
456
|
+
(0,s.execSync)(`sc delete "${e}"`),console.log(c.default.green(`✔ "${e}" successfully uninstalled.`))}
|
|
453
457
|
}else console.log(c.default.red("❌ Unsupported platform."))}catch(e){
|
|
454
458
|
console.error(c.default.red("❌ Uninstallation failed:"),e.message)}}},8625(e,t,o){
|
|
455
459
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
456
460
|
;Object.defineProperty(t,"__esModule",{value:!0})
|
|
457
|
-
;const
|
|
461
|
+
;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),P=new n.Command
|
|
458
462
|
;(async()=>{try{const e=process.cwd(),t="mahameru-pm"
|
|
459
|
-
;P.name("mahameru").description(`${
|
|
463
|
+
;P.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"),
|
|
460
464
|
P.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,
|
|
461
|
-
|
|
465
|
+
i.dev)({version:a.version})),P.command("build").description("Build MahameruJS production application.").action((0,
|
|
462
466
|
c.build)({rootPath:e
|
|
463
467
|
})),P.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,
|
|
464
468
|
g.startFork)({rootPath:e})),P.command("stop").description("Stop MahameruJS production server.").action((0,
|
|
465
|
-
v.stopFork)(e,
|
|
466
|
-
y.projectStatus)(e,
|
|
467
|
-
;const o=P.command("pm").description(`${
|
|
469
|
+
v.stopFork)(e,a.version)),P.command("status").description("View MahameruJS production server status.").action((0,
|
|
470
|
+
y.projectStatus)(e,a.version))
|
|
471
|
+
;const o=P.command("pm").description(`${s.default.bold(s.default.cyan("▲ MahameruJS"))} ${s.default.dim(`Process Manager v${a.version}`)}`)
|
|
468
472
|
;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,
|
|
469
|
-
u.pm)(
|
|
473
|
+
u.pm)(a.version)),
|
|
470
474
|
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(()=>{
|
|
471
|
-
console.log(
|
|
475
|
+
console.log(s.default.bold(s.default.cyan(`▲ MahameruJS Process Manager\n\n Not ${s.default.yellow("Not implemented yet.")}`)))
|
|
472
476
|
}),o.on("command:*",e=>{const t=e[0]
|
|
473
|
-
;["install","uninstall","start","stop"].includes(t)&&(console.log(
|
|
477
|
+
;["install","uninstall","start","stop"].includes(t)&&(console.log(s.default.yellow(`\n⚠ Did you mean 'mahameru pm service ${t}'?\n`)),
|
|
474
478
|
r.outputHelp(),process.exit(1))})
|
|
475
|
-
;const r=o.command("service").description(`${
|
|
479
|
+
;const r=o.command("service").description(`${s.default.bold(s.default.cyan("▲ MahameruJS"))} ${s.default.dim(`Process Manager Service v${a.version}`)}`)
|
|
476
480
|
;r.command("install").description("Install MahameruJS Process Manager and register the server as a service. This will make MahameruJS Process Manager boot on system startup.").option("-p, --port <number>","Port to run the server on",l.parsePort,8080).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").action((0,
|
|
477
481
|
d.install)(t)),
|
|
478
482
|
r.command("uninstall").description("Uninstall MahameruJS Process Manager as a service. This will remove the service from systemd and disable it.").action((0,
|
|
@@ -480,7 +484,7 @@ p.uninstall)(t)),r.command("start").description("Start MahameruJS Process Manage
|
|
|
480
484
|
f.startService)(t)),
|
|
481
485
|
r.command("stop").description("Stop MahameruJS Process Manager service.").option("-g, --graceful","Gracefully stop the service.",!1).action((0,
|
|
482
486
|
m.stopService)(t)),r.command("status").description("Get MahameruJS Process Manager status.").action((0,
|
|
483
|
-
h.status)(t,
|
|
487
|
+
h.status)(t,a.version)),await P.parseAsync(process.argv)}catch(e){console.error(e),process.exit(1)}})()},6921(e,t,o){
|
|
484
488
|
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)
|
|
485
489
|
;"darwin"===process.platform||"win32"===process.platform||process.platform,t.IS_WINDOWS="win32"===process.platform,
|
|
486
490
|
t.vL="darwin"===process.platform,t.ig="linux"===process.platform,t.Ds="mahameru",t.APPDATA_PATH=(()=>{
|
|
@@ -489,25 +493,25 @@ if(t.IS_WINDOWS)return(0,r.join)(process.env.APPDATA,t.Ds)
|
|
|
489
493
|
;throw new Error("Unsupported platform")})(),t.PROJECTS_FILE_PATH=(0,r.join)(t.APPDATA_PATH,"projects.json"),
|
|
490
494
|
t.MQ="mpm_ipc",t.IPC_SOCKET_PATH="win32"===process.platform?`\\\\.\\pipe\\${t.MQ}`:`/tmp/${t.MQ}.sock`},5043(e,t,o){
|
|
491
495
|
var r=this&&this.__createBinding||(Object.create?function(e,t,o,r){void 0===r&&(r=o)
|
|
492
|
-
;var
|
|
493
|
-
get:function(){return t[o]}}),Object.defineProperty(e,r,
|
|
494
|
-
}),
|
|
496
|
+
;var n=Object.getOwnPropertyDescriptor(t,o);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,
|
|
497
|
+
get:function(){return t[o]}}),Object.defineProperty(e,r,n)}:function(e,t,o,r){void 0===r&&(r=o),e[r]=t[o]
|
|
498
|
+
}),n=this&&this.__exportStar||function(e,t){
|
|
495
499
|
for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||r(t,e,o)}
|
|
496
|
-
;Object.defineProperty(t,"__esModule",{value:!0}),
|
|
497
|
-
var r,
|
|
498
|
-
;var
|
|
499
|
-
get:function(){return t[o]}}),Object.defineProperty(e,r,
|
|
500
|
-
}),
|
|
501
|
-
value:t})}:function(e,t){e.default=t}),
|
|
500
|
+
;Object.defineProperty(t,"__esModule",{value:!0}),n(o(3602),t),n(o(7258),t)},3602(e,t,o){
|
|
501
|
+
var r,n=this&&this.__createBinding||(Object.create?function(e,t,o,r){void 0===r&&(r=o)
|
|
502
|
+
;var n=Object.getOwnPropertyDescriptor(t,o);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,
|
|
503
|
+
get:function(){return t[o]}}),Object.defineProperty(e,r,n)}:function(e,t,o,r){void 0===r&&(r=o),e[r]=t[o]
|
|
504
|
+
}),s=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,
|
|
505
|
+
value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(r=function(e){
|
|
502
506
|
return r=Object.getOwnPropertyNames||function(e){var t=[]
|
|
503
507
|
;for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[t.length]=o);return t},r(e)},function(e){
|
|
504
|
-
if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o=r(e),
|
|
505
|
-
;return
|
|
508
|
+
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])
|
|
509
|
+
;return s(t,e),t}),i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
506
510
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.processManager=void 0
|
|
507
|
-
;const c=
|
|
511
|
+
;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)),P=o(4437),w=(0,
|
|
508
512
|
d.join)(__dirname,"mpm"),S={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",
|
|
509
513
|
".png":"image/png",".jpg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon"}
|
|
510
|
-
;t.processManager=async({host:e,port:t,daemon:r,cert:
|
|
514
|
+
;t.processManager=async({host:e,port:t,daemon:r,cert:n,key:s},a)=>{try{const i=await(0,y.freePortFinder)(t),$=(e,t)=>{
|
|
511
515
|
if(t.setHeader("Access-Control-Allow-Origin","*"),
|
|
512
516
|
t.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),
|
|
513
517
|
t.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization"),t.setHeader("X-Powered-By","MahameruJS"),
|
|
@@ -521,130 +525,137 @@ v.default.createReadStream(r).pipe(t)}{const e=(0,d.join)(w,"index.html")
|
|
|
521
525
|
t.end("<h1>404 - Frontend Build Not Found</h1>")):(t.writeHead(200,{"Content-Type":"text/html"}),
|
|
522
526
|
v.default.createReadStream(e).pipe(t)))}}):(t.writeHead(403,{"Content-Type":"text/plain"}),t.end("Forbidden"))}
|
|
523
527
|
return t.writeHead(404,{"Content-Type":"text/html"}),t.end("<h1>404 Not Found</h1>")
|
|
524
|
-
},
|
|
528
|
+
},M=()=>console.log("[MPM] HTTP server closed."),_=e=>console.log("[MPM] HTTP server error:",e),j=async()=>{
|
|
525
529
|
process.send||r||(console.clear(),
|
|
526
|
-
console.log(`${c.default.bold(c.default.cyan("▲ Mahameru"))} ${c.default.dim(`Process Manager v${
|
|
530
|
+
console.log(`${c.default.bold(c.default.cyan("▲ Mahameru"))} ${c.default.dim(`Process Manager v${a}`)}\n`)),
|
|
527
531
|
console.log(`Server listening on host ${e} and port ${t}.`),
|
|
528
|
-
process.send||r||console.log(` ${c.default.bold(c.default.green("PID"))}: ${process.pid}\n ${c.default.bold(c.default.green("URL"))}: ${
|
|
529
|
-
;const o=await(0,h.loadProjects)();for(const e of o)e.isLastStatusIsRunning&&await U(e)},
|
|
530
|
-
f.createServer)({cert:v.default.readFileSync(
|
|
531
|
-
},$).on("close",
|
|
532
|
+
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`)
|
|
533
|
+
;const o=await(0,h.loadProjects)();for(const e of o)e.isLastStatusIsRunning&&await U(e)},x=n&&s,E=n&&s?(0,
|
|
534
|
+
f.createServer)({cert:v.default.readFileSync(n),key:v.default.readFileSync(s)
|
|
535
|
+
},$).on("close",M).on("error",_).listen(i,e,j):(0,p.createServer)($).on("close",M).on("error",_).listen(i,e,j)
|
|
532
536
|
;if(!m.IS_WINDOWS){const e=o(9896);e.existsSync(m.IPC_SOCKET_PATH)&&e.unlinkSync(m.IPC_SOCKET_PATH)}const T=e=>t=>{
|
|
533
537
|
const o=t.toString().trim();console.log(`[${e}] ${o}`)},A=e=>t=>{const o=t.toString().trim()
|
|
534
|
-
;console.error(`[${e} ERROR] ${o}`)},b=(o,r,
|
|
535
|
-
success:!1,message:
|
|
536
|
-
}));else if("READY"===
|
|
537
|
-
o.write(JSON.stringify({success:!0,message:`Project ${r} successfully started by PM Daemon (PID: ${
|
|
538
|
-
mpmUrl:`http://${e}:${t}`}));else if("PROCESS_USAGE"===
|
|
538
|
+
;console.error(`[${e} ERROR] ${o}`)},b=(o,r,n)=>({type:s,data:a})=>{if(o)if("ERROR"===s)o.write(JSON.stringify({
|
|
539
|
+
success:!1,message:a
|
|
540
|
+
}));else if("READY"===s)console.log(`[MPM] Project${r} successfully started by PM Daemon (PID: ${n.pid})`),
|
|
541
|
+
o.write(JSON.stringify({success:!0,message:`Project ${r} successfully started by PM Daemon (PID: ${n.pid})`,data:a,
|
|
542
|
+
mpmUrl:`http://${e}:${t}`}));else if("PROCESS_USAGE"===s){const e=(0,h.getProject)(r);e&&z.emit("process-usage",{data:a,
|
|
539
543
|
project:(0,g.parseProject)(e)})}},D=e=>t=>{console.log(`[MPM] Project ${e} errored: ${t.message}`)},O=e=>({success:!0,
|
|
540
544
|
data:e}),R=e=>({success:!1,error:e}),k=e=>(0,g.parseProject)(e),C=()=>(0,h.getProjects)().map(g.parseProject),N=e=>{
|
|
541
|
-
console.log(`[MPM] ${e}`)},
|
|
542
|
-
const t=(0,d.join)(e.rootPath,"node_modules","mahameru","
|
|
543
|
-
v.existsSync)(t))throw new Error(`Mahameru package is not installed in ${e.rootPath} project. Please install it by running: npm install mahameru`)
|
|
545
|
+
console.log(`[MPM] ${e}`)},F=()=>{z.emit("projects",C())},I=e=>{
|
|
546
|
+
const t=(0,d.join)(e.rootPath,"node_modules","mahameru","server.js")
|
|
547
|
+
;if(!(0,v.existsSync)(t))throw new Error(`Mahameru package is not installed in ${e.rootPath} project. Please install it by running: npm install mahameru`)
|
|
544
548
|
;return t},H=e=>({MAHAMERU__SEND_PROCESS_USAGE_INTERVAL:"3000",MAHAMERU__ROOT_PATH:e.rootPath,
|
|
545
|
-
MAHAMERU__MODE:"production",...e.host?{MAHAMERU__HTTP_LISTEN_HOST:e.host
|
|
546
|
-
MAHAMERU__HTTP_LISTEN_PORT:e.port.toString()
|
|
549
|
+
MAHAMERU__MODE:"production",...e.host?{MAHAMERU__HTTP_LISTEN_HOST:e.host}:{},...e.port?{
|
|
550
|
+
MAHAMERU__HTTP_LISTEN_PORT:e.port.toString()}:{}}),W=(e,t,o=null)=>{t.stdout?.on("data",T(e.name)),
|
|
547
551
|
t.stderr?.on("data",A(e.name)),t.on("message",b(o,e.name,t)),t.on("error",D(e.name)),t.once("exit",o=>{e.child===t&&(0,
|
|
548
552
|
h.getProject)(e.name)&&(e.status=0===o||null===o?"stopped":"errored",e.pid=void 0,e.child=void 0,
|
|
549
|
-
|
|
550
|
-
};e.on("message",r)}),U=(e,t=null)=>new Promise((o,r)=>{let
|
|
551
|
-
l.fork)(
|
|
552
|
-
e.pid=
|
|
553
|
-
e.status="running",e.pid=
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
r(new Error(`Project ${e.name} exited before ready${"number"==typeof t?` with code ${t}`:""}`))})})
|
|
558
|
-
e.status="errored",e.pid=void 0,e.child=void 0,(0,h.setProject)(e),r(t)})}}),L=e=>new Promise((t,o)=>{
|
|
559
|
-
if(!e.child)return e.status="stopped",e.pid=void 0,(0,h.setProject)(e),void t(e);const r=e.child;let
|
|
560
|
-
|
|
561
|
-
e.child=void 0,(0,h.setProject)(e),t(e)})}),r.once("error",t=>{
|
|
562
|
-
h.setProject)(e),o(t)})}),r.once("exit",r=>{
|
|
553
|
+
z.emit("project-update",k(e)),F())})},J=(e,t)=>new Promise(o=>{const r=n=>{t.includes(n.type)&&(e.off("message",r),o(n))
|
|
554
|
+
};e.on("message",r)}),U=(e,t=null)=>new Promise((o,r)=>{let n=!1;const s=e=>{n||(n=!0,e())};try{const n=I(e),a=(0,
|
|
555
|
+
l.fork)(n,[],{cwd:e.rootPath,env:{...process.env,...H(e)},stdio:["inherit","pipe","pipe","ipc"]});e.status="stopped",
|
|
556
|
+
e.pid=a.pid,e.child=a,(0,h.setProject)(e),W(e,a,t),J(a,["READY","ERROR"]).then(({type:t,data:n})=>{"READY"===t?s(()=>{
|
|
557
|
+
e.status="running",e.pid=a.pid,e.child=a,e.port=n.port,e.host=n.host,(0,h.setProject)(e),o(e)}):"ERROR"===t&&s(()=>{
|
|
558
|
+
r(`[MPM] ${n.message}`)})}),a.once("error",t=>{s(()=>{e.status="errored",e.pid=void 0,e.child=void 0,(0,
|
|
559
|
+
h.setProject)(e),r(t)})}),a.once("exit",t=>{s(()=>{e.status=0===t||null===t?"stopped":"errored",e.pid=void 0,
|
|
560
|
+
e.child=void 0,
|
|
561
|
+
(0,h.setProject)(e),r(new Error(`Project ${e.name} exited before ready${"number"==typeof t?` with code ${t}`:""}`))})})
|
|
562
|
+
}catch(t){s(()=>{e.status="errored",e.pid=void 0,e.child=void 0,(0,h.setProject)(e),r(t)})}}),L=e=>new Promise((t,o)=>{
|
|
563
|
+
if(!e.child)return e.status="stopped",e.pid=void 0,(0,h.setProject)(e),void t(e);const r=e.child;let n=!1;const s=e=>{
|
|
564
|
+
n||(n=!0,e())};J(r,["SHUTDOWN_DONE"]).then(({type:o})=>{"SHUTDOWN_DONE"===o&&s(()=>{e.status="stopped",e.pid=void 0,
|
|
565
|
+
e.child=void 0,(0,h.setProject)(e),t(e)})}),r.once("error",t=>{s(()=>{e.status="errored",e.pid=void 0,e.child=void 0,(0,
|
|
566
|
+
h.setProject)(e),o(t)})}),r.once("exit",r=>{s(()=>{e.status=0===r||null===r?"stopped":"errored",e.pid=void 0,
|
|
563
567
|
e.child=void 0,
|
|
564
568
|
(0,h.setProject)(e),0!==r&&null!==r?o(new Error(`Project ${e.name} exited during shutdown with code ${r}`)):t(e)})}),
|
|
565
569
|
r.send({type:"SHUTDOWN"})}),B=async e=>{N(`Delete requested for project "${e}"`);const t=(0,h.getProject)(e)
|
|
566
570
|
;if(!t)throw N(`Delete aborted. Project "${e}" not found`),new Error("Project not found");const o=k(t)
|
|
567
571
|
;t.child?(N(`Project "${e}" is running. Stopping before delete`),await L(t)):(t.status="stopped",t.pid=void 0,
|
|
568
572
|
t.child=void 0,(0,h.setProject)(t),N(`Project "${e}" already stopped. Proceeding to delete`));const r=(0,
|
|
569
|
-
h.getProject)(e),
|
|
573
|
+
h.getProject)(e),n=r?k(r):o;return N(`Deleting project "${e}" from registry`),(0,h.deleteProject)(e),
|
|
570
574
|
N(`Project "${e}" exists after delete: ${(0,h.getProject)(e)?"true":"false"}`),N(`Emitting project-delete for "${e}"`),
|
|
571
|
-
|
|
572
|
-
;if("FORK_PROJECT"===o.command){const t=o.payload,{name:r,description:
|
|
575
|
+
z.emit("project-delete",n),F(),n},q=u.default.createServer(e=>{e.on("data",t=>{try{const o=JSON.parse(t.toString())
|
|
576
|
+
;if("FORK_PROJECT"===o.command){const t=o.payload,{name:r,description:n,version:s,projectRoot:a,port:i,host:c}=t,l=(0,
|
|
573
577
|
h.getProject)(r);if(l&&"running"===l.status&&void 0!==l.child&&void 0!==l.pid)return void e.write(JSON.stringify({
|
|
574
|
-
status:"error",message:"Project already running"}));console.log(`[MPM] Starting project: ${r} (${
|
|
575
|
-
pid:void 0,createdAt:l?.createdAt??(new Date).toISOString(),isDisabled:!1,name:r,mode:"production",description:
|
|
576
|
-
version:
|
|
577
|
-
l?
|
|
578
|
+
status:"error",message:"Project already running"}));console.log(`[MPM] Starting project: ${r} (${a})`);const d={
|
|
579
|
+
pid:void 0,createdAt:l?.createdAt??(new Date).toISOString(),isDisabled:!1,name:r,mode:"production",description:n,
|
|
580
|
+
version:s,rootPath:a,host:c,port:i,status:"stopped"};(0,h.setProject)(d),U(d,e).then(e=>{
|
|
581
|
+
l?z.emit("project-update",k(e)):z.emit("project-create",k(e)),F()}).catch(t=>{e.write(JSON.stringify({success:!1,
|
|
578
582
|
error:t.message}))})}else if("STOP"===o.command){const t=o.payload,r=(0,h.getProject)(t.name)
|
|
579
583
|
;if(!r)return void e.write(JSON.stringify({success:!1,error:"Project not found"}));L(r).then(t=>{
|
|
580
|
-
|
|
584
|
+
z.emit("project-update",k(t)),F(),e.write(JSON.stringify(O(k(t))))}).catch(t=>{e.write(JSON.stringify(R(t.message)))})
|
|
581
585
|
}else if("START"===o.command);else if("RESTART"===o.command);else if("STATUS"===o.command){const t=o.payload,r=(0,
|
|
582
586
|
h.getProject)(t.name);if(r){const{child:t,...o}=r;e.write(JSON.stringify({success:!0,data:o}))
|
|
583
587
|
}else e.write(JSON.stringify({success:!1,error:"Project not found"}))}}catch(t){e.write(JSON.stringify({success:!1,
|
|
584
588
|
error:t.message}))}})});q.on("close",()=>{console.log("[MPM IPC SERVER] IPC Server closed")}),q.on("error",e=>{
|
|
585
589
|
"EADDRINUSE"===e.code?console.error(`[MPM IPC SERVER] IPC Server already running on ${m.IPC_SOCKET_PATH}`):console.error("[MPM IPC SERVER]",e),
|
|
586
590
|
process.exit(1)}),q.listen(m.IPC_SOCKET_PATH,()=>{
|
|
587
|
-
console.log(`[MPM IPC SERVER] IPC Server listening on ${m.IPC_SOCKET_PATH}`)});const
|
|
588
|
-
},path:"/ws",serveClient:!1});
|
|
591
|
+
console.log(`[MPM IPC SERVER] IPC Server listening on ${m.IPC_SOCKET_PATH}`)});const z=new P.Server(E,{cors:{origin:"*"
|
|
592
|
+
},path:"/ws",serveClient:!1});z.on("connection",e=>{(0,h.setSocket)(e);const t=(0,h.getProjects)().map(g.parseProject)
|
|
589
593
|
;e.emit("projects",t),e.on("getProjects",e=>e({success:!0,data:(0,h.getProjects)().map(g.parseProject)})),
|
|
590
594
|
e.on("start",(e,t)=>{const o=(0,h.getProject)(e)
|
|
591
595
|
;return o?o.child||"running"===o.status?t(R(`Project ${e} is already running`)):void U(o).then(e=>{
|
|
592
|
-
|
|
596
|
+
z.emit("project-update",k(e)),F(),t(O(k(e)))}).catch(e=>{t(R(e.message))}):t(R("Project not found"))}),
|
|
593
597
|
e.on("stop",(e,t)=>{const o=(0,h.getProject)(e);if(!o)return t(R("Project not found"));L(o).then(e=>{
|
|
594
|
-
|
|
598
|
+
z.emit("project-update",k(e)),F(),t(O(k(e)))}).catch(e=>{t(R(e.message))})});const o=e=>(t,o)=>{
|
|
595
599
|
N(`Socket event "${e}" received for project "${t}"`),B(t).then(e=>{N(`Invoking delete callback for project "${t}"`),
|
|
596
600
|
o(O(e))}).catch(e=>{N(`Delete failed for project "${t}": ${e.message}`),o(R(e.message))})};e.on("delete",o("delete")),
|
|
597
|
-
e.on("remove",o("remove")),e.on("disconnect",()=>{(0,h.deleteSocket)(e.id)})});const
|
|
598
|
-
console.log(`[MPM] Received ${e}`),await(0,h.saveProjects)(),(0,h.getSockets)().forEach(e=>e.disconnect()),
|
|
599
|
-
q.close(),
|
|
601
|
+
e.on("remove",o("remove")),e.on("disconnect",()=>{(0,h.deleteSocket)(e.id)})});const G=async e=>{
|
|
602
|
+
console.log(`[MPM] Received ${e}`),await(0,h.saveProjects)(),(0,h.getSockets)().forEach(e=>e.disconnect()),z.close(),
|
|
603
|
+
q.close(),E.close(e=>{e&&console.log("[MPM]",e),process.exit(0)})};process.on("SIGINT",G),process.on("SIGTERM",G)
|
|
600
604
|
}catch(e){console.log("mpm error",e),process.exit(1)}}},7258(e,t,o){Object.defineProperty(t,"__esModule",{value:!0}),
|
|
601
605
|
t.saveProjects=t.loadProjects=t.clearSockets=t.deleteSocket=t.setSocket=t.getSocket=t.getSockets=t.clearProjects=t.deleteProject=t.setProjects=t.setProject=t.getProject=t.getProjects=void 0
|
|
602
|
-
;const r=o(3024),
|
|
606
|
+
;const r=o(3024),n=o(6760),s=o(1455),a=o(6921),i=o(6929),c=new Map;t.getProjects=()=>Array.from(c.values())
|
|
603
607
|
;t.getProject=e=>c.get(e);t.setProject=e=>(c.set(e.name,e),e);t.setProjects=e=>e.forEach(t.setProject)
|
|
604
608
|
;t.deleteProject=e=>c.delete(e);t.clearProjects=()=>c.clear();const l=new Map;t.getSockets=()=>Array.from(l.values())
|
|
605
609
|
;t.getSocket=e=>l.get(e);t.setSocket=e=>l.set(e.id,e);t.deleteSocket=e=>l.delete(e);t.clearSockets=()=>l.clear()
|
|
606
|
-
;t.loadProjects=async()=>{try{if((0,r.existsSync)((0,
|
|
607
|
-
|
|
608
|
-
|
|
610
|
+
;t.loadProjects=async()=>{try{if((0,r.existsSync)((0,n.dirname)(a.PROJECTS_FILE_PATH))||await(0,s.mkdir)((0,
|
|
611
|
+
n.dirname)(a.PROJECTS_FILE_PATH),{recursive:!0}),!(0,r.existsSync)(a.PROJECTS_FILE_PATH))return await(0,
|
|
612
|
+
s.writeFile)(a.PROJECTS_FILE_PATH,"[]","utf-8"),[];const e=await(0,s.readFile)(a.PROJECTS_FILE_PATH,"utf-8")
|
|
609
613
|
;return JSON.parse(e)}catch(e){throw new Error("Failed to load projects")}};t.saveProjects=async()=>{try{const e=(0,
|
|
610
614
|
t.getProjects)().map(e=>({...e,child:void 0,pid:void 0,isLastStatusIsRunning:"running"===e.status
|
|
611
|
-
})).map(
|
|
615
|
+
})).map(i.parseProject),o=JSON.stringify(e);await(0,s.writeFile)(a.PROJECTS_FILE_PATH,o,"utf-8")}catch(e){
|
|
612
616
|
throw new Error("Failed to save projects")}}},7209(e,t,o){var r=this&&this.__importDefault||function(e){
|
|
613
617
|
return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),
|
|
614
|
-
t.freePortFinder=async function(e=3e3){let t=e;const o=e+999;for(;t<o;)try{return await
|
|
618
|
+
t.freePortFinder=async function(e=3e3){let t=e;const o=e+999;for(;t<o;)try{return await s(t)}catch(e){t++}
|
|
615
619
|
throw new Error(`Port ${e} - 999 is not available`)},t.isPortAvailable=function(e){return new Promise((t,o)=>{
|
|
616
|
-
const r=
|
|
617
|
-
r.listen(e,"127.0.0.1")})};const
|
|
620
|
+
const r=n.default.createServer();r.once("error",e=>{e.code,o(!1)}),r.once("listening",()=>{r.close(()=>t(!0))}),
|
|
621
|
+
r.listen(e,"127.0.0.1")})};const n=r(o(7030));function s(e){return new Promise((t,o)=>{const r=n.default.createServer()
|
|
618
622
|
;r.once("error",e=>{e.code,o(e)}),r.once("listening",()=>{r.close(()=>t(e))}),r.listen(e,"127.0.0.1")})}},4830(e,t,o){
|
|
619
|
-
t.getProjectJson=async function(e){try{return JSON.parse(await(0,r.readFile)((0,
|
|
620
|
-
}catch(e){throw new Error("package.json not found")}};const r=o(1455),
|
|
623
|
+
t.getProjectJson=async function(e){try{return JSON.parse(await(0,r.readFile)((0,n.join)(e,"package.json"),"utf-8"))
|
|
624
|
+
}catch(e){throw new Error("package.json not found")}};const r=o(1455),n=o(6760)},6718(e,t,o){
|
|
621
625
|
t.getNodeModulesPath=function(){try{return(0,r.execSync)("npm root -g",{stdio:["ignore","pipe","ignore"]
|
|
622
626
|
}).toString().trim()}catch(e){throw new Error("npm is not installed or not accessible on your system.")}}
|
|
623
|
-
;const r=o(1421)},4813(e,t,o){t.isMahameruProjectDir=function(e){const t=(0,
|
|
624
|
-
|
|
627
|
+
;const r=o(1421)},4813(e,t,o){t.isMahameruProjectDir=function(e){const t=(0,n.join)(e,"package.json"),o=(0,
|
|
628
|
+
n.join)(e,"node_modules");if(!(0,r.existsSync)(t)&&(0,r.existsSync)(o))return!1;try{const e=(0,
|
|
625
629
|
r.readFileSync)(t,"utf-8"),o=JSON.parse(e);return!(!o.dependencies||!o.dependencies.mahameru)}catch(e){return!1}}
|
|
626
|
-
;const r=o(3024),
|
|
630
|
+
;const r=o(3024),n=o(6760)},6929(e,t){t.parseProject=function(e){return{pid:e.pid,createdAt:e.createdAt,
|
|
627
631
|
isDisabled:e.isDisabled,name:e.name,description:e.description,version:e.version,mode:e.mode,rootPath:e.rootPath,
|
|
628
|
-
port:e.port,host:e.host,status:e.status}}},3157(e,t,o){t.hasWindowsElevationRetry=function(){return"1"===process.env[
|
|
629
|
-
},t.getWindowsElevatedWorkingDirectory=function(){return process.env[
|
|
632
|
+
port:e.port,host:e.host,status:e.status}}},3157(e,t,o){t.hasWindowsElevationRetry=function(){return"1"===process.env[n]
|
|
633
|
+
},t.getWindowsElevatedWorkingDirectory=function(){return process.env[s]},t.isWindowsProcessElevated=function(){
|
|
630
634
|
if("win32"!==process.platform)return!1
|
|
631
635
|
;const e=(0,r.spawnSync)("powershell.exe",["-NoProfile","-NonInteractive","-Command","([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)"],{
|
|
632
636
|
encoding:"utf8",windowsHide:!0});return 0===e.status&&"true"===e.stdout.trim().toLowerCase()},
|
|
633
637
|
t.relaunchCurrentProcessAsAdmin=function(e){if("win32"!==process.platform)return{ok:!1,reason:"unsupported-platform"}
|
|
634
638
|
;const t=process.argv[1];if(!t)return{ok:!1,reason:"missing-entrypoint"}
|
|
635
|
-
;const o=[t,...process.argv.slice(2)],
|
|
636
|
-
`@(${p.map(e=>`'${
|
|
639
|
+
;const o=[t,...process.argv.slice(2)],i=`$env:${n}='1'`,c=`$env:${s}='${a(e)}'`,l=[i,c,`Set-Location -LiteralPath '${a(e)}'`,`& '${a(process.execPath)}' ${o.map(e=>`'${a(e)}'`).join(" ")}`,"",'Write-Host ""','Write-Host "Mahameru elevated session finished. Review any output above." -ForegroundColor Cyan','Write-Host "Press Enter to close this Administrator window." -ForegroundColor DarkGray',"Read-Host | Out-Null"].join("; "),d=["$argumentList = "+(p=["-NoProfile","-ExecutionPolicy","Bypass","-NoExit","-Command",l],
|
|
640
|
+
`@(${p.map(e=>`'${a(e)}'`).join(", ")})`),`Start-Process -FilePath 'powershell.exe' -Verb RunAs -WorkingDirectory '${a(e)}' -ArgumentList $argumentList`].join("; "),u=(0,
|
|
637
641
|
r.spawnSync)("powershell.exe",["-NoProfile","-NonInteractive","-Command",d],{encoding:"utf8",windowsHide:!0});var p
|
|
638
642
|
;if(0===u.status)return{ok:!0};const f=[u.stdout,u.stderr].filter(Boolean).join("\n").trim();return{ok:!1,
|
|
639
643
|
reason:/cancelled by the user|canceled by the user/i.test(f)?"user-cancelled":"spawn-failed",errorText:f}}
|
|
640
|
-
;const r=o(1421),
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
e
|
|
644
|
+
;const r=o(1421),n="MAHAMERU_ELEVATED_RETRY",s="MAHAMERU_ELEVATED_CWD";function a(e){return e.replace(/'/g,"''")}},
|
|
645
|
+
8419(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
646
|
+
;Object.defineProperty(t,"__esModule",{value:!0}),t.createZip=t.extractZip=void 0;const n=r(o(4650)),s=o(6760)
|
|
647
|
+
;t.extractZip=(e,t)=>new Promise((o,r)=>{try{new n.default(e).extractAllToAsync(t,!0,void 0,e=>{
|
|
648
|
+
e?r(new Error(`Extraction failed: ${e.message}`)):o(`Successfully extracted to ${t}`)})}catch(e){r(e)}})
|
|
649
|
+
;t.createZip=(e,t,o)=>new Promise((r,a)=>{try{const i=new n.default;if(o){const t=(0,s.basename)(e)
|
|
650
|
+
;i.addLocalFolder(e,t)}else i.addLocalFolder(e);i.writeZip(t,e=>{
|
|
651
|
+
e?a(new Error(`Zipping failed: ${e}`)):r(`Successfully created zip at ${t}`)})}catch(e){a(e)}})},4650(e){
|
|
652
|
+
e.exports=require("adm-zip")},6858(e){e.exports=require("commander")},6261(e){e.exports=require("events")},8720(e){
|
|
653
|
+
e.exports=require("ora")},5205(e){e.exports=require("picocolors")},6471(e){e.exports=require("porterman/string-helper")
|
|
654
|
+
},4437(e){e.exports=require("socket.io")},9896(e){e.exports=require("fs")},1943(e){e.exports=require("fs/promises")},
|
|
655
|
+
9278(e){e.exports=require("net")},1421(e){e.exports=require("node:child_process")},139(e){
|
|
645
656
|
e.exports=require("node:cluster")},3024(e){e.exports=require("node:fs")},1455(e){e.exports=require("node:fs/promises")},
|
|
646
657
|
7067(e){e.exports=require("node:http")},4708(e){e.exports=require("node:https")},8995(e){
|
|
647
658
|
e.exports=require("node:module")},7030(e){e.exports=require("node:net")},8161(e){e.exports=require("node:os")},6760(e){
|
|
648
|
-
e.exports=require("node:path")},6928(e){e.exports=require("path")},8330(e){e.exports={version:"0.0.
|
|
649
|
-
;(function o(r){const
|
|
650
|
-
;return e[r].call(
|
|
659
|
+
e.exports=require("node:path")},6928(e){e.exports=require("path")},8330(e){e.exports={version:"0.0.22"}}};const t={}
|
|
660
|
+
;(function o(r){const n=t[r];if(void 0!==n)return n.exports;const s=t[r]={exports:{}}
|
|
661
|
+
;return e[r].call(s.exports,s,s.exports,o),s.exports})(8625)})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mahameru/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "MahameruJS CLI Utility - The command-line interface for running and building Mahameru-based applications",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mahameru": "./cli.js"
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"node": ">=20.6.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"adm-zip": "^0.5.18",
|
|
30
31
|
"commander": "^15.0.0",
|
|
31
32
|
"ora": "^9.4.1",
|
|
32
33
|
"picocolors": "^1.1.1",
|