mirror of
https://github.com/Eugeny/tabby.git
synced 2025-09-18 22:26:05 +00:00
.
This commit is contained in:
@@ -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) {
|
||||
(<any>global).require('module').globalPaths.push(projectRoot);
|
||||
(<any>global).require('module').globalPaths.push(projectRoot + 'app/node_modules')
|
||||
}
|
||||
|
||||
let plugins = [
|
||||
(<any>global).require(projectRoot + 'terminus-settings').default,
|
||||
(<any>global).require(projectRoot + 'terminus-terminal').default,
|
||||
(<any>global).require(projectRoot + 'terminus-clickable-links').default,
|
||||
(<any>global).require(projectRoot + 'terminus-community-color-schemes').default,
|
||||
(<any>global).require(projectRoot + 'terminus-theme-hype').default,
|
||||
]
|
||||
|
||||
const core = (<any>global).require(projectRoot + 'terminus-core')
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
core.AppRootModule.forRoot(),
|
||||
...plugins,
|
||||
export async function getRootModule(): Promise<any> {
|
||||
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
|
||||
}
|
||||
|
@@ -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 ((<any>global).require('electron-is-dev')) {
|
||||
enableProdMode()
|
||||
}
|
||||
|
||||
(<any>console).timeStamp('angular bootstrap started')
|
||||
platformBrowserDynamic().bootstrapModule(RootModule);
|
||||
|
||||
|
||||
(<any>process).emitWarning = function () { console.log(arguments) }
|
||||
getRootModule().then(module => {
|
||||
platformBrowserDynamic().bootstrapModule(module)
|
||||
})
|
||||
|
32
app/src/plugins.ts
Normal file
32
app/src/plugins.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as fs from 'fs-promise'
|
||||
import * as path from 'path'
|
||||
|
||||
let nodeRequire = (<any>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<any[]> {
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user