UNPKG

mecano

Version:

Common functions for system deployment.

60 lines (56 loc) 1.55 kB
// Generated by CoffeeScript 1.11.1 var fs, path; module.exports = function(options, callback) { var do_file, do_read_source; options.log({ message: "Entering render", level: 'DEBUG', module: 'mecano/lib/render' }); if (!(options.source || options.content)) { return callback(new Error('Missing source or content')); } if (!options.target) { return callback(new Error('Missing target')); } do_read_source = function() { var ssh; if (!options.source) { return do_file(); } ssh = options.local ? null : options.ssh; return fs.exists(ssh, options.source, function(err, exists) { if (!exists) { return callback(new Error("Invalid source, got " + (JSON.stringify(options.source)))); } return fs.readFile(ssh, options.source, 'utf8', function(err, content) { if (err) { return callback(err); } options.content = content; return do_file(); }); }); }; do_file = (function(_this) { return function() { var extension; if (!options.engine && options.source) { extension = path.extname(options.source); switch (extension) { case '.j2': options.engine = 'nunjunks'; break; case '.eco': options.engine = 'eco'; } } options.source = null; options.header = null; return _this.file(options).then(callback); }; })(this); return do_read_source(); }; fs = require('ssh2-fs'); path = require('path');