This commit is contained in:
Eugene Pankov
2019-06-14 17:49:42 +02:00
parent 82e3348122
commit a5ecdeb5ea
62 changed files with 271 additions and 280 deletions

View File

@@ -4,7 +4,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr'
export function getRootModule (plugins: any[]) {
let imports = [
const imports = [
BrowserModule,
...plugins,
NgbModule.forRoot(),
@@ -15,7 +15,7 @@ export function getRootModule (plugins: any[]) {
extendedTimeOut: 5000,
}),
]
let bootstrap = [
const bootstrap = [
...(plugins.filter(x => x.bootstrap).map(x => x.bootstrap)),
]

View File

@@ -16,8 +16,8 @@ Raven.config(
{
release: require('electron').remote.app.getVersion(),
dataCallback: (data: any) => {
const normalize = (filename) => {
let splitArray = filename.split('/')
const normalize = (filename: string) => {
const splitArray = filename.split('/')
return splitArray[splitArray.length - 1]
}

View File

@@ -32,10 +32,10 @@ async function bootstrap (plugins: IPluginInfo[], safeMode = false): Promise<NgM
if (safeMode) {
plugins = plugins.filter(x => x.isBuiltin)
}
let pluginsModules = await loadPlugins(plugins, (current, total) => {
const pluginsModules = await loadPlugins(plugins, (current, total) => {
(document.querySelector('.progress .bar') as HTMLElement).style.width = 100 * current / total + '%'
})
let module = getRootModule(pluginsModules)
const module = getRootModule(pluginsModules)
window['rootModule'] = module
return platformBrowserDynamic().bootstrapModule(module)
}

View File

@@ -12,7 +12,7 @@ function normalizePath (path: string): string {
return path
}
nodeRequire.main.paths.map(x => nodeModule.globalPaths.push(normalizePath(x)))
nodeRequire.main.paths.map((x: string) => nodeModule.globalPaths.push(normalizePath(x)))
if (process.env.TERMINUS_DEV) {
nodeModule.globalPaths.unshift(path.dirname(require('electron').remote.app.getAppPath()))
@@ -38,7 +38,7 @@ if (process.env.TERMINUS_PLUGINS) {
process.env.TERMINUS_PLUGINS.split(':').map(x => nodeModule.globalPaths.push(normalizePath(x)))
}
export declare type ProgressCallback = (current, total) => void
export declare type ProgressCallback = (current: number, total: number) => void
export interface IPluginInfo {
name: string
@@ -80,7 +80,7 @@ builtinModules.forEach(m => {
})
const originalRequire = (global as any).require
;(global as any).require = function (query) {
;(global as any).require = function (query: string) {
if (cachedBuiltinModules[query]) {
return cachedBuiltinModules[query]
}
@@ -88,9 +88,9 @@ const originalRequire = (global as any).require
}
export async function findPlugins (): Promise<IPluginInfo[]> {
let paths = nodeModule.globalPaths
const paths = nodeModule.globalPaths
let foundPlugins: IPluginInfo[] = []
let candidateLocations: { pluginDir: string, packageName: string }[] = []
const candidateLocations: { pluginDir: string, packageName: string }[] = []
const PREFIX = 'terminus-'
for (let pluginDir of paths) {
@@ -98,28 +98,28 @@ export async function findPlugins (): Promise<IPluginInfo[]> {
if (!await fs.exists(pluginDir)) {
continue
}
let pluginNames = await fs.readdir(pluginDir)
const pluginNames = await fs.readdir(pluginDir)
if (await fs.exists(path.join(pluginDir, 'package.json'))) {
candidateLocations.push({
pluginDir: path.dirname(pluginDir),
packageName: path.basename(pluginDir)
})
}
for (let packageName of pluginNames) {
for (const packageName of pluginNames) {
if (packageName.startsWith(PREFIX)) {
candidateLocations.push({ pluginDir, packageName })
}
}
}
for (let { pluginDir, packageName } of candidateLocations) {
let pluginPath = path.join(pluginDir, packageName)
let infoPath = path.join(pluginPath, 'package.json')
for (const { pluginDir, packageName } of candidateLocations) {
const pluginPath = path.join(pluginDir, packageName)
const infoPath = path.join(pluginPath, 'package.json')
if (!await fs.exists(infoPath)) {
continue
}
let name = packageName.substring(PREFIX.length)
const name = packageName.substring(PREFIX.length)
if (foundPlugins.some(x => x.name === name)) {
console.info(`Plugin ${packageName} already exists, overriding`)
@@ -127,7 +127,7 @@ export async function findPlugins (): Promise<IPluginInfo[]> {
}
try {
let info = JSON.parse(await fs.readFile(infoPath, { encoding: 'utf-8' }))
const info = JSON.parse(await fs.readFile(infoPath, { encoding: 'utf-8' }))
if (!info.keywords || !(info.keywords.includes('terminus-plugin') || info.keywords.includes('terminus-builtin-plugin'))) {
continue
}
@@ -153,17 +153,17 @@ export async function findPlugins (): Promise<IPluginInfo[]> {
}
export async function loadPlugins (foundPlugins: IPluginInfo[], progress: ProgressCallback): Promise<any[]> {
let plugins: any[] = []
const plugins: any[] = []
progress(0, 1)
let index = 0
for (let foundPlugin of foundPlugins) {
for (const foundPlugin of foundPlugins) {
console.info(`Loading ${foundPlugin.name}: ${nodeRequire.resolve(foundPlugin.path)}`)
progress(index, foundPlugins.length)
try {
const label = 'Loading ' + foundPlugin.name
console.time(label)
let packageModule = nodeRequire(foundPlugin.path)
let pluginModule = packageModule.default.forRoot ? packageModule.default.forRoot() : packageModule.default
const packageModule = nodeRequire(foundPlugin.path)
const pluginModule = packageModule.default.forRoot ? packageModule.default.forRoot() : packageModule.default
pluginModule['pluginName'] = foundPlugin.name
pluginModule['bootstrap'] = packageModule.bootstrap
plugins.push(pluginModule)