UNPKG

mecano

Version:

Common functions for system deployment.

78 lines (71 loc) 2.17 kB
// Generated by CoffeeScript 1.7.1 var child, conditions, each, fs, misc; fs = require('ssh2-fs'); each = require('each'); misc = require('./misc'); conditions = require('./misc/conditions'); child = require('./misc/child'); module.exports = function(goptions, options, callback) { var finish, result, _ref; _ref = misc.args(arguments), goptions = _ref[0], options = _ref[1], callback = _ref[2]; result = child(); finish = function(err, removed) { if (callback) { callback(err, removed); } return result.end(err, removed); }; misc.options(options, function(err, options) { var removed; if (err) { return finish(err); } removed = 0; return each(options).parallel(goptions.parallel).on('item', function(options, next) { var remove; if (typeof options === 'string') { options = { source: options }; } if (options.source == null) { options.source = options.destination; } if (options.source == null) { return next(new Error("Missing source")); } remove = function() { if (options.ssh) { if (typeof options.log === "function") { options.log("Remove " + options.source); } return fs.exists(options.ssh, options.source, function(err, exists) { if (err) { return next(err); } if (exists) { removed++; } return misc.file.remove(options.ssh, options.source, next); }); } else { return each().files(options.source).on('item', function(file, next) { removed++; if (typeof options.log === "function") { options.log("Remove " + file); } return misc.file.remove(options.ssh, file, next); }).on('error', function(err) { return next(err); }).on('end', function() { return next(); }); } }; return conditions.all(options, next, remove); }).on('both', function(err) { return finish(err, removed); }); }); return result; };