@nodearch/cli
Version:
nodearch cli
70 lines (69 loc) • 2.84 kB
JavaScript
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 { Command } from '@nodearch/command';
import { AppContext, Logger } from '@nodearch/core';
import nodemon from 'nodemon';
import path from 'path';
import { fileURLToPath } from 'url';
import { LocalAppService } from '../../local-app.service.js';
let StartCommand = class StartCommand {
constructor(appContext, logger, localAppService) {
this.appContext = appContext;
this.logger = logger;
this.localAppService = localAppService;
this.command = 'start';
this.describe = 'Starts the application';
this.aliases = 's';
this.builder = {
watch: {
alias: 'w',
boolean: true,
describe: 'Start in watch mode [nodemon]'
}
};
}
async handler(options) {
const localApp = await this.localAppService.app;
const localAppInfo = await this.localAppService.info;
if (!localApp || !localAppInfo)
return;
if (!options.watch) {
this.logger.info('Starting your app...');
return await localApp.start();
}
const ext = this.appContext.getSettings().loadMode;
const starterScriptPath = path.join(fileURLToPath(this.appContext.getSettings().paths.appDir), 'utils', 'app-starter.' + ext);
nodemon({
watch: [fileURLToPath(localAppInfo.paths.appDir)],
ext: 'ts',
cwd: fileURLToPath(localAppInfo.paths.rootDir),
script: starterScriptPath,
legacyWatch: true
});
nodemon
.on('start', () => {
this.logger.info('App started in watch mode');
})
.on('quit', () => {
this.logger.info('App has quit');
process.exit();
})
.on('restart', (files) => {
this.logger.info('App restarted due to: ', files);
});
}
};
StartCommand = __decorate([
Command(),
__metadata("design:paramtypes", [AppContext,
Logger,
LocalAppService])
], StartCommand);
export { StartCommand };