UNPKG

generator-theia

Version:

Theia Generator

38 lines 3.46 kB
"use strict"; /* * Copyright (C) 2017 TypeFox and others. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("../common"); var AbstractBackendGenerator = (function (_super) { __extends(AbstractBackendGenerator, _super); function AbstractBackendGenerator() { return _super !== null && _super.apply(this, arguments) || this; } AbstractBackendGenerator.prototype.doGenerate = function (fs, backendModules) { fs.write(this.backend('server.js'), this.compileServer(backendModules)); fs.write(this.backend('main.js'), this.compileMain(backendModules)); }; AbstractBackendGenerator.prototype.compileServer = function (backendModules) { return this.compileCopyright() + "\n// @ts-check\nrequire('reflect-metadata');\nconst path = require('path');\nconst express = require('express');\nconst { Container, injectable } = require('inversify');\n\nconst { BackendApplication } = require('@theia/core/lib/node');\nconst { backendApplicationModule } = require('@theia/core/lib/node/backend-application-module');\nconst { messagingBackendModule } = require('@theia/core/lib/node/messaging/messaging-backend-module');\nconst { loggerBackendModule } = require('@theia/core/lib/node/logger-backend-module');\n\nconst container = new Container();\ncontainer.load(backendApplicationModule);\ncontainer.load(messagingBackendModule);\ncontainer.load(loggerBackendModule);\n\nfunction load(raw) {\n return Promise.resolve(raw.default).then(module =>\n container.load(module)\n )\n}\n\nfunction start(port, host) {\n const application = container.get(BackendApplication);\n application.use(express.static(path.join(__dirname, '../../lib'), {\n index: 'index.html'\n }));\n return application.start(port, host);\n}\n\nmodule.exports = (port, host) => Promise.resolve()" + this.compileBackendModuleImports(backendModules) + "\n .then(() => start(port, host)).catch(reason => {\n console.error('Failed to start the backend application.');\n if (reason) {\n console.error(reason);\n }\n throw reason;\n });"; }; AbstractBackendGenerator.prototype.compileMain = function (backendModules) { return this.compileCopyright() + "\n// @ts-check\n\nconst { port, hostname } = require('yargs').argv;\nconsole.info(\"Starting express on port '\" + port + \"'.\")\nif (hostname) {\n console.info(\"Allowed host is '\" + hostname + \"'.\")\n}\nmodule.exports = require('./server')(port, hostname);"; }; return AbstractBackendGenerator; }(common_1.AbstractGenerator)); exports.AbstractBackendGenerator = AbstractBackendGenerator; //# sourceMappingURL=abstract-backend-generator.js.map