Skip to content

Commit 4ae13ce

Browse files
committed
fix(cli): support scoped plugins
1 parent 2aa0f8f commit 4ae13ce

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/cli/bin/install-plugin.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@ const wrapAsync = require('./utils').wrapAsync;
66
const installPlugin = (plugin, config) =>
77
wrapAsync(function*() {
88
const name = plugin.name || plugin;
9-
yield checkAndInstallPackage(name);
9+
const safePluginName = _.kebabCase(name);
10+
yield checkAndInstallPackage(safePluginName);
1011
// Put the installed plugin in the patternlab-config.json
11-
_.set(config, `plugins[${name}]['enabled']`, false);
12-
return name;
12+
_.set(config, `plugins[${safePluginName}]['enabled']`, true);
13+
14+
// Get the options from the plugin, if any
15+
const pluginPathConfig = path.resolve(
16+
path.join(process.cwd(), 'node_modules', safePluginName, 'config.json')
17+
);
18+
try {
19+
const pluginConfigJSON = require(pluginPathConfig);
20+
if (!_.has(config.plugins[safePluginName].options)) {
21+
_.set(config, `plugins[${safePluginName}]['options]`, pluginConfigJSON);
22+
}
23+
} catch (ex) {
24+
//a config.json file is not required at this time
25+
}
26+
return safePluginName;
1327
});
1428

1529
module.exports = installPlugin;

0 commit comments

Comments
 (0)