@mahameru/cli 0.0.21 → 0.0.23
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 +373 -359
- 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.23 │
|
|
7
7
|
* │ Built: 2026 │
|
|
8
8
|
* │ │
|
|
9
9
|
* │ Copyright (c) Bintan <hello@bintvn.co> │
|
|
@@ -13,308 +13,315 @@
|
|
|
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 u,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
text:`${c.default.cyan("[Mahameru]")} Starting TypeScript watch...`,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
getCanonicalFileName:e=>e,getCurrentDirectory:()=>m,getNewLine:()=>S.newLine};let j=!1,x=!1,T=0
|
|
161
|
+
let u,_=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
|
+
a.join)(m,"src","routes"),(0,a.join)(h,"types","routes.d.ts")),await(0,p.generateDataSourceTypes)((0,
|
|
163
|
+
a.join)(m,"src","databases"),(0,a.join)(h,"types","dataSources.d.ts")),await(0,p.generateTypesBarrel)((0,
|
|
164
|
+
a.join)(h,"types","index.d.ts")),await(0,p.generateMahameruDts)((0,a.join)(m,"mahameru.d.ts")),await(0,s.mkdir)(h,{
|
|
165
|
+
recursive:!0});const R=(0,i.default)({text:`${c.default.cyan("[Mahameru]")} Starting TypeScript watch...`,
|
|
166
|
+
spinner:"triangle"}).start(),k={dev:!0,host:t,port:o,rootPath:m};u=new d.App(k),
|
|
167
|
+
_=await async function({environment:e,spinner:t,onBuildStart:o,onBuildSuccess:r,onBuildFailure:i}){const l=(0,
|
|
168
|
+
a.resolve)((0,
|
|
169
|
+
a.join)(m,"node_modules","typescript")),{createWatchCompilerHost:d,createWatchProgram:u,formatDiagnosticsWithColorAndContext:p,formatDiagnostic:P,sys:S,createEmitAndSemanticDiagnosticsBuilderProgram:_}=f(l),j={
|
|
170
|
+
getCanonicalFileName:e=>e,getCurrentDirectory:()=>m,getNewLine:()=>S.newLine};let x=!1,E=!1,T=0
|
|
165
171
|
;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,
|
|
172
|
+
},S,_,e=>{E=!0;const t=e.file?p([e],j):P(e,j);process.stderr.write(t.endsWith("\n")?t:`${t}\n`)},e=>{
|
|
167
173
|
const t=e.messageText.toString().trim();(function(e){
|
|
168
174
|
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}),
|
|
175
|
+
})(t)&&(T+=1,A.set(T,Date.now()),b.set(T,{emittedRuntimeFiles:new Set,changedRuntimeSourceFiles:new Set}),E=!1,o()),
|
|
170
176
|
function(e){
|
|
171
177
|
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=$((0,
|
|
173
|
-
const t=$((0,
|
|
174
|
-
;
|
|
175
|
-
;H&&(C.watchDirectory=(e,t,o,r)=>
|
|
176
|
-
;W.writeFile=(e,t,o,r,s
|
|
178
|
+
}(t)||console.log(`${c.default.yellow("[Mahameru TSC]")} ${t}`)}),N=$((0,a.resolve)((0,a.join)(h,"types"))),F=e=>{
|
|
179
|
+
const t=$((0,a.resolve)(e));return t===N||t.startsWith(`${N}/`)},I=C.watchFile?.bind(C)
|
|
180
|
+
;I&&(C.watchFile=(e,t,o,r)=>F(e)?{close(){}}:I(e,t,o,r));const H=C.watchDirectory?.bind(C)
|
|
181
|
+
;H&&(C.watchDirectory=(e,t,o,r)=>F(e)?{close(){}}:H(e,t,o,r));const W=C,J=W.writeFile?.bind(W)??S.writeFile.bind(S)
|
|
182
|
+
;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
183
|
;const t=0===T?1:T;T=t,R=R.then(()=>B(e,t)).catch(e=>{
|
|
178
184
|
console.error(c.default.red("[Mahameru Dev] Build lifecycle failed.")),console.error(e)})};const L=u(C)
|
|
179
185
|
;async function B(e,o){const l=A.get(o)??Date.now(),d=b.get(o)??{emittedRuntimeFiles:new Set,
|
|
180
186
|
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(!w){const e=(0,
|
|
184
|
-
|
|
185
|
-
})}return w}();for(const o of e){if(!(0,
|
|
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),
|
|
187
|
+
;if(E)return x||(x=!0,t.fail(`${c.default.red("[Mahameru]")} Initial TypeScript build failed.`),
|
|
188
|
+
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(!w){const e=(0,a.resolve)((0,
|
|
190
|
+
a.join)(__dirname,"node_modules","tsc-alias")),{prepareSingleFileReplaceTscAliasPaths:t}=f(e);w=t({configFile:v,outDir:h
|
|
191
|
+
})}return w}();for(const o of e){if(!(0,n.existsSync)(o))continue;const e=await(0,s.readFile)(o,"utf8"),r=t({
|
|
192
|
+
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 M(200)
|
|
194
|
+
;await M(100)}throw new Error("Timed out waiting for emitted dev runtime artifacts.")}();const e=(0,a.resolve)((0,
|
|
195
|
+
a.join)(__dirname,"node_modules","tsc-alias")),{replaceTscAliasPaths:t}=f(e);await t({configFile:v,outDir:h})}}catch(e){
|
|
196
|
+
return console.error(c.default.red("[Mahameru Alias] Alias rewrite failed.")),console.error(e),x||(x=!0,
|
|
191
197
|
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
|
|
198
|
+
b.delete(o),A.delete(o),void i()}const u=Date.now()-l;try{await r({durationMs:u,
|
|
193
199
|
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=`${$((0,
|
|
199
|
-
|
|
200
|
-
}(t))
|
|
200
|
+
initialBuild:!x})}catch(e){return console.error(c.default.red("[Mahameru Alias] Alias rewrite failed.")),
|
|
201
|
+
console.error(e),void i()}finally{b.delete(o),A.delete(o)}x||(x=!0,D())}function q(e,t){const o=(0,
|
|
202
|
+
a.resolve)(e),r=$(o),n=b.get(T);if(n&&function(e){const t=`${$((0,a.resolve)(g))}/`
|
|
203
|
+
;return e.startsWith(t)&&e.endsWith(".js")&&!e.endsWith(".d.ts")&&!e.endsWith(".map")}(r)){n.emittedRuntimeFiles.add(o)
|
|
204
|
+
;for(const e of function(e){if(!e)return[];const t=`${$((0,a.resolve)(y))}/`;return e.map(e=>(0,
|
|
205
|
+
a.resolve)(e.fileName)).filter(e=>{const o=$(e);return o.startsWith(t)&&o.endsWith(".ts")&&!o.endsWith(".d.ts")})
|
|
206
|
+
}(t))n.changedRuntimeSourceFiles.add(e)}}try{return await k,L}catch(e){throw L.close(),e}}({environment:e,spinner:R,
|
|
201
207
|
onBuildStart:()=>{T=!0},
|
|
202
208
|
onBuildSuccess:({durationMs:e,emittedRuntimeFiles:t,changedRuntimeSourceFiles:o,initialBuild:r})=>{if(b=e,T=!1,!r){
|
|
203
|
-
for(const e of t)D.add(e);for(const e of o)O.add(e)}T||!u?.initialized||
|
|
204
|
-
T=!1,b=0,A=!1,D.clear(),O.clear(),
|
|
205
|
-
}),
|
|
206
|
-
;const
|
|
207
|
-
|
|
209
|
+
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
|
+
T=!1,b=0,A=!1,D.clear(),O.clear(),x&&(clearTimeout(x),x=null)}
|
|
211
|
+
}),R.succeed(`${c.default.green("[Mahameru]")} Initial build completed.\n`),await u.start()
|
|
212
|
+
;const C=new l.Watchman([h,P]),N=new l.Watchman(y);let F=Promise.resolve();const I=()=>{x&&clearTimeout(x),
|
|
213
|
+
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,
|
|
208
214
|
D.clear(),
|
|
209
|
-
O.clear(),
|
|
210
|
-
await u.stop(),u=new d.App(
|
|
211
|
-
;const
|
|
212
|
-
;const l=Date.now()-
|
|
213
|
-
|
|
215
|
+
O.clear(),x=null,r)return console.log(c.default.yellow("\n [Mahameru] Config file changed. Reloading server...\n")),
|
|
216
|
+
await u.stop(),u=new d.App(k),console.clear(),void await u.start();if(0===e.length&&!o)return
|
|
217
|
+
;const n=e[e.length-1],s=t[t.length-1]??(n?S(n):(0,a.resolve)(y)),i=Date.now();o?await u.devHRM():await u.devHRM(n)
|
|
218
|
+
;const l=Date.now()-i,p=b+l;console.log(`${c.default.green("[Mahameru Dev]")} Rebuilt ${(0,
|
|
219
|
+
a.relative)(m,s).replace(/\\/g,"/")} build: ${b}ms runtime: ${l}ms total: ${p}ms`)}).catch(e=>{
|
|
214
220
|
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?
|
|
220
|
-
|
|
221
|
-
;(function(e){const t=`${$((0,
|
|
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
|
-
u.createRequire)(__filename),m=process.cwd(),h=(0,
|
|
232
|
-
|
|
233
|
-
;return(0,
|
|
221
|
+
;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)(P));if(!o.startsWith(`${r}/`)&&o!==s)return null
|
|
223
|
+
;if(o.endsWith(".d.ts")||o.endsWith(".map")||o.endsWith(".tsbuildinfo"))return null;if(o===s)return"config"
|
|
224
|
+
;if(!o.endsWith(".js"))return null;if(o.startsWith(`${n}/`))return"runtime";return null}(t)
|
|
225
|
+
;o&&("runtime"===o&&"delete"!==e&&"rename"!==e||((e,t)=>{"config"===e?E=!0:(D.add(t),O.add(S(t))),T||I()})(o,t))}),
|
|
226
|
+
N.on("all",async({event:e,filePath:t,oldFilePath:o})=>{if("delete"!==e&&"rename"!==e)return;const r="rename"===e&&o?o:t
|
|
227
|
+
;(function(e){const t=`${$((0,a.resolve)(y))}/`;return $((0,a.resolve)(e)).startsWith(t)})(r)&&(await async function(e){
|
|
228
|
+
const t=(0,a.resolve)(e),o=(0,a.relative)(y,t);if(o.startsWith(".."))return;if(/\.[^\\/]+$/.test(o)){
|
|
229
|
+
const e=function(e){const t=(0,a.relative)(y,e);return(0,a.resolve)(g,t.replace(/\.ts$/i,".js"))}(t)
|
|
230
|
+
;return void await Promise.all([(0,s.rm)(e,{force:!0}).catch(()=>{}),(0,s.rm)(`${e}.map`,{force:!0}).catch(()=>{}),(0,
|
|
231
|
+
s.rm)(e.replace(/\.js$/i,".d.ts"),{force:!0}).catch(()=>{}),(0,s.rm)(e.replace(/\.js$/i,".d.ts.map"),{force:!0
|
|
232
|
+
}).catch(()=>{})])}await(0,s.rm)((0,a.resolve)(g,o),{recursive:!0,force:!0}).catch(()=>{})}(r),A=!0,O.add((0,
|
|
233
|
+
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(),_?.close(),process.exit(e))};process.once("SIGINT",()=>{H(0)}),
|
|
235
|
+
process.once("SIGTERM",()=>{H(0)}),await new Promise(()=>{})}
|
|
236
|
+
;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
|
+
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"),P=(0,a.join)(m,"mahameru.config.ts");let w=null;function S(e){const t=(0,a.relative)(g,e)
|
|
239
|
+
;return(0,a.resolve)(y,t.replace(/\.js$/i,".ts"))}function $(e){return e.replace(/\\/g,"/")}function M(e){
|
|
234
240
|
return new Promise(t=>{setTimeout(t,e)})}},5775(e,t,o){t.deleteDirIfExists=async function(e){return await(0,r.rm)(e,{
|
|
235
241
|
recursive:!0,force:!0})},t.parsePort=function(e){const t=parseInt(e,10);return isNaN(t)?void 0:t}
|
|
236
|
-
;const r=o(1455),
|
|
242
|
+
;const r=o(1455),n=o(8161)},6469(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{
|
|
237
243
|
default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Watchman=void 0
|
|
238
|
-
;const
|
|
244
|
+
;const n=o(6261),s=o(9896),a=o(1943),i=r(o(6928)),c=/[*?[\]{}]/;class l extends n.EventEmitter{targets
|
|
239
245
|
;abortControllers=[];renameBuffer=[];bufferTimeout=null;recentEvents=new Map;constructor(e){super()
|
|
240
246
|
;const t=Array.isArray(e)?e:[e];this.targets=t.map(e=>this.createTarget(e))}async start(){this.stop()
|
|
241
247
|
;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,
|
|
248
|
+
;this.abortControllers.push(e);const{signal:o}=e;(async()=>{try{const e=(0,a.watch)(t.watchPath,{recursive:t.recursive,
|
|
243
249
|
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:
|
|
250
|
+
;const n=i.default.resolve(t.watchPath,r)
|
|
251
|
+
;this.matchesTarget(n)&&("change"!==e?"rename"===e&&this.handleRenameEvent(r,t.watchPath):this.emitEvent({
|
|
252
|
+
event:"change",filePath:n}))}}catch(e){
|
|
247
253
|
"AbortError"!==e.name&&console.error(`[Watchman] Watch error at ${t.watchPath}:`,e)}})()
|
|
248
254
|
}else console.warn("[Watchman] No files or directories matched the configured watch targets.")}stop(){
|
|
249
255
|
for(const e of this.abortControllers)e.abort();this.abortControllers=[],this.recentEvents.clear(),
|
|
250
256
|
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,
|
|
257
|
+
const t=this.normalizePath(e),o=i.default.resolve(e);if(c.test(t))return{original:e,normalized:t,absolute:o,kind:"glob"}
|
|
258
|
+
;return{original:e,normalized:t,absolute:o,kind:(0,s.existsSync)(o)&&(0,s.statSync)(o).isDirectory()?"directory":"file"}
|
|
253
259
|
}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:
|
|
260
|
+
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}`
|
|
261
|
+
;(0,s.existsSync)(r)&&(e.has(a)||e.set(a,{watchPath:r,recursive:n}))}return Array.from(e.values())}matchesTarget(e){
|
|
262
|
+
const t=this.normalizePath(i.default.resolve(e))
|
|
263
|
+
;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
264
|
}emitEvent(e){this.shouldDeduplicate(e)||(this.emit(e.event,e),this.emit("all",e))}shouldDeduplicate(e){
|
|
259
|
-
const t=this.normalizePath(
|
|
265
|
+
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
266
|
;this.recentEvents.set(o,r);for(const[e,t]of this.recentEvents)r-t>80&&this.recentEvents.delete(e)
|
|
261
|
-
;return"number"==typeof
|
|
267
|
+
;return"number"==typeof n&&r-n<=80}handleRenameEvent(e,t){this.renameBuffer.push({filename:e,timestamp:Date.now(),
|
|
262
268
|
watcherRoot:t}),this.bufferTimeout&&clearTimeout(this.bufferTimeout),this.bufferTimeout=setTimeout(()=>{
|
|
263
269
|
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,
|
|
270
|
+
fullPath:i.default.resolve(e.watcherRoot,e.filename)})).filter(e=>this.matchesTarget(e.fullPath));if(2===e.length){
|
|
271
|
+
const[t,o]=e,r=(0,s.existsSync)(t.fullPath),n=(0,s.existsSync)(o.fullPath);if(!r&&n)return void this.emitEvent({
|
|
272
|
+
event:"rename",oldFilePath:t.fullPath,filePath:o.fullPath});if(r&&!n)return void this.emitEvent({event:"rename",
|
|
273
|
+
oldFilePath:o.fullPath,filePath:t.fullPath})}for(const t of e)(0,s.existsSync)(t.fullPath)?this.emitEvent({
|
|
268
274
|
event:"create",filePath:t.fullPath}):this.emitEvent({event:"delete",filePath:t.fullPath})}getGlobBasePath(e){
|
|
269
275
|
const t=e.split("/"),o=[];for(const e of t){if(c.test(e))break;o.push(e)}
|
|
270
|
-
return 0===o.length?
|
|
276
|
+
return 0===o.length?i.default.dirname(e):o.join("/")}normalizePath(e){return e.replace(/\\/g,"/")}}t.Watchman=l},
|
|
271
277
|
846(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
272
278
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.startFork=void 0
|
|
273
|
-
;const
|
|
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)
|
|
274
280
|
;t.startFork=({rootPath:e})=>async t=>{const o=(0,d.getWindowsElevatedWorkingDirectory)()??e,r=t.port,p=t.host;(0,
|
|
275
|
-
|
|
281
|
+
a.isMahameruProjectDir)(o)||(console.error(s.default.red(`\n${o} is not a Mahameru project directory.`)),
|
|
276
282
|
process.exit(1));const f=await(0,l.getProjectJson)(o),m=(0,c.default)("Checking available port...").start(),h=await(0,
|
|
277
|
-
|
|
283
|
+
i.freePortFinder)(r);m.text="Connecting to MahameruJS PM Daemon...";const g=n.default.createConnection({
|
|
278
284
|
path:u.IPC_SOCKET_PATH},()=>{g.write(JSON.stringify({command:"FORK_PROJECT",payload:{name:f.name,
|
|
279
285
|
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
|
-
;
|
|
286
|
+
const t=JSON.parse(e.toString()),{success:o,message:r,data:n,mpmUrl:a}=t
|
|
287
|
+
;o?(!function({name:e,version:t,mode:o,host:r,port:n,pid:a,mpmUrl:i}){
|
|
288
|
+
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
|
+
;i&&c.push(`${s.default.bold("PM URL:")} ${s.default.cyan(i)}`),console.log(s.default.green("\n Project Started")),
|
|
284
290
|
c.forEach(e=>console.log(` ${e}`)),
|
|
285
|
-
console.log(`\n${
|
|
286
|
-
version:f.version,mode:"production",host:
|
|
287
|
-
m.succeed(
|
|
288
|
-
|
|
291
|
+
console.log(`\n${s.default.dim("Use `mahameru status` to inspect this managed project.")}\n`)}({name:f.name,
|
|
292
|
+
version:f.version,mode:"production",host:n.host,port:n.port,pid:n.pid,mpmUrl:a}),
|
|
293
|
+
m.succeed(s.default.green(`\n${r}`))):(m.fail(s.default.red("Failed to start project!")),console.error(t)),g.end(),
|
|
294
|
+
process.exit(0)}),g.on("error",e=>{
|
|
295
|
+
"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
296
|
if(!(0,d.hasWindowsElevationRetry)()&&!(0,d.isWindowsProcessElevated)()){
|
|
290
|
-
e.warn(
|
|
297
|
+
e.warn(s.default.yellow("\nWindows blocked access to the Mahameru PM pipe. Requesting Administrator approval..."))
|
|
291
298
|
;const o=(0,d.relaunchCurrentProcessAsAdmin)(t)
|
|
292
|
-
;o.ok&&(console.log(
|
|
293
|
-
console.log(
|
|
294
|
-
console.log(
|
|
299
|
+
;o.ok&&(console.log(s.default.cyan("An Administrator PowerShell window has been launched for the elevated retry.")),
|
|
300
|
+
console.log(s.default.dim(`The elevated retry will run from: ${t}`)),
|
|
301
|
+
console.log(s.default.dim("Keep that window open to see whether `mahameru start` succeeds or why it fails.")),
|
|
295
302
|
process.exit(0))
|
|
296
303
|
;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(
|
|
304
|
+
;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.`)),
|
|
305
|
+
o.errorText&&console.error(s.default.dim(o.errorText)),process.exit(1)}
|
|
306
|
+
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
|
+
console.log(s.default.dim("Check the visible Administrator PowerShell window for the detailed failure output.")),
|
|
308
|
+
process.exit(1)}(m,o):(m.fail(s.default.red(`\n${e.message}`)),console.error(e)),process.exit(1)})}},1471(e,t,o){
|
|
302
309
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
303
310
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.startService=void 0
|
|
304
|
-
;const
|
|
311
|
+
;const n=o(6921),s=o(1421),a=o(3024),i=o(6760),c=r(o(5205));t.startService=e=>()=>{
|
|
305
312
|
const t="linux"===process.platform,o="win32"===process.platform,r=`/etc/systemd/system/${e}.service`;try{if(t){
|
|
306
313
|
if(process.getuid&&0!==process.getuid())throw new Error("This action requires root privileges. Please run with sudo.")
|
|
307
314
|
;if(!(0,
|
|
308
|
-
|
|
315
|
+
a.existsSync)(r))throw new Error(`Service "${e}" is not registered on this system. Please run "mahameru pm service install" first.`)
|
|
309
316
|
;console.log(c.default.cyan(`🔍 Checking status for service: ${e}...`));let t=!1;try{"active"===(0,
|
|
310
|
-
|
|
317
|
+
s.execSync)(`systemctl is-active ${e}`,{stdio:["ignore","pipe","ignore"]}).toString().trim()&&(t=!0)}catch{t=!1}
|
|
311
318
|
t?console.log(c.default.yellow(`⚠️ Service "${e}" is already running.`)):(console.log(c.default.cyan(`🚀 Starting ${e}...`)),
|
|
312
|
-
(0,
|
|
319
|
+
(0,s.execSync)(`systemctl start ${e}`),console.log(c.default.green(`\n🚀 ${e} has been successfully started.`)),
|
|
313
320
|
console.log(`📝 To check service status, run: ${c.default.bold(`systemctl status ${e}`)}`))
|
|
314
321
|
}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,
|
|
322
|
+
i.join)(n.APPDATA_PATH," winsw",`${e}.exe`);if((0,a.existsSync)(t))return(0,s.execSync)(`"${t}" start`,{
|
|
323
|
+
cwd:n.APPDATA_PATH}),void console.log(c.default.green(`✔ Success: Service "${e}" has been started.`))
|
|
324
|
+
;console.log(c.default.yellow("WinSW binary not found. Falling back to sc.exe...")),(0,s.execSync)(`sc start "${e}"`),
|
|
318
325
|
console.log(c.default.green(`✔ Success: Service "${e}" has been started via sc.exe.`))}catch(e){
|
|
319
326
|
console.error(c.default.red(`❌ Error: Failed to start service: ${e.message}`)),
|
|
320
327
|
console.error("Make sure you are running CMD/PowerShell as an Administrator and the service is installed.")}}({
|
|
@@ -322,73 +329,73 @@ serviceName:e}):console.log(c.default.red("❌ Unsupported platform."))}catch(e)
|
|
|
322
329
|
console.error(c.default.red("❌ Failed to start service:"),e.message)}}},7695(e,t,o){
|
|
323
330
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
324
331
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.projectStatus=void 0
|
|
325
|
-
;const
|
|
332
|
+
;const n=r(o(7030)),s=o(4830),a=r(o(8720)),i=r(o(5205)),c=o(3157),l=o(6921)
|
|
326
333
|
;t.projectStatus=(e,t)=>async({host:o,port:r})=>{try{
|
|
327
|
-
console.log(`${
|
|
334
|
+
console.log(`${i.default.bold(i.default.cyan("▲ Mahameru"))} ${i.default.dim(`CLI v${t}`)}\n`);const o=(0,
|
|
328
335
|
c.getWindowsElevatedWorkingDirectory)()??e,r=await(0,
|
|
329
|
-
|
|
336
|
+
s.getProjectJson)(o),d=(0,a.default)("Checking available port...").start(),u=n.default.createConnection({
|
|
330
337
|
path:l.IPC_SOCKET_PATH},()=>{u.write(JSON.stringify({command:"STATUS",payload:{name:r.name}}))});u.on("data",e=>{
|
|
331
338
|
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${
|
|
339
|
+
;t?(d.succeed(i.default.green("\nManaged project status loaded.")),function(e){
|
|
340
|
+
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}`]
|
|
341
|
+
;console.log(i.default.cyan("\n Project Status")),r.forEach(e=>console.log(` ${e}`)),
|
|
342
|
+
console.log(`\n${i.default.dim(`Created at: ${e.createdAt}`)}\n`)}(r)):d.fail(`${i.default.red("[Mahameru]")} ${o}`),
|
|
336
343
|
process.exit(0)}),u.on("error",e=>{"win32"===process.platform&&"EPERM"===e.code?function(e,t){if(!(0,
|
|
337
344
|
c.hasWindowsElevationRetry)()&&!(0,c.isWindowsProcessElevated)()){
|
|
338
|
-
e.warn(
|
|
345
|
+
e.warn(i.default.yellow("\nWindows blocked access to the Mahameru PM pipe. Requesting Administrator approval..."))
|
|
339
346
|
;const o=(0,c.relaunchCurrentProcessAsAdmin)(t)
|
|
340
|
-
;o.ok&&(console.log(
|
|
341
|
-
console.log(
|
|
342
|
-
console.log(
|
|
347
|
+
;o.ok&&(console.log(i.default.cyan("An Administrator PowerShell window has been launched for the elevated retry.")),
|
|
348
|
+
console.log(i.default.dim(`The elevated retry will run from: ${t}`)),
|
|
349
|
+
console.log(i.default.dim("Keep that window open to see the managed project status or why it failed.")),process.exit(0))
|
|
343
350
|
;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(
|
|
351
|
+
;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.`)),
|
|
352
|
+
o.errorText&&console.error(i.default.dim(o.errorText)),process.exit(1)}
|
|
353
|
+
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)}.`)),
|
|
354
|
+
console.log(i.default.dim("Check the visible Administrator PowerShell window for the detailed failure output.")),
|
|
348
355
|
process.exit(1)
|
|
349
|
-
}(d,o):"ENOENT"===e.code||"ECONNREFUSED"===e.code?d.fail(
|
|
356
|
+
}(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
357
|
console.error(e)),process.exit(1)})}catch(e){console.error(e),process.exit(1)}}},7659(e,t,o){
|
|
351
358
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
352
359
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.status=void 0
|
|
353
|
-
;const
|
|
360
|
+
;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
361
|
console.log(`${l.default.bold(l.default.cyan("▲ Mahameru"))} ${l.default.dim(`Process Manager Status v${t}`)}`),
|
|
355
362
|
console.log("---------------+---------------------------------------------------");for(const[t,o]of Object.entries(e)){
|
|
356
363
|
const e=t.padEnd(14," ");console.log(` ${e} | ${o}`)}
|
|
357
364
|
console.log("---------------+---------------------------------------------------")}t.status=(e,t)=>()=>{
|
|
358
365
|
const o="linux"===process.platform,r="win32"===process.platform,u=`/etc/systemd/system/${e}.service`;let p="";try{p=(0,
|
|
359
|
-
|
|
366
|
+
s.getNodeModulesPath)()}catch(e){return void console.error(l.default.red(`❌ ${e.message}`))}const f=(0,
|
|
360
367
|
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,
|
|
368
|
+
"Memory Usage":"N/A","CPU Usage":"N/A"};if(!(0,i.existsSync)(u))return o.Installed=l.default.red("Not Installed"),
|
|
362
369
|
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,
|
|
370
|
+
a.execSync)(`systemctl show ${e} --property=ActiveState`,{stdio:["ignore","pipe","ignore"]
|
|
371
|
+
}).toString().trim().split("=")[1],r=(0,a.execSync)(`systemctl show ${e} --property=SubState`,{
|
|
365
372
|
stdio:["ignore","pipe","ignore"]
|
|
366
|
-
}).toString().trim().split("=")[1],
|
|
373
|
+
}).toString().trim().split("=")[1],n=(0,a.execSync)(`systemctl show ${e} --property=MainPID`,{
|
|
367
374
|
stdio:["ignore","pipe","ignore"]}).toString().trim().split("=")[1];if("active"===t){
|
|
368
|
-
o.State=l.default.green(`${t} (${r})`),o["Main Process"]=
|
|
369
|
-
|
|
375
|
+
o.State=l.default.green(`${t} (${r})`),o["Main Process"]=n&&"0"!==n?n:"N/A";try{const t=(0,
|
|
376
|
+
a.execSync)(`systemctl show ${e} --property=MemoryCurrent`,{stdio:["ignore","pipe","ignore"]
|
|
370
377
|
}).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,
|
|
378
|
+
;o["Memory Usage"]=`${e} MB`}}catch{}try{const e=(0,a.execSync)(`ps -p ${n} -o %cpu`,{stdio:["ignore","pipe","ignore"]
|
|
372
379
|
}).toString().trim().split("\n")[1];e&&(o["CPU Usage"]=`${e.trim()}%`)}catch{}
|
|
373
380
|
}else o.State="failed"===t?l.default.red(`${t} (${r})`):l.default.yellow(`${t} (${r})`)}catch(e){
|
|
374
381
|
o.State=l.default.red("Unknown (Error reading systemctl)")}d(o,t),function(e){try{const t=(0,
|
|
375
|
-
|
|
382
|
+
i.readFileSync)(e,"utf-8").match(/StandardError=append:(.+)/);if(t&&t[1]){const e=t[1].trim();if((0,i.existsSync)(e)){
|
|
376
383
|
console.log(l.default.bold(l.default.yellow(`\n📝 Last 3 lines from error log (${e}):`)));const t=(0,
|
|
377
|
-
|
|
384
|
+
i.readFileSync)(e,"utf-8").trim().split("\n").slice(-3)
|
|
378
385
|
;t.length>0&&""!==t[0]?t.forEach(e=>console.log(` ${l.default.dim(e)}`)):console.log(l.default.dim(" (Log file is empty)")),
|
|
379
386
|
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
|
-
|
|
387
|
+
if("win32"===process.platform)try{const r=(0,c.join)(n.APPDATA_PATH,"winsw",`${e}.exe`),s=(0,
|
|
388
|
+
c.join)(n.APPDATA_PATH,"winsw",`${e}.xml`);let d=null,u=null;if((0,i.existsSync)(s))try{const e=(0,
|
|
389
|
+
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
390
|
}catch(e){}const p=()=>{d&&console.log(`Host : ${l.default.cyan(d)}`),
|
|
384
391
|
u&&console.log(`Port : ${l.default.cyan(u)}`),
|
|
385
|
-
u&&d&&console.log(`URL : ${l.default.cyan(`http://${d}:${u}`)}`)};if((0,
|
|
386
|
-
|
|
392
|
+
u&&d&&console.log(`URL : ${l.default.cyan(`http://${d}:${u}`)}`)};if((0,i.existsSync)(r))try{const e=(0,
|
|
393
|
+
a.execSync)(`"${r}" status`,{cwd:t}).toString().trim()
|
|
387
394
|
;return console.log(`\n${l.default.bold(l.default.cyan("▲ Mahameru"))} ${l.default.dim(`Process Manager Status v${o}`)}\n`),
|
|
388
395
|
void("NonExistent"===e?(console.log(`Installation status : ${l.default.red("Not Installed (NonExistent)")}`),
|
|
389
396
|
console.log(`Service Status : ${l.default.red("-")}`)):(console.log(`Installation status : ${l.default.green("Installed")}`),
|
|
390
397
|
"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,
|
|
398
|
+
p()))}catch(e){}try{const t=(0,a.execSync)(`sc query "${e}"`,{stdio:["pipe","pipe","ignore"]}).toString()
|
|
392
399
|
;console.log(`\n${l.default.bold(l.default.cyan("▲ Mahameru"))} ${l.default.dim(`Process Manager Status v${o}`)}\n`),
|
|
393
400
|
console.log(`Installation status : ${l.default.green("Installed")}`),
|
|
394
401
|
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 +409,29 @@ mahameruInstalationPath:f,version:t}):console.log(l.default.red("❌ Unsupported
|
|
|
402
409
|
console.error(l.default.red("❌ Failed to retrieve service status:"),e.message)}}},2074(e,t,o){
|
|
403
410
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
404
411
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.stopFork=void 0
|
|
405
|
-
;const
|
|
406
|
-
console.log(`${
|
|
407
|
-
|
|
412
|
+
;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{
|
|
413
|
+
console.log(`${i.default.bold(i.default.cyan("▲ Mahameru"))} ${i.default.dim(`CLI v${t}`)}\n`);const o=await(0,
|
|
414
|
+
s.getProjectJson)(e),r=(0,a.default)("Checking available port...").start(),l=n.default.createConnection({
|
|
408
415
|
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(
|
|
416
|
+
const{success:t,message:o,data:n}=JSON.parse(e.toString())
|
|
417
|
+
;t?console.log(n):r.fail(`${i.default.red("[Mahameru]")} ${o}`),process.exit(0)})}catch(e){console.error(e),
|
|
411
418
|
process.exit(1)}}},5019(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
412
419
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.stopService=void 0
|
|
413
|
-
;const
|
|
420
|
+
;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
421
|
const o="linux"===process.platform,r="win32"===process.platform,d=`/etc/systemd/system/${e}.service`;let u="";try{u=(0,
|
|
415
|
-
|
|
422
|
+
s.getNodeModulesPath)()}catch(e){return void console.error(l.default.red(`❌ ${e.message}`))}const p=(0,
|
|
416
423
|
c.join)(u,"@mahameru","cli");try{if(o){
|
|
417
424
|
if(process.getuid&&0!==process.getuid())throw new Error("This action requires root privileges. Please run with sudo.")
|
|
418
|
-
;if(!(0,
|
|
425
|
+
;if(!(0,i.existsSync)(d))throw new Error(`Service "${e}" is not registered on this system.`)
|
|
419
426
|
;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,
|
|
427
|
+
a.execSync)(`systemctl is-active ${e}`,{stdio:["ignore","pipe","ignore"]}).toString().trim()&&(t=!0)}catch{t=!1}
|
|
428
|
+
t?(console.log(l.default.yellow(`🛑 Service is active. Stopping ${e}...`)),(0,a.execSync)(`systemctl stop ${e}`),
|
|
422
429
|
console.log(l.default.green(`\n🛑 ${e} has been successfully stopped.`))):console.log(l.default.yellow(`⚠️ Service "${e}" is already stopped.`))
|
|
423
430
|
}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,
|
|
431
|
+
console.log(`Attempting to stop service: ${l.default.cyan(e)}...`);const o=(0,c.join)(n.APPDATA_PATH,"winsw",`${e}.exe`)
|
|
432
|
+
;if((0,i.existsSync)(o))return(0,a.execSync)(`"${o}" stop`,{cwd:t
|
|
426
433
|
}),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,
|
|
434
|
+
;console.log(l.default.yellow("WinSW binary not found. Falling back to sc.exe...")),(0,a.execSync)(`sc stop "${e}"`),
|
|
428
435
|
console.log(l.default.green(`✔ Success: Service "${e}" has been stopped via sc.exe.`))}catch(e){
|
|
429
436
|
console.error(l.default.red(`❌ Error: Failed to stop service: ${e.message}`)),
|
|
430
437
|
console.error("Make sure you are running CMD/PowerShell as an Administrator.")}}({serviceName:e,
|
|
@@ -432,47 +439,47 @@ mahameruInstalationPath:p}):console.log(l.default.red("❌ Unsupported platform.
|
|
|
432
439
|
console.error(l.default.red("❌ Failed to stop service:"),e.message)}}},6571(e,t,o){
|
|
433
440
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
434
441
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.uninstall=void 0
|
|
435
|
-
;const
|
|
442
|
+
;const n=o(6921),s=o(1421),a=o(3024),i=o(6760),c=r(o(5205));t.uninstall=e=>()=>{
|
|
436
443
|
const t="linux"===process.platform,o="win32"===process.platform,r=`/etc/systemd/system/${e}.service`;try{if(t){
|
|
437
444
|
if(process.getuid&&0!==process.getuid())throw new Error("This action requires root privileges. Please run with sudo.")
|
|
438
|
-
;if(!(0,
|
|
445
|
+
;if(!(0,a.existsSync)(r))throw new Error(`Service "${e}" was not found or is not registered on this system.`)
|
|
439
446
|
;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,
|
|
447
|
+
s.execSync)(`systemctl is-active ${e}`,{stdio:["ignore","pipe","ignore"]}).toString().trim()&&(t=!0)}catch{t=!1}
|
|
448
|
+
t&&(console.log(c.default.yellow(`🛑 Service is running. Stopping ${e}...`)),(0,s.execSync)(`systemctl stop ${e}`)),
|
|
449
|
+
console.log(c.default.cyan("🔄 Disabling service..."));try{(0,s.execSync)(`systemctl disable ${e}`,{
|
|
443
450
|
stdio:["ignore","pipe","ignore"]})}catch{}console.log(c.default.cyan(`🗑️ Removing service file from ${r}...`)),(0,
|
|
444
|
-
|
|
451
|
+
s.execSync)(`rm ${r}`),(0,s.execSync)("systemctl daemon-reload"),(0,s.execSync)("systemctl reset-failed"),
|
|
445
452
|
console.log(c.default.green(`\n🚀 ${e} successfully uninstalled!`))}else if(o){
|
|
446
|
-
console.log("Deleting Windows Service...");const t=(0,
|
|
447
|
-
|
|
448
|
-
cwd:
|
|
453
|
+
console.log("Deleting Windows Service...");const t=(0,i.join)(n.APPDATA_PATH,"winsw",`${e}.exe`);if((0,
|
|
454
|
+
a.existsSync)(t)){try{(0,s.execSync)(`"${t}" stop`,{cwd:n.APPDATA_PATH})}catch(e){}(0,s.execSync)(`"${t}" uninstall`,{
|
|
455
|
+
cwd:n.APPDATA_PATH}),console.log(`Sukses: Service "${e}" berhasil di-uninstall.`),
|
|
449
456
|
console.log(c.default.green("✔ Mahameru Process Manager successfully uninstalled."))}else{
|
|
450
457
|
console.log(c.default.yellow("Cannot found WinSW binary. Fallback to sc delete..."));try{(0,
|
|
451
|
-
|
|
452
|
-
(0,
|
|
458
|
+
s.execSync)(`sc stop "${e}"`)}catch(e){}
|
|
459
|
+
(0,s.execSync)(`sc delete "${e}"`),console.log(c.default.green(`✔ "${e}" successfully uninstalled.`))}
|
|
453
460
|
}else console.log(c.default.red("❌ Unsupported platform."))}catch(e){
|
|
454
461
|
console.error(c.default.red("❌ Uninstallation failed:"),e.message)}}},8625(e,t,o){
|
|
455
462
|
var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
456
463
|
;Object.defineProperty(t,"__esModule",{value:!0})
|
|
457
|
-
;const
|
|
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),P=new n.Command
|
|
458
465
|
;(async()=>{try{const e=process.cwd(),t="mahameru-pm"
|
|
459
|
-
;P.name("mahameru").description(`${
|
|
466
|
+
;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
467
|
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
|
-
|
|
468
|
+
i.dev)({version:a.version})),P.command("build").description("Build MahameruJS production application.").action((0,
|
|
462
469
|
c.build)({rootPath:e
|
|
463
470
|
})),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
471
|
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(`${
|
|
472
|
+
v.stopFork)(e,a.version)),P.command("status").description("View MahameruJS production server status.").action((0,
|
|
473
|
+
y.projectStatus)(e,a.version))
|
|
474
|
+
;const o=P.command("pm").description(`${s.default.bold(s.default.cyan("▲ MahameruJS"))} ${s.default.dim(`Process Manager v${a.version}`)}`)
|
|
468
475
|
;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)(
|
|
476
|
+
u.pm)(a.version)),
|
|
470
477
|
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(
|
|
478
|
+
console.log(s.default.bold(s.default.cyan(`▲ MahameruJS Process Manager\n\n Not ${s.default.yellow("Not implemented yet.")}`)))
|
|
472
479
|
}),o.on("command:*",e=>{const t=e[0]
|
|
473
|
-
;["install","uninstall","start","stop"].includes(t)&&(console.log(
|
|
480
|
+
;["install","uninstall","start","stop"].includes(t)&&(console.log(s.default.yellow(`\n⚠ Did you mean 'mahameru pm service ${t}'?\n`)),
|
|
474
481
|
r.outputHelp(),process.exit(1))})
|
|
475
|
-
;const r=o.command("service").description(`${
|
|
482
|
+
;const r=o.command("service").description(`${s.default.bold(s.default.cyan("▲ MahameruJS"))} ${s.default.dim(`Process Manager Service v${a.version}`)}`)
|
|
476
483
|
;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
484
|
d.install)(t)),
|
|
478
485
|
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 +487,7 @@ p.uninstall)(t)),r.command("start").description("Start MahameruJS Process Manage
|
|
|
480
487
|
f.startService)(t)),
|
|
481
488
|
r.command("stop").description("Stop MahameruJS Process Manager service.").option("-g, --graceful","Gracefully stop the service.",!1).action((0,
|
|
482
489
|
m.stopService)(t)),r.command("status").description("Get MahameruJS Process Manager status.").action((0,
|
|
483
|
-
h.status)(t,
|
|
490
|
+
h.status)(t,a.version)),await P.parseAsync(process.argv)}catch(e){console.error(e),process.exit(1)}})()},6921(e,t,o){
|
|
484
491
|
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
492
|
;"darwin"===process.platform||"win32"===process.platform||process.platform,t.IS_WINDOWS="win32"===process.platform,
|
|
486
493
|
t.vL="darwin"===process.platform,t.ig="linux"===process.platform,t.Ds="mahameru",t.APPDATA_PATH=(()=>{
|
|
@@ -489,25 +496,25 @@ if(t.IS_WINDOWS)return(0,r.join)(process.env.APPDATA,t.Ds)
|
|
|
489
496
|
;throw new Error("Unsupported platform")})(),t.PROJECTS_FILE_PATH=(0,r.join)(t.APPDATA_PATH,"projects.json"),
|
|
490
497
|
t.MQ="mpm_ipc",t.IPC_SOCKET_PATH="win32"===process.platform?`\\\\.\\pipe\\${t.MQ}`:`/tmp/${t.MQ}.sock`},5043(e,t,o){
|
|
491
498
|
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
|
-
}),
|
|
499
|
+
;var n=Object.getOwnPropertyDescriptor(t,o);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,
|
|
500
|
+
get:function(){return t[o]}}),Object.defineProperty(e,r,n)}:function(e,t,o,r){void 0===r&&(r=o),e[r]=t[o]
|
|
501
|
+
}),n=this&&this.__exportStar||function(e,t){
|
|
495
502
|
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}),
|
|
503
|
+
;Object.defineProperty(t,"__esModule",{value:!0}),n(o(3602),t),n(o(7258),t)},3602(e,t,o){
|
|
504
|
+
var r,n=this&&this.__createBinding||(Object.create?function(e,t,o,r){void 0===r&&(r=o)
|
|
505
|
+
;var n=Object.getOwnPropertyDescriptor(t,o);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,
|
|
506
|
+
get:function(){return t[o]}}),Object.defineProperty(e,r,n)}:function(e,t,o,r){void 0===r&&(r=o),e[r]=t[o]
|
|
507
|
+
}),s=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,
|
|
508
|
+
value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(r=function(e){
|
|
502
509
|
return r=Object.getOwnPropertyNames||function(e){var t=[]
|
|
503
510
|
;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
|
|
511
|
+
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
|
+
;return s(t,e),t}),i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
506
513
|
;Object.defineProperty(t,"__esModule",{value:!0}),t.processManager=void 0
|
|
507
|
-
;const c=
|
|
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)),P=o(4437),w=(0,
|
|
508
515
|
d.join)(__dirname,"mpm"),S={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",
|
|
509
516
|
".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:
|
|
517
|
+
;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
518
|
if(t.setHeader("Access-Control-Allow-Origin","*"),
|
|
512
519
|
t.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),
|
|
513
520
|
t.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization"),t.setHeader("X-Powered-By","MahameruJS"),
|
|
@@ -521,130 +528,137 @@ v.default.createReadStream(r).pipe(t)}{const e=(0,d.join)(w,"index.html")
|
|
|
521
528
|
t.end("<h1>404 - Frontend Build Not Found</h1>")):(t.writeHead(200,{"Content-Type":"text/html"}),
|
|
522
529
|
v.default.createReadStream(e).pipe(t)))}}):(t.writeHead(403,{"Content-Type":"text/plain"}),t.end("Forbidden"))}
|
|
523
530
|
return t.writeHead(404,{"Content-Type":"text/html"}),t.end("<h1>404 Not Found</h1>")
|
|
524
|
-
},
|
|
531
|
+
},M=()=>console.log("[MPM] HTTP server closed."),_=e=>console.log("[MPM] HTTP server error:",e),j=async()=>{
|
|
525
532
|
process.send||r||(console.clear(),
|
|
526
|
-
console.log(`${c.default.bold(c.default.cyan("▲ Mahameru"))} ${c.default.dim(`Process Manager v${
|
|
533
|
+
console.log(`${c.default.bold(c.default.cyan("▲ Mahameru"))} ${c.default.dim(`Process Manager v${a}`)}\n`)),
|
|
527
534
|
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",
|
|
535
|
+
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
|
+
;const o=await(0,h.loadProjects)();for(const e of o)e.isLastStatusIsRunning&&await U(e)},x=n&&s,E=n&&s?(0,
|
|
537
|
+
f.createServer)({cert:v.default.readFileSync(n),key:v.default.readFileSync(s)
|
|
538
|
+
},$).on("close",M).on("error",_).listen(i,e,j):(0,p.createServer)($).on("close",M).on("error",_).listen(i,e,j)
|
|
532
539
|
;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
540
|
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"===
|
|
541
|
+
;console.error(`[${e} ERROR] ${o}`)},b=(o,r,n)=>({type:s,data:a})=>{if(o)if("ERROR"===s)o.write(JSON.stringify({
|
|
542
|
+
success:!1,message:a
|
|
543
|
+
}));else if("READY"===s)console.log(`[MPM] Project${r} successfully started by PM Daemon (PID: ${n.pid})`),
|
|
544
|
+
o.write(JSON.stringify({success:!0,message:`Project ${r} successfully started by PM Daemon (PID: ${n.pid})`,data:a,
|
|
545
|
+
mpmUrl:`http://${e}:${t}`}));else if("PROCESS_USAGE"===s){const e=(0,h.getProject)(r);e&&z.emit("process-usage",{data:a,
|
|
539
546
|
project:(0,g.parseProject)(e)})}},D=e=>t=>{console.log(`[MPM] Project ${e} errored: ${t.message}`)},O=e=>({success:!0,
|
|
540
547
|
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`)
|
|
548
|
+
console.log(`[MPM] ${e}`)},F=()=>{z.emit("projects",C())},I=e=>{
|
|
549
|
+
const t=(0,d.join)(e.rootPath,"node_modules","mahameru","server.js")
|
|
550
|
+
;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
551
|
;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()
|
|
552
|
+
MAHAMERU__MODE:"production",...e.host?{MAHAMERU__HTTP_LISTEN_HOST:e.host}:{},...e.port?{
|
|
553
|
+
MAHAMERU__HTTP_LISTEN_PORT:e.port.toString()}:{}}),W=(e,t,o=null)=>{t.stdout?.on("data",T(e.name)),
|
|
547
554
|
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
555
|
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=>{
|
|
556
|
+
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))
|
|
557
|
+
};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,
|
|
558
|
+
l.fork)(n,[],{cwd:e.rootPath,env:{...process.env,...H(e)},stdio:["inherit","pipe","pipe","ipc"]});e.status="stopped",
|
|
559
|
+
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(()=>{
|
|
560
|
+
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(()=>{
|
|
561
|
+
r(`[MPM] ${n.message}`)})}),a.once("error",t=>{s(()=>{e.status="errored",e.pid=void 0,e.child=void 0,(0,
|
|
562
|
+
h.setProject)(e),r(t)})}),a.once("exit",t=>{s(()=>{e.status=0===t||null===t?"stopped":"errored",e.pid=void 0,
|
|
563
|
+
e.child=void 0,
|
|
564
|
+
(0,h.setProject)(e),r(new Error(`Project ${e.name} exited before ready${"number"==typeof t?` with code ${t}`:""}`))})})
|
|
565
|
+
}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)=>{
|
|
566
|
+
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=>{
|
|
567
|
+
n||(n=!0,e())};J(r,["SHUTDOWN_DONE"]).then(({type:o})=>{"SHUTDOWN_DONE"===o&&s(()=>{e.status="stopped",e.pid=void 0,
|
|
568
|
+
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,
|
|
569
|
+
h.setProject)(e),o(t)})}),r.once("exit",r=>{s(()=>{e.status=0===r||null===r?"stopped":"errored",e.pid=void 0,
|
|
563
570
|
e.child=void 0,
|
|
564
571
|
(0,h.setProject)(e),0!==r&&null!==r?o(new Error(`Project ${e.name} exited during shutdown with code ${r}`)):t(e)})}),
|
|
565
572
|
r.send({type:"SHUTDOWN"})}),B=async e=>{N(`Delete requested for project "${e}"`);const t=(0,h.getProject)(e)
|
|
566
573
|
;if(!t)throw N(`Delete aborted. Project "${e}" not found`),new Error("Project not found");const o=k(t)
|
|
567
574
|
;t.child?(N(`Project "${e}" is running. Stopping before delete`),await L(t)):(t.status="stopped",t.pid=void 0,
|
|
568
575
|
t.child=void 0,(0,h.setProject)(t),N(`Project "${e}" already stopped. Proceeding to delete`));const r=(0,
|
|
569
|
-
h.getProject)(e),
|
|
576
|
+
h.getProject)(e),n=r?k(r):o;return N(`Deleting project "${e}" from registry`),(0,h.deleteProject)(e),
|
|
570
577
|
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:
|
|
578
|
+
z.emit("project-delete",n),F(),n},q=u.default.createServer(e=>{e.on("data",t=>{try{const o=JSON.parse(t.toString())
|
|
579
|
+
;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
580
|
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?
|
|
581
|
+
status:"error",message:"Project already running"}));console.log(`[MPM] Starting project: ${r} (${a})`);const d={
|
|
582
|
+
pid:void 0,createdAt:l?.createdAt??(new Date).toISOString(),isDisabled:!1,name:r,mode:"production",description:n,
|
|
583
|
+
version:s,rootPath:a,host:c,port:i,status:"stopped"};(0,h.setProject)(d),U(d,e).then(e=>{
|
|
584
|
+
l?z.emit("project-update",k(e)):z.emit("project-create",k(e)),F()}).catch(t=>{e.write(JSON.stringify({success:!1,
|
|
578
585
|
error:t.message}))})}else if("STOP"===o.command){const t=o.payload,r=(0,h.getProject)(t.name)
|
|
579
586
|
;if(!r)return void e.write(JSON.stringify({success:!1,error:"Project not found"}));L(r).then(t=>{
|
|
580
|
-
|
|
587
|
+
z.emit("project-update",k(t)),F(),e.write(JSON.stringify(O(k(t))))}).catch(t=>{e.write(JSON.stringify(R(t.message)))})
|
|
581
588
|
}else if("START"===o.command);else if("RESTART"===o.command);else if("STATUS"===o.command){const t=o.payload,r=(0,
|
|
582
589
|
h.getProject)(t.name);if(r){const{child:t,...o}=r;e.write(JSON.stringify({success:!0,data:o}))
|
|
583
590
|
}else e.write(JSON.stringify({success:!1,error:"Project not found"}))}}catch(t){e.write(JSON.stringify({success:!1,
|
|
584
591
|
error:t.message}))}})});q.on("close",()=>{console.log("[MPM IPC SERVER] IPC Server closed")}),q.on("error",e=>{
|
|
585
592
|
"EADDRINUSE"===e.code?console.error(`[MPM IPC SERVER] IPC Server already running on ${m.IPC_SOCKET_PATH}`):console.error("[MPM IPC SERVER]",e),
|
|
586
593
|
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});
|
|
594
|
+
console.log(`[MPM IPC SERVER] IPC Server listening on ${m.IPC_SOCKET_PATH}`)});const z=new P.Server(E,{cors:{origin:"*"
|
|
595
|
+
},path:"/ws",serveClient:!1});z.on("connection",e=>{(0,h.setSocket)(e);const t=(0,h.getProjects)().map(g.parseProject)
|
|
589
596
|
;e.emit("projects",t),e.on("getProjects",e=>e({success:!0,data:(0,h.getProjects)().map(g.parseProject)})),
|
|
590
597
|
e.on("start",(e,t)=>{const o=(0,h.getProject)(e)
|
|
591
598
|
;return o?o.child||"running"===o.status?t(R(`Project ${e} is already running`)):void U(o).then(e=>{
|
|
592
|
-
|
|
599
|
+
z.emit("project-update",k(e)),F(),t(O(k(e)))}).catch(e=>{t(R(e.message))}):t(R("Project not found"))}),
|
|
593
600
|
e.on("stop",(e,t)=>{const o=(0,h.getProject)(e);if(!o)return t(R("Project not found"));L(o).then(e=>{
|
|
594
|
-
|
|
601
|
+
z.emit("project-update",k(e)),F(),t(O(k(e)))}).catch(e=>{t(R(e.message))})});const o=e=>(t,o)=>{
|
|
595
602
|
N(`Socket event "${e}" received for project "${t}"`),B(t).then(e=>{N(`Invoking delete callback for project "${t}"`),
|
|
596
603
|
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(),
|
|
604
|
+
e.on("remove",o("remove")),e.on("disconnect",()=>{(0,h.deleteSocket)(e.id)})});const G=async e=>{
|
|
605
|
+
console.log(`[MPM] Received ${e}`),await(0,h.saveProjects)(),(0,h.getSockets)().forEach(e=>e.disconnect()),z.close(),
|
|
606
|
+
q.close(),E.close(e=>{e&&console.log("[MPM]",e),process.exit(0)})};process.on("SIGINT",G),process.on("SIGTERM",G)
|
|
600
607
|
}catch(e){console.log("mpm error",e),process.exit(1)}}},7258(e,t,o){Object.defineProperty(t,"__esModule",{value:!0}),
|
|
601
608
|
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),
|
|
609
|
+
;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
610
|
;t.getProject=e=>c.get(e);t.setProject=e=>(c.set(e.name,e),e);t.setProjects=e=>e.forEach(t.setProject)
|
|
604
611
|
;t.deleteProject=e=>c.delete(e);t.clearProjects=()=>c.clear();const l=new Map;t.getSockets=()=>Array.from(l.values())
|
|
605
612
|
;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
|
-
|
|
613
|
+
;t.loadProjects=async()=>{try{if((0,r.existsSync)((0,n.dirname)(a.PROJECTS_FILE_PATH))||await(0,s.mkdir)((0,
|
|
614
|
+
n.dirname)(a.PROJECTS_FILE_PATH),{recursive:!0}),!(0,r.existsSync)(a.PROJECTS_FILE_PATH))return await(0,
|
|
615
|
+
s.writeFile)(a.PROJECTS_FILE_PATH,"[]","utf-8"),[];const e=await(0,s.readFile)(a.PROJECTS_FILE_PATH,"utf-8")
|
|
609
616
|
;return JSON.parse(e)}catch(e){throw new Error("Failed to load projects")}};t.saveProjects=async()=>{try{const e=(0,
|
|
610
617
|
t.getProjects)().map(e=>({...e,child:void 0,pid:void 0,isLastStatusIsRunning:"running"===e.status
|
|
611
|
-
})).map(
|
|
618
|
+
})).map(i.parseProject),o=JSON.stringify(e);await(0,s.writeFile)(a.PROJECTS_FILE_PATH,o,"utf-8")}catch(e){
|
|
612
619
|
throw new Error("Failed to save projects")}}},7209(e,t,o){var r=this&&this.__importDefault||function(e){
|
|
613
620
|
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
|
|
621
|
+
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
622
|
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
|
|
623
|
+
const r=n.default.createServer();r.once("error",e=>{e.code,o(!1)}),r.once("listening",()=>{r.close(()=>t(!0))}),
|
|
624
|
+
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
625
|
;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),
|
|
626
|
+
t.getProjectJson=async function(e){try{return JSON.parse(await(0,r.readFile)((0,n.join)(e,"package.json"),"utf-8"))
|
|
627
|
+
}catch(e){throw new Error("package.json not found")}};const r=o(1455),n=o(6760)},6718(e,t,o){
|
|
621
628
|
t.getNodeModulesPath=function(){try{return(0,r.execSync)("npm root -g",{stdio:["ignore","pipe","ignore"]
|
|
622
629
|
}).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
|
-
|
|
630
|
+
;const r=o(1421)},4813(e,t,o){t.isMahameruProjectDir=function(e){const t=(0,n.join)(e,"package.json"),o=(0,
|
|
631
|
+
n.join)(e,"node_modules");if(!(0,r.existsSync)(t)&&(0,r.existsSync)(o))return!1;try{const e=(0,
|
|
625
632
|
r.readFileSync)(t,"utf-8"),o=JSON.parse(e);return!(!o.dependencies||!o.dependencies.mahameru)}catch(e){return!1}}
|
|
626
|
-
;const r=o(3024),
|
|
633
|
+
;const r=o(3024),n=o(6760)},6929(e,t){t.parseProject=function(e){return{pid:e.pid,createdAt:e.createdAt,
|
|
627
634
|
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[
|
|
635
|
+
port:e.port,host:e.host,status:e.status}}},3157(e,t,o){t.hasWindowsElevationRetry=function(){return"1"===process.env[n]
|
|
636
|
+
},t.getWindowsElevatedWorkingDirectory=function(){return process.env[s]},t.isWindowsProcessElevated=function(){
|
|
630
637
|
if("win32"!==process.platform)return!1
|
|
631
638
|
;const e=(0,r.spawnSync)("powershell.exe",["-NoProfile","-NonInteractive","-Command","([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)"],{
|
|
632
639
|
encoding:"utf8",windowsHide:!0});return 0===e.status&&"true"===e.stdout.trim().toLowerCase()},
|
|
633
640
|
t.relaunchCurrentProcessAsAdmin=function(e){if("win32"!==process.platform)return{ok:!1,reason:"unsupported-platform"}
|
|
634
641
|
;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=>`'${
|
|
642
|
+
;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],
|
|
643
|
+
`@(${p.map(e=>`'${a(e)}'`).join(", ")})`),`Start-Process -FilePath 'powershell.exe' -Verb RunAs -WorkingDirectory '${a(e)}' -ArgumentList $argumentList`].join("; "),u=(0,
|
|
637
644
|
r.spawnSync)("powershell.exe",["-NoProfile","-NonInteractive","-Command",d],{encoding:"utf8",windowsHide:!0});var p
|
|
638
645
|
;if(0===u.status)return{ok:!0};const f=[u.stdout,u.stderr].filter(Boolean).join("\n").trim();return{ok:!1,
|
|
639
646
|
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
|
|
647
|
+
;const r=o(1421),n="MAHAMERU_ELEVATED_RETRY",s="MAHAMERU_ELEVATED_CWD";function a(e){return e.replace(/'/g,"''")}},
|
|
648
|
+
8419(e,t,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}}
|
|
649
|
+
;Object.defineProperty(t,"__esModule",{value:!0}),t.createZip=t.extractZip=void 0;const n=r(o(4650)),s=o(6760)
|
|
650
|
+
;t.extractZip=(e,t)=>new Promise((o,r)=>{try{new n.default(e).extractAllToAsync(t,!0,void 0,e=>{
|
|
651
|
+
e?r(new Error(`Extraction failed: ${e.message}`)):o(`Successfully extracted to ${t}`)})}catch(e){r(e)}})
|
|
652
|
+
;t.createZip=(e,t,o)=>new Promise((r,a)=>{try{const i=new n.default;if(o){const t=(0,s.basename)(e)
|
|
653
|
+
;i.addLocalFolder(e,t)}else i.addLocalFolder(e);i.writeZip(t,e=>{
|
|
654
|
+
e?a(new Error(`Zipping failed: ${e}`)):r(`Successfully created zip at ${t}`)})}catch(e){a(e)}})},4650(e){
|
|
655
|
+
e.exports=require("adm-zip")},6858(e){e.exports=require("commander")},6261(e){e.exports=require("events")},8720(e){
|
|
656
|
+
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")},9896(e){e.exports=require("fs")},1943(e){e.exports=require("fs/promises")},
|
|
658
|
+
9278(e){e.exports=require("net")},1421(e){e.exports=require("node:child_process")},139(e){
|
|
645
659
|
e.exports=require("node:cluster")},3024(e){e.exports=require("node:fs")},1455(e){e.exports=require("node:fs/promises")},
|
|
646
660
|
7067(e){e.exports=require("node:http")},4708(e){e.exports=require("node:https")},8995(e){
|
|
647
661
|
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(
|
|
662
|
+
e.exports=require("node:path")},6928(e){e.exports=require("path")},8330(e){e.exports={version:"0.0.23"}}};const t={}
|
|
663
|
+
;(function o(r){const n=t[r];if(void 0!==n)return n.exports;const s=t[r]={exports:{}}
|
|
664
|
+
;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.23",
|
|
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",
|