This commit is contained in:
Eugene Pankov
2017-04-17 14:57:22 +02:00
parent 36c2aef860
commit 919aa7c65f
21 changed files with 108 additions and 78 deletions

View File

@@ -14,6 +14,10 @@ export async function getRootModule(): Promise<any> {
...(plugins.filter(x => x.bootstrap).map(x => x.bootstrap)),
]
if (bootstrap.length == 0) {
throw new Error('Did not find any bootstrap components. Are there any plugins installed?')
}
@NgModule({
imports,
bootstrap,

View File

@@ -1,26 +1,36 @@
import * as fs from 'fs-promise'
import * as path from 'path'
const nodeModule = (<any>global).require('module')
function normalizePath (path: string): string {
const cygwinPrefix = '/cygdrive/'
if (path.startsWith(cygwinPrefix)) {
path = path.substring(cygwinPrefix.length).replace('/', '\\')
path = path[0] + ':' + path.substring(1)
}
return path
};
(<any>global).require.main.paths.map(x => nodeModule.globalPaths.push(normalizePath(x)))
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.unshift(x))
process.env.TERMINUS_PLUGINS.split(':').map(x => nodeModule.globalPaths.unshift(normalizePath(x)))
}
export async function loadPlugins (): Promise<any[]> {
let paths = module.globalPaths
let paths = nodeModule.globalPaths
let plugins: any[] = []
for (let pluginDir of paths) {
pluginDir = normalizePath(pluginDir)
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)}`)
console.info(`Loading ${pluginName}: ${(<any>global).require.resolve(pluginPath)}`)
try {
let pluginModule = nodeRequire(pluginPath)
let pluginModule = (<any>global).require(pluginPath)
plugins.push(pluginModule)
} catch (error) {
console.error(`Could not load ${pluginName}:`, error)

View File

@@ -2,7 +2,7 @@
"compilerOptions": {
"baseUrl": "./src",
"module": "commonjs",
"target": "es5",
"target": "es2015",
"declaration": false,
"noImplicitAny": false,
"removeComments": false,