1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-25 11:33:35 +03:00
This commit is contained in:
Eugene Pankov 2017-07-01 00:55:21 +02:00
parent b109fb8766
commit 8a8f89b386
3 changed files with 68 additions and 33 deletions

View File

@ -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'

View File

@ -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,7 +76,18 @@ 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'))) {
candidateLocations.push({
pluginDir: path.dirname(pluginDir),
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 pluginPath = path.join(pluginDir, pluginName)
let infoPath = path.join(pluginPath, 'package.json') let infoPath = path.join(pluginPath, 'package.json')
if (!await fs.exists(infoPath)) { if (!await fs.exists(infoPath)) {
@ -76,7 +100,9 @@ export async function findPlugins (): Promise<IPluginInfo[]> {
try { try {
let info = JSON.parse(await fs.readFile(infoPath, {encoding: 'utf-8'})) let info = JSON.parse(await fs.readFile(infoPath, {encoding: 'utf-8'}))
console.log(pluginDir, builtinPluginsPath) if (!info.keywords || info.keywords.indexOf('terminus-plugin') === -1) {
continue
}
foundPlugins.push({ foundPlugins.push({
name: pluginName.substring('terminus-'.length), name: pluginName.substring('terminus-'.length),
packageName: pluginName, packageName: pluginName,
@ -90,7 +116,6 @@ export async function findPlugins (): Promise<IPluginInfo[]> {
console.error('Cannot load package info for', pluginName) console.error('Cannot load package info for', pluginName)
} }
} }
}
(window as any).installedPlugins = foundPlugins (window as any).installedPlugins = foundPlugins
return foundPlugins return foundPlugins
@ -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)

View File

@ -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(),