UNPKG

mecano

Version:

Common functions for system deployment.

61 lines (55 loc) 1.66 kB
// Generated by CoffeeScript 1.11.1 var fs, mustache, path, stream; module.exports = { ssh: null, handler: function(options) { var latestdir, logdir, now; if (!options.serializer) { throw Error("Missing option: serializer"); } if (options.archive == null) { options.archive = false; } if (options.basedir == null) { options.basedir = './log'; } options.basedir = path.resolve(options.basedir); if (options.basename == null) { options.basename = 'localhost'; } if (options.filename == null) { options.filename = "{{basename}}.log"; } options.basedir = mustache.render(options.basedir, options); options.filename = mustache.render(options.filename, options); if (!options.archive) { logdir = path.resolve(options.basedir); } else { latestdir = path.resolve(options.basedir, 'latest'); now = new Date(); if (options.archive === true) { options.archive = ("" + (now.getFullYear())).slice(-2) + ("0" + (now.getFullYear())).slice(-2) + ("0" + (now.getDate())).slice(-2); } logdir = path.resolve(options.basedir, options.archive); } this.mkdir({ shy: true }, logdir); this.call(function() { if (options.stream == null) { options.stream = fs.createWriteStream(path.resolve(logdir, options.filename)); } return this.call(options, stream); }); return this.link({ "if": latestdir, shy: true, source: logdir, target: latestdir }); } }; fs = require('fs'); path = require('path'); mustache = require('mustache'); stream = require('./stream');