UNPKG

generator-theia

Version:

Theia Generator

99 lines 3.92 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 __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); var os = require("os"); var path = require("path"); var AbstractGenerator = (function () { function AbstractGenerator(model) { this.model = model; } AbstractGenerator.prototype.srcGen = function () { var paths = []; for (var _i = 0; _i < arguments.length; _i++) { paths[_i] = arguments[_i]; } return path.join.apply(path, __spread(['src-gen'], paths)); }; AbstractGenerator.prototype.backend = function () { var paths = []; for (var _i = 0; _i < arguments.length; _i++) { paths[_i] = arguments[_i]; } return this.srcGen.apply(this, __spread(['backend'], paths)); }; AbstractGenerator.prototype.frontend = function () { var paths = []; for (var _i = 0; _i < arguments.length; _i++) { paths[_i] = arguments[_i]; } return this.srcGen.apply(this, __spread(['frontend'], paths)); }; AbstractGenerator.prototype.compileFrontendModuleImports = function (modules) { return this.compileModuleImports(modules, 'require'); }; AbstractGenerator.prototype.compileBackendModuleImports = function (modules) { return this.compileModuleImports(modules, 'require'); }; AbstractGenerator.prototype.compileModuleImports = function (modules, fn) { if (modules.size === 0) { return ''; } var lines = Array.from(modules.keys()).map(function (moduleName) { var invocation = fn + "('" + modules.get(moduleName) + "')"; if (fn === 'require') { return "Promise.resolve(" + invocation + ")"; } return invocation; }).map(function (statement) { return " .then(function () { return " + statement + ".then(load) })"; }); return os.EOL + lines.join(os.EOL); }; AbstractGenerator.prototype.compileCopyright = function () { var copyright = this.model.config.copyright; return copyright ? copyright + os.EOL : ''; }; AbstractGenerator.prototype.node_modulesPath = function () { return this.model.config.node_modulesPath; }; AbstractGenerator.prototype.isWeb = function () { return this.model.target === 'web'; }; AbstractGenerator.prototype.isElectron = function () { return this.model.target === 'electron-renderer'; }; AbstractGenerator.prototype.ifWeb = function (value, defaultValue) { if (defaultValue === void 0) { defaultValue = ''; } return this.isWeb() ? value : defaultValue; }; AbstractGenerator.prototype.ifElectron = function (value, defaultValue) { if (defaultValue === void 0) { defaultValue = ''; } return this.isElectron() ? value : defaultValue; }; return AbstractGenerator; }()); exports.AbstractGenerator = AbstractGenerator; //# sourceMappingURL=abstract-generator.js.map