UNPKG

@athenna/core

Version:

One foundation for multiple applications.

89 lines (88 loc) 3.32 kB
/** * @athenna/core * * (c) João Lenon <lenon@athenna.io> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Log } from '@athenna/logger'; import { Config } from '@athenna/config'; import { Path, Module } from '@athenna/common'; import { BaseCommand, Option } from '@athenna/artisan'; export class ServeCommand extends BaseCommand { static signature() { return 'serve'; } static description() { return 'Serve your application.'; } async handle() { const entrypoint = Config.get('rc.commands.serve.entrypoint', Path.bin(`main.${Path.ext()}`)); if (this.watch) { const nodemon = this.getNodemon(); nodemon({ script: entrypoint.replace('.ts', '.js'), ignore: [ '.git', '.github', '.idea', '.vscode', '.fleet', 'public', 'src/resources/**/*', 'vite.config.{js,ts,mjs}', 'node_modules/**/node_modules' ], watch: [ './', 'package.json', '.athennarc.json', 'tsconfig.json', '.env', '.env.dev', '.env.test', '.env.testing', '.env.example' ], ext: '*.*', ...Config.get('rc.commands.serve.nodemon', {}) }); let isFirstRestart = true; nodemon .on('start', async () => { 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'); } } __decorate([ Option({ signature: '-w, --watch', description: 'Use nodemon to watch the application and restart on changes.', default: false }), __metadata("design:type", Boolean) ], ServeCommand.prototype, "watch", void 0);