@athenna/core
Advanced tools
Comparing version 4.10.3 to 4.11.0
{ | ||
"name": "@athenna/core", | ||
"version": "4.10.3", | ||
"version": "4.11.0", | ||
"description": "The plug and play Node.js framework.", | ||
@@ -101,2 +101,3 @@ "license": "MIT", | ||
"lint-staged": "^12.5.0", | ||
"nodemon": "^3.0.1", | ||
"prettier": "^2.8.7" | ||
@@ -103,0 +104,0 @@ }, |
@@ -12,5 +12,7 @@ /** | ||
env: string; | ||
watch: boolean; | ||
static signature(): string; | ||
static description(): string; | ||
handle(): Promise<void>; | ||
getNodemon(): any; | ||
} |
@@ -15,2 +15,4 @@ /** | ||
}; | ||
import { Log } from '@athenna/logger'; | ||
import { Config } from '@athenna/config'; | ||
import { Module } from '@athenna/common'; | ||
@@ -31,4 +33,30 @@ import { BaseCommand, Option } from '@athenna/artisan'; | ||
const entrypoint = Config.get('rc.commands.serve.entrypoint', Path.bootstrap(`main.${Path.ext()}`)); | ||
if (this.watch) { | ||
const nodemon = this.getNodemon(); | ||
nodemon({ | ||
script: entrypoint.replace('.ts', '.js') | ||
}); | ||
if (Config.is('rc.bootLogs', false)) { | ||
return; | ||
} | ||
let isFirstRestart = true; | ||
nodemon | ||
.on('start', () => { | ||
if (isFirstRestart) { | ||
return; | ||
} | ||
console.clear(); | ||
Log.channelOrVanilla('application').success('Application successfully restarted'); | ||
}) | ||
.on('restart', () => { | ||
isFirstRestart = false; | ||
}); | ||
return; | ||
} | ||
await Module.resolve(entrypoint, Config.get('rc.parentURL')); | ||
} | ||
getNodemon() { | ||
const require = Module.createRequire(import.meta.url); | ||
return require('nodemon'); | ||
} | ||
} | ||
@@ -42,1 +70,8 @@ __decorate([ | ||
], ServeCommand.prototype, "env", void 0); | ||
__decorate([ | ||
Option({ | ||
signature: '-w, --watch', | ||
description: 'Use nodemon to watch the application and restart on changes.', | ||
default: false | ||
}) | ||
], ServeCommand.prototype, "watch", void 0); |
111915
3012
24