Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Commit

Permalink
refactor and bump
Browse files Browse the repository at this point in the history
  • Loading branch information
kfatehi committed Oct 16, 2014
1 parent 7ec0938 commit d647b95
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 77 deletions.
1 change: 0 additions & 1 deletion commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = function(deps, parser) {
if (err) {
console.error(err.stack);
} else {
console.log(plugin+" installed")
if (restart) {
require('../resilient')(deps).restart()
}
Expand Down
1 change: 0 additions & 1 deletion commands/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = function(deps, parser) {
if (err) {
console.error(err.stack);
} else {
console.log(plugin+" uninstalled")
if (restart) {
require('../resilient')(deps).restart()
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strider-cli",
"version": "1.2.1",
"version": "1.3.0",
"description": "CLI for Strider",
"main": "index.js",
"scripts": {
Expand All @@ -27,7 +27,7 @@
"readline": "0.0.4",
"rimraf": "^2.2.8",
"step": "0.0.5",
"strider-ecosystem-client": "1.1.0",
"strider-ecosystem-client": "1.2.0",
"superagent": "^0.20.0",
"touch": "0.0.3"
}
Expand Down
7 changes: 4 additions & 3 deletions plugin_manager/create_new_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var path = require('path')
var git = require('./git')
var fs = require('fs')

module.exports = function (deps) {
var localPlugins = require('./local_plugins')(deps)
module.exports = function (pluginsPath) {
var localPlugins = require('./local_plugins')(pluginsPath)
var pluginsPath = localPlugins.path()
prompt.message = "plugin";
prompt.start()
Expand All @@ -30,7 +30,7 @@ module.exports = function (deps) {
if (fs.existsSync(pluginPath)) {
console.error(res.name+' already exists: '+pluginPath)
} else {
git.clone('https://github.com/bitwit/strider-template.git', pluginPath, function(err) {
git.clone('https://github.com/Strider-CD/strider-template.git', '1.0.0', pluginPath, function(err) {
if (err) throw err;
var pkgPath = path.join(pluginPath, 'package.json')
fs.readFile(pkgPath, function (err, jsonFile) {
Expand All @@ -39,6 +39,7 @@ module.exports = function (deps) {
Object.keys(schema.properties).forEach(function (key) {
pkg[key] = res[key]
})
pkg["strider"]["id"] = res.name
fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2), function () {
console.log(
["", "A strider plugin template has been prepared for you in the following directory"
Expand Down
10 changes: 8 additions & 2 deletions plugin_manager/git.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
var spawn = require('child_process').spawn

module.exports = {
clone: function(repo, path, cb) {
var proc = spawn('git', [ 'clone', repo, path ], { stdio: 'inherit' })
clone: function(repo, tag, path, cb) {

var proc = spawn('git', [
'clone',
'--branch', tag,
'--depth', '1',
repo, path
], { stdio: 'inherit' })
proc.on('close', function (code) {
if (code !== 0) {
return cb(new Error('git clone failed with non-zero status '+code))
Expand Down
16 changes: 9 additions & 7 deletions plugin_manager/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
module.exports = function (deps) {
var pluginsPath = deps.getPluginPath()()

return {
listLocal: function() {
return require('./list_local_plugins')(deps)
return require('./list_local_plugins')(pluginsPath)
},
listRemote: function() {
return require('./list_remote_plugins')(deps)
return require('./list_remote_plugins')(pluginsPath)
},
createNew: function() {
return require('./create_new_plugin')(deps)
return require('./create_new_plugin')(pluginsPath)
},
install: function(pluginName, cb) {
require('./install_plugin')(deps)(pluginName, cb)
install: function(name, cb) {
return require('./install_plugin')(pluginsPath)(name, cb)
},
uninstall: function(pluginName, cb) {
require('./uninstall_plugin')(deps)(pluginName, cb)
uninstall: function(name, cb) {
return require('./uninstall_plugin')(pluginsPath)(name, cb)
}
}
}
38 changes: 24 additions & 14 deletions plugin_manager/install_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,39 @@ var _ = require('lodash')
, path = require('path')
, git = require('./git')
, npm = require('./npm')
, client = require('strider-ecosystem-client')

module.exports = function(deps) {
var home = deps.getPluginPath()()[0]
module.exports = function(pluginsPath) {
var local = require('./local_plugins')(pluginsPath)
var home = pluginsPath[0]

/*
* Callback signature:
* cb(Error anyError, Boolean restartOrNot)
*/
return function(name, cb) {
var pluginPath = path.join(home, name)
console.log(pluginPath)
if (fs.existsSync(pluginPath)) {
afterCloned(pluginPath, cb)
} else {
var client = require('strider-ecosystem-client')
client.fetchPlugin(name).then(function(plugin) {
git.clone(plugin.git_url, pluginPath, function(err) {
if (err) throw err;
console.log('cloned')
local.listAllZipped(function (err, localPlugins) {
if (err) return cb(err);
client.fetchPlugins().then(function(remotePlugins) {
var local = localPlugins[name]
var remote = remotePlugins[name]
if (!remote) {
console.error(name+' is not a valid plugin')
return cb();
}

var pluginPath = path.join(home, remote.module_name)

if (local || fs.existsSync(pluginPath)) {
afterCloned(pluginPath, cb)
})
} else if (remote) {
git.clone(remote.repo, remote.tag, pluginPath, function(err) {
if (err) return cb(err)
afterCloned(pluginPath, cb)
})
}
}).error(cb).catch(cb)
}
})
}
}

Expand Down
5 changes: 2 additions & 3 deletions plugin_manager/list_local_plugins.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = function(deps) {
module.exports = function(pluginsPath) {
var Table = require('cli-table');
var path = require('path')
var localPlugins = require('./local_plugins')(deps)
var localPlugins = require('./local_plugins')(pluginsPath)
var table = new Table({
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
head: ['name', 'version']
Expand Down
25 changes: 13 additions & 12 deletions plugin_manager/list_remote_plugins.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
module.exports = function(deps) {
module.exports = function(pluginsPath) {
var _ = require('lodash')
var Table = require('cli-table');
var table = new Table({
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
head: ['name', 'stable', 'installed']
head: ['name', 'description', 'stable', 'installed']
});
var getPluginPath = deps.getPluginPath()
var path = require('path')
var local = require('./local_plugins')(deps)

var local = require('./local_plugins')(pluginsPath)

var client = require('strider-ecosystem-client')

client.fetchPlugins().then(function(remotePlugins) {
local.listAll(function (err, localPlugins) {
localPlugins = local.zip(localPlugins)
remotePlugins.forEach(function (plugin) {
var local = localPlugins[plugin.name]
local.listAllZipped(function (err, localPlugins) {
Object.keys(remotePlugins).forEach(function (name) {
var remote = remotePlugins[name]
var local = localPlugins[name]
console.log(remote);
table.push([
plugin.name,
plugin.version,
local ? local.version : ''
name,
remote.description,
remote.tag,
local ? local.version : 'no'
])
})
console.log(table.toString());
Expand Down
62 changes: 35 additions & 27 deletions plugin_manager/local_plugins.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
module.exports = function(deps) {
var getPluginPath = deps.getPluginPath()
module.exports = function(pluginsPath) {
var Loader = require('strider-extension-loader')
var loader = new Loader();

var path = require('path')
var glob = require('glob')
var _ = require('lodash')

return {
path: fullPath,
listAll: listAll,
zip: function (plugins) {
return _.zipObject(
_.pluck(plugins, 'name'),
_.map(plugins, function (plugin) {
return {
version: plugin.version,
path: plugin.path
}
})
)
}
listAllZipped: listAllZipped
}

function zip(plugins) {
var ids = _.pluck(plugins, 'name')
return _.zipObject(ids, plugins)
}

function fullPath() {
return getPluginPath()[0]
return pluginsPath[0]
}

function getPluginFullPaths(cb) {
glob(path.join(fullPath(), 'strider-*'), cb)
function getVersion(pluginPath) {
return require(path.join(pluginPath, 'package.json')).version
}

function listAll(cb) {
getPluginFullPaths(function (err, plugins) {
var out = []
plugins.forEach(function (fullPath) {
out.push({
path: fullPath,
name: path.basename(fullPath),
version: require(path.join(fullPath, 'package.json')).version
})
})
cb(err, out);
loader.collectExtensions(pluginsPath, function(err) {
var plugins = []
var extensions = loader.extensions;
for (var groupName in extensions) {
var group = extensions[groupName]
for (var pluginName in group) {
var plugin = group[pluginName]
plugins.push({
group: groupName,
name: pluginName,
path: plugin.dir,
version: getVersion(plugin.dir)
})
}
}
cb(err, plugins);
})
}

function listAllZipped(cb) {
listAll(function(err, plugins) {
cb(err, zip(plugins))
})
}
}
12 changes: 7 additions & 5 deletions plugin_manager/uninstall_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ var _ = require('lodash')
, path = require('path')
, rimraf = require('rimraf')

module.exports = function(deps) {
var localPlugins = require('./local_plugins')(deps)
module.exports = function(pluginsPath) {
var local = require('./local_plugins')(pluginsPath)

/*
* Callback signature:
* cb(Error anyError, Boolean restartOrNot)
*/
return function(name, cb) {
localPlugins.listAll(function (err, plugins) {
var plugin = _.find(plugins, { name: name });
local.listAllZipped(function (err, plugins) {
var plugin = plugins[name]
if (plugin) {
rimraf(plugin.path, function(err) {
cb(err, true)
console.log('removed '+plugin.path)
})
} else {
cb(new Error(name+' not found'))
console.error(name+' not found')
cb()
}
})
}
Expand Down

0 comments on commit d647b95

Please sign in to comment.