UNPKG

mecano

Version:

Common functions for system deployment.

115 lines (103 loc) 3 kB
// Generated by CoffeeScript 1.11.1 var conditions, connect, each, misc, tilde; each = require('each'); tilde = require('tilde-expansion'); connect = require('ssh2-connect'); misc = require('./index'); conditions = require('./conditions'); /* `options(options, callback)` ---------------------------- Normalize options. An ssh connection is needed if the key "ssh" hold a configuration object. The 'uid' and 'gid' fields will be converted to integer if they match a username or a group. `callback` Received parameters are: * `err` Error object if any. * `options` Sanitized options. */ module.exports.options = function(options, callback) { return each(options).call(function(options, next) { var connection, el, i, j, k, len, len1, mode, ref, ref1, source, target, v; if (typeof options.if_exists === 'string') { options.if_exists = [options.if_exists]; } if (typeof options.unless_exists === 'string') { options.unless_exists = [options.unless_exists]; } if (options.if_exists) { ref = options.if_exists; for (i = j = 0, len = ref.length; j < len; i = ++j) { el = ref[i]; if (el === true && options.target) { options.if_exists[i] = options.target; } } } if (options.unless_exists) { ref1 = options.unless_exists; for (i = k = 0, len1 = ref1.length; k < len1; i = ++k) { v = ref1[i]; if (v === true && options.target) { options.unless_exists[i] = options.target; } } } if (options.chmod) { if (options.mode == null) { options.mode = options.chmod; } } connection = function() { var ref2; if (!options.ssh) { return source(); } if ((ref2 = options.ssh.config) != null ? ref2.host : void 0) { return source(); } return connect(options.ssh, function(err, ssh) { if (err) { return next(err); } options.ssh = ssh; return source(); }); }; source = function() { if (options.source == null) { return target(); } if (/^\w+:/.test(options.source)) { return target(); } return tilde(options.source, function(source) { options.source = source; return target(); }); }; target = function() { if (options.target == null) { return mode(); } if (typeof options.target !== 'string') { return mode(); } if (/^\w+:/.test(options.source)) { return mode(); } return tilde(options.target, function(target) { options.target = target; return mode(); }); }; mode = function() { if (typeof options.mode === 'string') { options.mode = parseInt(options.mode, 8); } return next(); }; return connection(); }).then(function(err) { return callback(err, options); }); };