mirror of
https://github.com/Eugeny/tabby
synced 2024-11-15 01:17:14 +00:00
wip
This commit is contained in:
parent
b109fb8766
commit
8a8f89b386
3 changed files with 68 additions and 33 deletions
|
@ -1,4 +1,4 @@
|
||||||
import 'zone.js/dist/zone.js'
|
import 'zone.js'
|
||||||
import 'core-js/es7/reflect'
|
import 'core-js/es7/reflect'
|
||||||
import 'core-js/core/delay'
|
import 'core-js/core/delay'
|
||||||
import 'rxjs'
|
import 'rxjs'
|
||||||
|
|
|
@ -20,11 +20,7 @@ if (process.env.DEV) {
|
||||||
nodeModule.globalPaths.unshift(path.dirname(require('electron').remote.app.getAppPath()))
|
nodeModule.globalPaths.unshift(path.dirname(require('electron').remote.app.getAppPath()))
|
||||||
}
|
}
|
||||||
|
|
||||||
const builtinPluginsPath = path.join(
|
const builtinPluginsPath = path.join((process as any).resourcesPath, 'builtin-plugins')
|
||||||
path.dirname(require('electron').remote.app.getPath('exe')),
|
|
||||||
(process.platform === 'darwin') ? '../Resources' : 'resources',
|
|
||||||
'builtin-plugins',
|
|
||||||
)
|
|
||||||
|
|
||||||
const userPluginsPath = path.join(
|
const userPluginsPath = path.join(
|
||||||
require('electron').remote.app.getPath('appData'),
|
require('electron').remote.app.getPath('appData'),
|
||||||
|
@ -35,9 +31,9 @@ const userPluginsPath = path.join(
|
||||||
Object.assign(window, { builtinPluginsPath, userPluginsPath })
|
Object.assign(window, { builtinPluginsPath, userPluginsPath })
|
||||||
nodeModule.globalPaths.unshift(builtinPluginsPath)
|
nodeModule.globalPaths.unshift(builtinPluginsPath)
|
||||||
nodeModule.globalPaths.unshift(path.join(userPluginsPath, 'node_modules'))
|
nodeModule.globalPaths.unshift(path.join(userPluginsPath, 'node_modules'))
|
||||||
|
// nodeModule.globalPaths.unshift(path.join((process as any).resourcesPath, 'app.asar', 'node_modules'))
|
||||||
if (process.env.TERMINUS_PLUGINS) {
|
if (process.env.TERMINUS_PLUGINS) {
|
||||||
process.env.TERMINUS_PLUGINS.split(':').map(x => nodeModule.globalPaths.unshift(normalizePath(x)))
|
process.env.TERMINUS_PLUGINS.split(':').map(x => nodeModule.globalPaths.push(normalizePath(x)))
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare type ProgressCallback = (current, total) => void
|
export declare type ProgressCallback = (current, total) => void
|
||||||
|
@ -53,9 +49,26 @@ export interface IPluginInfo {
|
||||||
info?: any
|
info?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const builtinModules = [
|
||||||
|
'@angular/animations',
|
||||||
|
'@angular/common',
|
||||||
|
'@angular/compiler',
|
||||||
|
'@angular/core',
|
||||||
|
'@angular/forms',
|
||||||
|
'@angular/platform-browser',
|
||||||
|
'@angular/platform-browser-dynamic',
|
||||||
|
'@ng-bootstrap/ng-bootstrap',
|
||||||
|
'rxjs',
|
||||||
|
'terminus-core',
|
||||||
|
'terminus-settings',
|
||||||
|
'terminus-terminal',
|
||||||
|
'zone.js/dist/zone.js',
|
||||||
|
]
|
||||||
|
|
||||||
export async function findPlugins (): Promise<IPluginInfo[]> {
|
export async function findPlugins (): Promise<IPluginInfo[]> {
|
||||||
let paths = nodeModule.globalPaths
|
let paths = nodeModule.globalPaths
|
||||||
let foundPlugins: IPluginInfo[] = []
|
let foundPlugins: IPluginInfo[] = []
|
||||||
|
let candidateLocations: { pluginDir: string, pluginName: string }[] = []
|
||||||
|
|
||||||
for (let pluginDir of paths) {
|
for (let pluginDir of paths) {
|
||||||
pluginDir = normalizePath(pluginDir)
|
pluginDir = normalizePath(pluginDir)
|
||||||
|
@ -63,32 +76,44 @@ export async function findPlugins (): Promise<IPluginInfo[]> {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let pluginNames = await fs.readdir(pluginDir)
|
let pluginNames = await fs.readdir(pluginDir)
|
||||||
for (let pluginName of pluginNames.filter(x => /^terminus-/.exec(x))) {
|
if (await fs.exists(path.join(pluginDir, 'package.json'))) {
|
||||||
let pluginPath = path.join(pluginDir, pluginName)
|
candidateLocations.push({
|
||||||
let infoPath = path.join(pluginPath, 'package.json')
|
pluginDir: path.dirname(pluginDir),
|
||||||
if (!await fs.exists(infoPath)) {
|
pluginName: path.basename(pluginDir)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for (let pluginName of pluginNames) {
|
||||||
|
candidateLocations.push({ pluginDir, pluginName })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let { pluginDir, pluginName } of candidateLocations) {
|
||||||
|
let pluginPath = path.join(pluginDir, pluginName)
|
||||||
|
let infoPath = path.join(pluginPath, 'package.json')
|
||||||
|
if (!await fs.exists(infoPath)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundPlugins.some(x => x.name === pluginName)) {
|
||||||
|
console.info(`Plugin ${pluginName} already exists`)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let info = JSON.parse(await fs.readFile(infoPath, {encoding: 'utf-8'}))
|
||||||
|
if (!info.keywords || info.keywords.indexOf('terminus-plugin') === -1) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
foundPlugins.push({
|
||||||
if (foundPlugins.some(x => x.name === pluginName)) {
|
name: pluginName.substring('terminus-'.length),
|
||||||
console.info(`Plugin ${pluginName} already exists`)
|
packageName: pluginName,
|
||||||
}
|
isBuiltin: pluginDir === builtinPluginsPath,
|
||||||
|
version: info.version,
|
||||||
try {
|
description: info.description,
|
||||||
let info = JSON.parse(await fs.readFile(infoPath, {encoding: 'utf-8'}))
|
path: pluginPath,
|
||||||
console.log(pluginDir, builtinPluginsPath)
|
info,
|
||||||
foundPlugins.push({
|
})
|
||||||
name: pluginName.substring('terminus-'.length),
|
} catch (error) {
|
||||||
packageName: pluginName,
|
console.error('Cannot load package info for', pluginName)
|
||||||
isBuiltin: pluginDir === builtinPluginsPath,
|
|
||||||
version: info.version,
|
|
||||||
description: info.description,
|
|
||||||
path: pluginPath,
|
|
||||||
info,
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Cannot load package info for', pluginName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +128,16 @@ export async function loadPlugins (foundPlugins: IPluginInfo[], progress: Progre
|
||||||
for (let foundPlugin of foundPlugins) {
|
for (let foundPlugin of foundPlugins) {
|
||||||
console.info(`Loading ${foundPlugin.name}: ${nodeRequire.resolve(foundPlugin.path)}`)
|
console.info(`Loading ${foundPlugin.name}: ${nodeRequire.resolve(foundPlugin.path)}`)
|
||||||
progress(index, foundPlugins.length)
|
progress(index, foundPlugins.length)
|
||||||
|
// pre-inject builtin modules
|
||||||
|
builtinModules.forEach(moduleName => {
|
||||||
|
let mod = nodeRequire(moduleName)
|
||||||
|
let modPath = nodeRequire.resolve(moduleName)
|
||||||
|
let modSubpath = modPath.substring(modPath.indexOf(moduleName))
|
||||||
|
console.log('injecting', moduleName, modPath)
|
||||||
|
let targetPath = path.join(foundPlugin.path, 'node_modules', modSubpath)
|
||||||
|
console.log(targetPath, modPath)
|
||||||
|
nodeRequire.cache[targetPath] = mod
|
||||||
|
})
|
||||||
try {
|
try {
|
||||||
let pluginModule = nodeRequire(foundPlugin.path)
|
let pluginModule = nodeRequire(foundPlugin.path)
|
||||||
plugins.push(pluginModule)
|
plugins.push(pluginModule)
|
||||||
|
|
|
@ -61,7 +61,7 @@ module.exports = {
|
||||||
'mz': 'commonjs mz',
|
'mz': 'commonjs mz',
|
||||||
'path': 'commonjs path',
|
'path': 'commonjs path',
|
||||||
'rxjs': 'commonjs rxjs',
|
'rxjs': 'commonjs rxjs',
|
||||||
'zone.js': 'commonjs zone.js',
|
'zone.js': 'commonjs zone.js/dist/zone.js',
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.ModuleConcatenationPlugin(),
|
new webpack.optimize.ModuleConcatenationPlugin(),
|
||||||
|
|
Loading…
Reference in a new issue