This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a56b93
commit bf039f2
Showing
8 changed files
with
79 additions
and
222 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
import * as admin from './controllers/admin'; | ||
import * as data from './controllers/pluginData'; | ||
import * as plugin from './controllers/plugin'; | ||
import * as user from './controllers/user'; | ||
|
||
module.exports = {} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
|
||
import * as Hapi from 'hapi'; | ||
|
||
import * as Plugins from '../lib/plugins'; | ||
|
||
const log = require('printit')({ | ||
date: true, | ||
prefix: 'Plugins' | ||
}); | ||
|
||
const root = path.resolve('./plugins'); | ||
|
||
export function loadPlugins(server: Hapi.Server) { | ||
// Check and update plugins currently stored in the database | ||
Plugins.PluginConnector.update().catch(processError); | ||
|
||
// Retrieve a list of the plugins currently present in the /plugins directory | ||
let plugins = fs.readdirSync(root).filter(file => fs.statSync(path.join(root, file)).isDirectory()); | ||
|
||
// Add plugin's public directories as static routes | ||
for(let plugin of plugins) { | ||
// Get instance of the connector so the plugin gets registered if | ||
// it wasn't before | ||
Plugins.PluginConnector.getInstance(plugin) | ||
.then((connector) => { | ||
if(!connector) throw new Error('Couldn\'t get database connector'); | ||
|
||
return connector.getState() | ||
}).then((state) => { | ||
// Only create the root if the plugin is enabled | ||
if(state === Plugins.State.enabled) { | ||
// Get the plugin's public path | ||
let pluginPublicPath = path.join(root, plugin, 'public'); | ||
|
||
// Check if the plugin has a public directory | ||
if(fs.existsSync(pluginPublicPath)) { | ||
// Create a static route for the plugin | ||
server.route({ | ||
method: 'GET', | ||
path: '/' + plugin + '/{file*}', | ||
handler: { directory: { | ||
path: __dirname + pluginPublicPath, | ||
listing: true | ||
}} | ||
}); | ||
} | ||
} | ||
}).catch(processError); | ||
} | ||
} | ||
|
||
function processError(e) { | ||
log.error(e); | ||
process.exit(1); | ||
} |