From c19f0b18952988c1cd137d084b6e1f65b4dbf3a3 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sat, 15 Apr 2017 15:20:18 +0200 Subject: [PATCH] . --- Makefile | 2 +- app/main.js | 2 +- app/package.json | 5 +++ app/src/app.module.ts | 43 ++++++++----------- app/src/entry.ts | 11 ++--- app/src/plugins.ts | 32 ++++++++++++++ tsconfig.json => app/tsconfig.json | 2 +- app/webpack.config.js | 13 ++++-- package.json | 7 ++- terminus-clickable-links/tsconfig.json | 6 +-- terminus-clickable-links/webpack.config.js | 1 + .../tsconfig.json | 6 +-- .../webpack.config.js | 1 + terminus-core/rxjs.ts | 1 - terminus-core/src/components/appRoot.ts | 2 - terminus-core/src/components/titleBar.pug | 2 +- terminus-core/src/index.ts | 6 +-- terminus-core/src/services/config.ts | 2 +- terminus-core/src/services/electron.ts | 1 - terminus-core/src/services/hostApp.ts | 2 +- terminus-core/webpack.config.js | 1 + terminus-core/zone.js.ts | 1 - terminus-settings/webpack.config.js | 1 + terminus-terminal/src/services/sessions.ts | 1 - terminus-terminal/webpack.config.js | 1 + terminus-theme-hype/tsconfig.json | 6 +-- terminus-theme-hype/webpack.config.js | 1 + tslint.json | 4 -- 28 files changed, 88 insertions(+), 75 deletions(-) create mode 100644 app/src/plugins.ts rename tsconfig.json => app/tsconfig.json (96%) delete mode 100644 terminus-core/rxjs.ts delete mode 100644 terminus-core/zone.js.ts diff --git a/Makefile b/Makefile index 24a35772..66931c21 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ SHORT_VERSION=$(shell python -c 'import subprocess; v = subprocess.check_output( all: run run: - DEV=1 NODE_PATH=./app/node_modules ./node_modules/.bin/electron ./app --debug + DEV=1 TERMINUS_PLUGINS=`realpath .` ./node_modules/.bin/electron ./app --debug lint: tslint -c tslint.json app/src/*.ts app/src/**/*.ts diff --git a/app/main.js b/app/main.js index 644f8223..8f364907 100644 --- a/app/main.js +++ b/app/main.js @@ -131,7 +131,7 @@ start = () => { width: 800, height: 400, //icon: `${app.getAppPath()}/assets/img/icon.png`, - title: 'Term', + title: 'Terminus', minWidth: 300, minHeight: 100, 'web-preferences': {'web-security': false}, diff --git a/app/package.json b/app/package.json index 4239e14d..4eaf3358 100644 --- a/app/package.json +++ b/app/package.json @@ -2,6 +2,10 @@ "name": "terminus", "version": "0.0.1", "main": "main.js", + "scripts": { + "build": "../node_modules/.bin/webpack --progress --color --display-modules", + "watch": "../node_modules/.bin/webpack --progress --color --watch" + }, "dependencies": { "@angular/animations": "4.0.1", "@angular/common": "4.0.1", @@ -15,6 +19,7 @@ "electron-config": "0.2.1", "electron-debug": "1.0.1", "electron-is-dev": "0.1.2", + "fs-promise": "^2.0.2", "js-yaml": "3.8.2", "path": "0.12.7", "rxjs": "5.3.0", diff --git a/app/src/app.module.ts b/app/src/app.module.ts index bd5ef111..3096cb31 100644 --- a/app/src/app.module.ts +++ b/app/src/app.module.ts @@ -1,28 +1,23 @@ import { NgModule } from '@angular/core' +import { BrowserModule } from '@angular/platform-browser' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' +import { loadPlugins } from './plugins' -const projectRoot = '/home/eugene/Work/term/' -if (process.env.DEV) { - (global).require('module').globalPaths.push(projectRoot); - (global).require('module').globalPaths.push(projectRoot + 'app/node_modules') -} - -let plugins = [ - (global).require(projectRoot + 'terminus-settings').default, - (global).require(projectRoot + 'terminus-terminal').default, - (global).require(projectRoot + 'terminus-clickable-links').default, - (global).require(projectRoot + 'terminus-community-color-schemes').default, - (global).require(projectRoot + 'terminus-theme-hype').default, -] - -const core = (global).require(projectRoot + 'terminus-core') - -@NgModule({ - imports: [ - core.AppRootModule.forRoot(), - ...plugins, +export async function getRootModule(): Promise { + let plugins = await loadPlugins() + let imports = [ + BrowserModule, + ...(plugins.map(x => x.default.forRoot ? x.default.forRoot() : x.default)), NgbModule.forRoot(), - ], - bootstrap: [core.AppRootComponent] -}) -export class RootModule { } + ] + let bootstrap = [ + ...(plugins.filter(x => x.bootstrap).map(x => x.bootstrap)), + ] + + @NgModule({ + imports, + bootstrap, + }) class RootModule { } + + return RootModule +} diff --git a/app/src/entry.ts b/app/src/entry.ts index 59e9dec9..ea27f431 100644 --- a/app/src/entry.ts +++ b/app/src/entry.ts @@ -3,12 +3,11 @@ import 'core-js' import 'zone.js/dist/zone.js' import 'core-js/es7/reflect' -import 'jquery' // Always land on the start view location.hash = '' -import { RootModule } from './app.module' +import { getRootModule } from './app.module' import { enableProdMode } from '@angular/core' import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' @@ -18,8 +17,6 @@ if ((global).require('electron-is-dev')) { enableProdMode() } -(console).timeStamp('angular bootstrap started') -platformBrowserDynamic().bootstrapModule(RootModule); - - -(process).emitWarning = function () { console.log(arguments) } +getRootModule().then(module => { + platformBrowserDynamic().bootstrapModule(module) +}) diff --git a/app/src/plugins.ts b/app/src/plugins.ts new file mode 100644 index 00000000..a86e230f --- /dev/null +++ b/app/src/plugins.ts @@ -0,0 +1,32 @@ +import * as fs from 'fs-promise' +import * as path from 'path' + +let nodeRequire = (global).require +let module = nodeRequire('module') +nodeRequire.main.paths.map(x => module.globalPaths.push(x)) +if (process.env.TERMINUS_PLUGINS) { + process.env.TERMINUS_PLUGINS.split(':').map(x => module.globalPaths.push(x)) +} + +export async function loadPlugins (): Promise { + let paths = module.globalPaths + let plugins: any[] = [] + for (let pluginDir of paths) { + if (!await fs.exists(pluginDir)) { + continue + } + for (let pluginName of await fs.readdir(pluginDir)) { + if (/^terminus-/.exec(pluginName)) { + let pluginPath = path.join(pluginDir, pluginName) + console.info(`Loading ${pluginName}: ${nodeRequire.resolve(pluginPath)}`) + try { + let pluginModule = nodeRequire(pluginPath) + plugins.push(pluginModule) + } catch (error) { + console.error(`Could not load ${pluginName}:`, error) + } + } + } + } + return plugins +} diff --git a/tsconfig.json b/app/tsconfig.json similarity index 96% rename from tsconfig.json rename to app/tsconfig.json index 567e883e..7d9d1fbe 100644 --- a/tsconfig.json +++ b/app/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "baseUrl": "./app/src", + "baseUrl": "./src", "module": "commonjs", "target": "es5", "declaration": false, diff --git a/app/webpack.config.js b/app/webpack.config.js index 408c6bb6..1a429cef 100644 --- a/app/webpack.config.js +++ b/app/webpack.config.js @@ -25,8 +25,10 @@ module.exports = { loaders: [ { test: /\.ts$/, - use: 'awesome-typescript-loader', - exclude: [/node_modules/] + loader: 'awesome-typescript-loader', + options: { + configFileName: path.resolve(__dirname, 'tsconfig.json'), + } }, { test: /\.scss$/, @@ -40,14 +42,14 @@ module.exports = { test: /\.(png|svg)$/, loader: "file-loader", options: { - name: 'images/[name].[hash:8].[ext]' + name: 'images/[name].[ext]' } }, { test: /\.(ttf|eot|otf|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader", options: { - name: 'fonts/[name].[hash:8].[ext]' + name: 'fonts/[name].[ext]' } } ] @@ -60,6 +62,9 @@ module.exports = { '@angular/forms': 'commonjs @angular/forms', '@angular/common': 'commonjs @angular/common', '@ng-bootstrap/ng-bootstrap': 'commonjs @ng-bootstrap/ng-bootstrap', + 'fs-promise': 'commonjs fs-promise', + 'module': 'commonjs module', + 'path': 'commonjs path', 'rxjs': 'commonjs rxjs', 'zone.js': 'commonjs zone.js', }, diff --git a/package.json b/package.json index 96bdec4e..b6176cee 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "term", "devDependencies": { "angular2-perfect-scrollbar": "2.0.0", - "jquery": "^3.1.1", "@types/fs-promise": "^1.0.1", "@types/core-js": "^0.9.35", "@types/electron": "1.4.34", @@ -36,7 +35,7 @@ "url-loader": "^0.5.7", "val-loader": "^0.5.0", "vrsource-tslint-rules": "^4.0.1", - "webpack": "2.3.3" + "webpack": "2.4.1" }, "build": { "appId": "com.elements.benchmark", @@ -58,8 +57,8 @@ } }, "scripts": { - "build": "webpack --progress --color", - "watch": "webpack --progress --color --watch", + "build": "node --max-old-space-size=4096 ./node_modules/.bin/webpack --progress --color", + "watch": "node --max-old-space-size=4096 ./node_modules/.bin/webpack --progress --color --watch", "pack": "build --dir", "postinstall": "install-app-deps", "dist": "build" diff --git a/terminus-clickable-links/tsconfig.json b/terminus-clickable-links/tsconfig.json index 993ae363..5cb388c6 100644 --- a/terminus-clickable-links/tsconfig.json +++ b/terminus-clickable-links/tsconfig.json @@ -20,11 +20,7 @@ "dom", "es2015", "es7" - ], - "paths": { - "*": ["../../app/node_modules/*"], - "terminus-*": ["../../terminus-*"] - } + ] }, "compileOnSave": false, "exclude": [ diff --git a/terminus-clickable-links/webpack.config.js b/terminus-clickable-links/webpack.config.js index f238b09e..710488e1 100644 --- a/terminus-clickable-links/webpack.config.js +++ b/terminus-clickable-links/webpack.config.js @@ -22,6 +22,7 @@ module.exports = { test: /\.ts$/, loader: 'awesome-typescript-loader', query: { + configFileName: path.resolve(__dirname, 'tsconfig.json'), paths: { "terminus-*": [path.resolve(__dirname, '../terminus-*')], "*": [path.resolve(__dirname, '../app/node_modules/*')], diff --git a/terminus-community-color-schemes/tsconfig.json b/terminus-community-color-schemes/tsconfig.json index 993ae363..5cb388c6 100644 --- a/terminus-community-color-schemes/tsconfig.json +++ b/terminus-community-color-schemes/tsconfig.json @@ -20,11 +20,7 @@ "dom", "es2015", "es7" - ], - "paths": { - "*": ["../../app/node_modules/*"], - "terminus-*": ["../../terminus-*"] - } + ] }, "compileOnSave": false, "exclude": [ diff --git a/terminus-community-color-schemes/webpack.config.js b/terminus-community-color-schemes/webpack.config.js index d98dc76f..b1bca705 100644 --- a/terminus-community-color-schemes/webpack.config.js +++ b/terminus-community-color-schemes/webpack.config.js @@ -22,6 +22,7 @@ module.exports = { test: /\.ts$/, loader: 'awesome-typescript-loader', options: { + configFileName: path.resolve(__dirname, 'tsconfig.json'), paths: { "terminus-*": [path.resolve(__dirname, '../terminus-*')], "*": [path.resolve(__dirname, '../app/node_modules/*')], diff --git a/terminus-core/rxjs.ts b/terminus-core/rxjs.ts deleted file mode 100644 index c276befc..00000000 --- a/terminus-core/rxjs.ts +++ /dev/null @@ -1 +0,0 @@ -export * from 'rxjs' diff --git a/terminus-core/src/components/appRoot.ts b/terminus-core/src/components/appRoot.ts index 5607f0d4..c7dcc41f 100644 --- a/terminus-core/src/components/appRoot.ts +++ b/terminus-core/src/components/appRoot.ts @@ -55,8 +55,6 @@ export class AppRootComponent { _themes: ThemesService, _quitter: QuitterService, ) { - (console).timeStamp('AppComponent ctor') - this.logger = log.create('main') this.logger.info('v', electron.app.getVersion()) diff --git a/terminus-core/src/components/titleBar.pug b/terminus-core/src/components/titleBar.pug index 6465a857..8014a22c 100644 --- a/terminus-core/src/components/titleBar.pug +++ b/terminus-core/src/components/titleBar.pug @@ -1,4 +1,4 @@ -.title((dblclick)='hostApp.toggleMaximize()') Term +.title((dblclick)='hostApp.toggleMaximize()') Terminus button.btn.btn-secondary.btn-minimize((click)='hostApp.minimize()') i.fa.fa-window-minimize button.btn.btn-secondary.btn-maximize((click)='hostApp.toggleMaximize()') diff --git a/terminus-core/src/index.ts b/terminus-core/src/index.ts index d3a2de1f..c7cd2e51 100644 --- a/terminus-core/src/index.ts +++ b/terminus-core/src/index.ts @@ -1,5 +1,4 @@ import { NgModule, ModuleWithProviders } from '@angular/core' -console.info((global).require.resolve('@angular/core')) import { BrowserModule } from '@angular/platform-browser' import { BrowserAnimationsModule } from '@angular/platform-browser/animations' import { FormsModule } from '@angular/forms' @@ -64,9 +63,6 @@ const PROVIDERS = [ ], }) export default class AppModule { -} - -export class AppRootModule { static forRoot(): ModuleWithProviders { return { ngModule: AppModule, @@ -75,5 +71,5 @@ export class AppRootModule { } } -export { AppRootComponent } +export { AppRootComponent as bootstrap } export * from './api' diff --git a/terminus-core/src/services/config.ts b/terminus-core/src/services/config.ts index 1af43f9d..c9bc825a 100644 --- a/terminus-core/src/services/config.ts +++ b/terminus-core/src/services/config.ts @@ -53,7 +53,7 @@ const configMerge = (a, b) => require('deepmerge')(a, b, { arrayMerge: (_d, s) = @Injectable() export class ConfigService { - store: ConfigProxy + store: any change = new EventEmitter() restartRequested: boolean private _store: any diff --git a/terminus-core/src/services/electron.ts b/terminus-core/src/services/electron.ts index b19e744f..9ad5dc45 100644 --- a/terminus-core/src/services/electron.ts +++ b/terminus-core/src/services/electron.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core' - @Injectable() export class ElectronService { constructor() { diff --git a/terminus-core/src/services/hostApp.ts b/terminus-core/src/services/hostApp.ts index 4e39ec30..fc237c2b 100644 --- a/terminus-core/src/services/hostApp.ts +++ b/terminus-core/src/services/hostApp.ts @@ -28,7 +28,7 @@ export class HostAppService { electron.ipcRenderer.on('host:quit-request', () => this.zone.run(() => this.quitRequested.emit())) electron.ipcRenderer.on('uncaughtException', function(err) { - console.error('Unhandled exception:', err) + this.logger.error('Unhandled exception:', err) }) electron.ipcRenderer.on('host:window-shown', () => { diff --git a/terminus-core/webpack.config.js b/terminus-core/webpack.config.js index b335fd2a..55ff01d0 100644 --- a/terminus-core/webpack.config.js +++ b/terminus-core/webpack.config.js @@ -22,6 +22,7 @@ module.exports = { test: /\.ts$/, loader: 'awesome-typescript-loader', options: { + configFileName: path.resolve(__dirname, 'tsconfig.json'), paths: { "terminus-*": [path.resolve(__dirname, '../terminus-*')], "*": [path.resolve(__dirname, '../app/node_modules/*')], diff --git a/terminus-core/zone.js.ts b/terminus-core/zone.js.ts deleted file mode 100644 index 672bc266..00000000 --- a/terminus-core/zone.js.ts +++ /dev/null @@ -1 +0,0 @@ -export * from 'zone.js' diff --git a/terminus-settings/webpack.config.js b/terminus-settings/webpack.config.js index d5656a9e..9ffcf7ee 100644 --- a/terminus-settings/webpack.config.js +++ b/terminus-settings/webpack.config.js @@ -22,6 +22,7 @@ module.exports = { test: /\.ts$/, loader: 'awesome-typescript-loader', options: { + configFileName: path.resolve(__dirname, 'tsconfig.json'), paths: { "terminus-*": [path.resolve(__dirname, '../terminus-*')], "*": [path.resolve(__dirname, '../app/node_modules/*')], diff --git a/terminus-terminal/src/services/sessions.ts b/terminus-terminal/src/services/sessions.ts index c57f3b60..62f38a1a 100644 --- a/terminus-terminal/src/services/sessions.ts +++ b/terminus-terminal/src/services/sessions.ts @@ -23,7 +23,6 @@ export class Session { constructor (options: SessionOptions) { this.name = options.name this.recoveryId = options.recoveryId - console.log('Spawning', options.command) let env = { ...process.env, diff --git a/terminus-terminal/webpack.config.js b/terminus-terminal/webpack.config.js index a52b6a61..acd92e6d 100644 --- a/terminus-terminal/webpack.config.js +++ b/terminus-terminal/webpack.config.js @@ -22,6 +22,7 @@ module.exports = { test: /\.ts$/, loader: 'awesome-typescript-loader', query: { + configFileName: path.resolve(__dirname, 'tsconfig.json'), paths: { "terminus-*": [path.resolve(__dirname, '../terminus-*')], "*": [path.resolve(__dirname, '../app/node_modules/*')], diff --git a/terminus-theme-hype/tsconfig.json b/terminus-theme-hype/tsconfig.json index b6010174..1ac8dfd3 100644 --- a/terminus-theme-hype/tsconfig.json +++ b/terminus-theme-hype/tsconfig.json @@ -12,11 +12,7 @@ "dom", "es2015", "es7" - ], - "paths": { - "*": ["../../app/node_modules/*"], - "terminus-*": ["../../terminus-*"] - } + ] }, "exclude": [ "node_modules" diff --git a/terminus-theme-hype/webpack.config.js b/terminus-theme-hype/webpack.config.js index 691d1af7..38f550ea 100644 --- a/terminus-theme-hype/webpack.config.js +++ b/terminus-theme-hype/webpack.config.js @@ -21,6 +21,7 @@ module.exports = { test: /\.ts$/, loader: 'awesome-typescript-loader', options: { + configFileName: path.resolve(__dirname, 'tsconfig.json'), paths: { "terminus-*": [path.resolve(__dirname, '../terminus-*')], "*": [path.resolve(__dirname, '../app/node_modules/*')], diff --git a/tslint.json b/tslint.json index 217c8c7c..3cfd1502 100644 --- a/tslint.json +++ b/tslint.json @@ -4,10 +4,6 @@ "node_modules/tslint-eslint-rules/dist/rules" ], "rules": { - "no-console": [ - true, - "log" - ], "no-duplicate-imports": true, "no-duplicate-variable": true, "no-jasmine-focus": true,