mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 05:35:42 +08:00
34 lines
779 B
JavaScript
34 lines
779 B
JavaScript
/**
|
|
* Executes `source` to retrieve plugins configuration
|
|
* and loads the `index.js` of specified plugins.
|
|
*
|
|
* Outputs a module that looks like the following:
|
|
*
|
|
* module.exports = [{plugin: string, module: object}, ...]
|
|
*
|
|
*/
|
|
const {stripIndent} = require('common-tags');
|
|
|
|
function getPluginList(config) {
|
|
if (config && config.client) {
|
|
return config.client.map((x) => typeof x === 'string' ? x : Object.keys(x)[0]);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
module.exports = function(source) {
|
|
this.cacheable();
|
|
const config = this.exec(source, this.resourcePath);
|
|
const plugins = getPluginList(config).map((plugin) => `{
|
|
module: require('${plugin}/client'),
|
|
name: '${plugin}'
|
|
}`);
|
|
|
|
return stripIndent`
|
|
module.exports = [
|
|
${plugins.join(',')}
|
|
];
|
|
`;
|
|
};
|