-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from pattern-lab/dev
Pattern Lab Node 2.6.0-alpha
- Loading branch information
Showing
15 changed files
with
276 additions
and
48 deletions.
There are no files selected for viewing
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
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
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,79 @@ | ||
"use strict"; | ||
|
||
var plugin_manager = function (config, configPath) { | ||
var path = require('path'), | ||
fs = require('fs-extra'), | ||
util = require('./utilities'); | ||
|
||
function loadPlugin(pluginName) { | ||
return require(path.join(process.cwd(), 'node_modules', pluginName)); | ||
} | ||
|
||
function installPlugin(pluginName) { | ||
try { | ||
var pluginPath = path.resolve( | ||
path.join(process.cwd(), 'node_modules', pluginName) | ||
); | ||
console.log('Attempting to load plugin from', pluginPath); | ||
try { | ||
var pluginDirStats = fs.statSync(pluginPath); | ||
} catch (ex) { | ||
util.logRed(pluginName + ' not found, please use npm to install it first.'); | ||
util.logRed(pluginName + ' not loaded.'); | ||
return; | ||
} | ||
var pluginPathDirExists = pluginDirStats.isDirectory(); | ||
if (pluginPathDirExists) { | ||
|
||
//write config entry back | ||
var diskConfig = fs.readJSONSync(path.resolve(configPath), 'utf8'); | ||
diskConfig[pluginName] = false; | ||
fs.outputFileSync(path.resolve(configPath), JSON.stringify(diskConfig, null, 2)); | ||
|
||
util.logGreen('Plugin ' + pluginName + ' installed.'); | ||
|
||
//todo, tell them how to uninstall or disable | ||
|
||
} | ||
} catch (ex) { | ||
console.log(ex); | ||
} | ||
} | ||
|
||
function detectPlugins() { | ||
var node_modules_path = path.join(process.cwd(), 'node_modules'); | ||
return fs.readdirSync(node_modules_path).filter(function (dir) { | ||
var module_path = path.join(process.cwd(), 'node_modules', dir); | ||
return fs.statSync(module_path).isDirectory() && dir.indexOf('plugin-node-') === 0; | ||
}); | ||
} | ||
|
||
function disablePlugin(pluginName) { | ||
console.log('disablePlugin not implemented yet. No change made to state of plugin', pluginName); | ||
} | ||
|
||
function enablePlugin(pluginName) { | ||
console.log('enablePlugin not implemented yet. No change made to state of plugin', pluginName); | ||
} | ||
|
||
return { | ||
install_plugin: function (pluginName) { | ||
installPlugin(pluginName); | ||
}, | ||
load_plugin: function (pluginName) { | ||
return loadPlugin(pluginName); | ||
}, | ||
detect_plugins: function () { | ||
return detectPlugins(); | ||
}, | ||
disable_plugin: function (pluginName) { | ||
disablePlugin(pluginName); | ||
}, | ||
enable_plugin: function (pluginName) { | ||
enablePlugin(pluginName); | ||
} | ||
}; | ||
|
||
}; | ||
|
||
module.exports = plugin_manager; |
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
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
Oops, something went wrong.