UNPKG

stackpress

Version:

Incept is a content management framework.

54 lines (53 loc) 2.38 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Terminal_1 = __importDefault(require("@stackpress/lib/Terminal")); class StackpressTerminal extends Terminal_1.default { get brand() { return this.control.brand; } get cwd() { return this.server.loader.cwd; } constructor(args, server) { super(args); this.server = server; this.verbose = this.expect(['verbose', 'v'], false); this.config = this.expect(['bootstrap', 'b'], null); this.server.register('cli', this); this._control.brand = this.server.config.path('cli.label', ''); } bootstrap() { return __awaiter(this, void 0, void 0, function* () { yield this.server.bootstrap(); yield this.server.resolve('config'); yield this.server.resolve('listen'); yield this.server.resolve('route'); return this; }); } run() { return __awaiter(this, void 0, void 0, function* () { const request = this.server.request({ data: this.data }); const response = this.server.response(); const status = yield this.server.emit(this.command, request, response); const verbose = this.expect(['verbose', 'v'], false); if (status.code === 404 && this.command !== 'serve' && verbose) { this._control.error(`Command "${this.command}" not found.`); } return status; }); } } exports.default = StackpressTerminal;