UNPKG

generator-theia

Version:

Theia Generator

41 lines 3.5 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 AbstractFrontendGenerator = (function (_super) { __extends(AbstractFrontendGenerator, _super); function AbstractFrontendGenerator() { return _super !== null && _super.apply(this, arguments) || this; } AbstractFrontendGenerator.prototype.doGenerate = function (fs, frontendModules) { fs.write(this.frontend('index.html'), this.compileIndexHtml(frontendModules)); fs.write(this.frontend('index.js'), this.compileIndexJs(frontendModules)); }; AbstractFrontendGenerator.prototype.compileIndexHtml = function (frontendModules) { return "<!DOCTYPE html>\n<html>\n\n<head>" + this.compileIndexHead(frontendModules) + "\n <script type=\"text/javascript\" src=\"./bundle.js\" charset=\"utf-8\"></script>\n</head>\n\n<body>\n</body>\n\n</html>"; }; AbstractFrontendGenerator.prototype.compileIndexHead = function (frontendModules) { return "\n <meta charset=\"UTF-8\">\n <link href=\"http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css\" rel=\"stylesheet\">\n <script type=\"text/javascript\" src=\"https://www.promisejs.org/polyfills/promise-6.1.0.js\" charset=\"utf-8\"></script>"; }; AbstractFrontendGenerator.prototype.compileIndexJs = function (frontendModules) { return this.compileCopyright() + "\n// @ts-check\nconst { Container } = require('inversify');\nconst { FrontendApplication } = require('@theia/core/lib/browser');\nconst { frontendApplicationModule } = require('@theia/core/lib/browser/frontend-application-module');\nconst { messagingFrontendModule } = require('@theia/core/lib/browser/messaging/messaging-frontend-module');\nconst { loggerFrontendModule } = require('@theia/core/lib/browser/logger-frontend-module');\n\nconst container = new Container();\ncontainer.load(frontendApplicationModule);\ncontainer.load(messagingFrontendModule);\ncontainer.load(loggerFrontendModule);\n\nfunction load(raw) {\n return Promise.resolve(raw.default).then(module =>\n container.load(module)\n )\n}\n\nfunction start() {\n const application = container.get(FrontendApplication);\n application.start();\n}\n\nmodule.exports = Promise.resolve()" + this.compileFrontendModuleImports(frontendModules) + "\n .then(start).catch(reason => {\n console.error('Failed to start the frontend application.');\n if (reason) {\n console.error(reason);\n }\n });"; }; return AbstractFrontendGenerator; }(common_1.AbstractGenerator)); exports.AbstractFrontendGenerator = AbstractFrontendGenerator; //# sourceMappingURL=abstract-frontend-generator.js.map