UNPKG

generator-theia

Version:

Theia Generator

64 lines 7.89 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 __()); }; })(); var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("../common"); var AppPackageGenerator = (function (_super) { __extends(AppPackageGenerator, _super); function AppPackageGenerator() { return _super !== null && _super.apply(this, arguments) || this; } AppPackageGenerator.prototype.generate = function (fs) { fs.writeJSON('package.json', this.compilePackage()); if (!fs.exists('webpack.config.js')) { fs.write('webpack.config.js', this.compileWebpackConfig()); } }; AppPackageGenerator.prototype.compilePackage = function () { var dependendencies = this.isWeb() ? {} : {}; var scripts = this.isWeb() ? { "start": "concurrently -n backend,frontend -c blue,green \"yarn run start:backend\" \"yarn run start:frontend\"", "start:backend": "yarn run build:backend && node ./src-gen/backend/main.js --port=3000| bunyan", "start:backend:debug": "yarn run build:backend && node ./src-gen/backend/main.js --port=3000 --loglevel=debug | bunyan", "start:frontend": "webpack-dev-server --open", } : { "start": "yarn run build:backend && electron ./src-gen/frontend/electron-main.js --hostname=localhost | bunyan", "start:debug": "yarn run build:backend && electron ./src-gen/frontend/electron-main.js --hostname=localhost --loglevel=debug | bunyan" }; var devDependencies = this.isWeb() ? { "webpack-dev-server": "^2.5.0" } : { "electron": "^1.6.11", "electron-rebuild": "^1.5.11" }; return __assign({}, this.model.pck, { "dependencies": common_1.sortByKey(__assign({}, dependendencies, this.model.pck.dependencies)), "scripts": common_1.sortByKey(__assign({ "clean": "rimraf lib", "cold:start": "yarn run clean && yarn run start", "build": "yarn run build:frontend && yarn run build:backend", "build:frontend": "webpack", "build:backend": "shx cp " + this.srcGen() + "/frontend/index.html lib", "watch": "yarn run build:frontend && webpack --watch" }, scripts, this.model.pck.scripts)), "devDependencies": common_1.sortByKey(__assign({ "rimraf": "^2.6.1", "concurrently": "^3.5.0", "bunyan": "^1.8.10", "webpack": "^2.2.1", "copy-webpack-plugin": "^4.0.1", "circular-dependency-plugin": "^2.0.0", "css-loader": "^0.28.1", "file-loader": "^0.11.1", "source-map-loader": "^0.2.1", "shx": "^0.2.2", "url-loader": "^0.5.8", "font-awesome-webpack": "0.0.5-beta.2", "less": "^2.7.2" }, devDependencies, this.model.pck.devDependencies)) }); }; AppPackageGenerator.prototype.compileWebpackConfig = function () { return this.compileCopyright() + "\n// @ts-check\nconst path = require('path');\nconst webpack = require('webpack');\nconst CopyWebpackPlugin = require('copy-webpack-plugin');\nconst CircularDependencyPlugin = require('circular-dependency-plugin');\n\nconst outputPath = path.resolve(__dirname, 'lib');\n\nconst monacoEditorPath = '" + this.node_modulesPath() + "/monaco-editor-core/min/vs';\nconst monacoLanguagesPath = '" + this.node_modulesPath() + "/monaco-languages/release';\nconst monacoCssLanguagePath = '" + this.node_modulesPath() + "/monaco-css/release/min';\nconst monacoTsLanguagePath = '" + this.node_modulesPath() + "/monaco-typescript/release';\nconst monacoJsonLanguagePath = '" + this.node_modulesPath() + "/monaco-json/release/min';\nconst monacoHtmlLanguagePath = '" + this.node_modulesPath() + "/monaco-html/release/min';" + this.ifWeb("\nconst requirePath = '" + this.node_modulesPath() + "/requirejs/require.js';\n\nconst port = require('yargs').argv.port || 3000;") + "\n\nmodule.exports = {\n entry: path.resolve(__dirname, 'src-gen/frontend/index.js'),\n output: {\n filename: 'bundle.js',\n path: outputPath\n },\n target: '" + this.model.target + "',\n node: {" + this.ifElectron("\n __dirname: false,\n __filename: false", "\n fs: 'empty',\n child_process: 'empty',\n net: 'empty',\n crypto: 'empty'") + "\n },\n module: {\n rules: [\n {\n test: /\\.css$/,\n loader: 'style-loader!css-loader'\n },\n {\n test: /\\.(ttf|eot|svg)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,\n loader: 'url-loader?limit=10000&mimetype=image/svg+xml'\n },\n {\n test: /\\.js$/,\n enforce: 'pre',\n loader: 'source-map-loader'\n },\n {\n test: /\\.woff(2)?(\\?v=[0-9]\\.[0-9]\\.[0-9])?$/,\n loader: \"url-loader?limit=10000&mimetype=application/font-woff\"\n }\n ],\n noParse: /vscode-languageserver-types|vscode-uri/\n },\n resolve: {\n extensions: ['.js'],\n alias: {\n 'vs': path.resolve(outputPath, monacoEditorPath)\n }\n },\n devtool: 'source-map',\n plugins: [\n new webpack.HotModuleReplacementPlugin(),\n new CopyWebpackPlugin([" + this.ifWeb("\n {\n from: requirePath,\n to: '.'\n },") + "\n {\n from: monacoEditorPath,\n to: 'vs'\n },\n {\n from: monacoLanguagesPath,\n to: 'vs/basic-languages'\n },\n {\n from: monacoCssLanguagePath,\n to: 'vs/language/css'\n },\n {\n from: monacoTsLanguagePath,\n to: 'vs/language/typescript'\n },\n {\n from: monacoJsonLanguagePath,\n to: 'vs/language/json'\n },\n {\n from: monacoHtmlLanguagePath,\n to: 'vs/language/html'\n }\n ]),\n new CircularDependencyPlugin({\n exclude: /(node_modules|examples)\\/./,\n failOnError: false // https://github.com/nodejs/readable-stream/issues/280#issuecomment-297076462\n })\n ],\n stats: {\n warnings: true\n }" + this.ifWeb(",\n devServer: {\n inline: true,\n hot: true,\n proxy: {\n '/services/*': {\n target: 'ws://localhost:' + port,\n ws: true\n },\n '*': 'http://localhost:' + port,\n },\n historyApiFallback: true,\n stats: {\n colors: true,\n warnings: false\n },\n host: process.env.HOST,\n port: process.env.PORT\n }") + "\n};"; }; return AppPackageGenerator; }(common_1.AbstractGenerator)); exports.AppPackageGenerator = AppPackageGenerator; //# sourceMappingURL=app-package-generator.js.map