forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-plugin.js
More file actions
33 lines (27 loc) · 1 KB
/
install-plugin.js
File metadata and controls
33 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const path = require('path');
const _ = require('lodash');
const checkAndInstallPackage = require('./utils').checkAndInstallPackage;
const wrapAsync = require('./utils').wrapAsync;
const installPlugin = (plugin, config) =>
wrapAsync(function*() {
const name = plugin.name || plugin;
yield checkAndInstallPackage(name);
// Put the installed plugin in the patternlab-config.json
_.set(config, `plugins[${name}]['enabled']`, true);
_.set(config, `plugins[${name}]['initialized']`, false);
// Get the options from the plugin, if any
const pluginPathConfig = path.resolve(
path.join(process.cwd(), 'node_modules', name, 'config.json')
);
try {
const pluginConfigJSON = require(pluginPathConfig);
if (!_.has(config.plugins[name].options)) {
_.set(config, `plugins[${name}]['options]`, pluginConfigJSON);
}
} catch (ex) {
//a config.json file is not required at this time
}
return name;
});
module.exports = installPlugin;