UNPKG

mina

Version:

Lightweight deployer for node development, inspired by mina and minco

109 lines (95 loc) 2.94 kB
// Generated by CoffeeScript 1.8.0 (function() { var clc, deploy, do_deploy, fs, init_config, log_err, log_info, parse_config, path, print_completion, print_usage; fs = require("fs"); path = require("path"); clc = require("cli-color"); parse_config = (require("./config")).parse; deploy = require("./deploy").deploy; log_err = function(t) { return console.log(clc.red(t)); }; log_info = function(t) { return console.log(clc.yellow(t)); }; exports.run = function(args) { switch (args[0]) { case "help": return print_usage(); case "init": return init_config(); case "deploy": return do_deploy(args[1]); case "completion=bash": return print_completion('bash'); case "completion=zsh": return print_completion('zsh'); default: return print_usage(); } }; print_completion = function(name) { var code, filepath; code = 0; filepath = path.join(__dirname, '../completion', name); console.log(String(fs.readFileSync(filepath))); return process.exit(code); }; print_usage = function() { var cmd, commands, desc, _results; commands = { deploy: "Deploy using the given config file or $MINA_CONFIG or deploy.json", init: "Write an example config file", help: "That's me" }; console.log("Usage: mina [command] [config file]\n"); console.log(clc.yellow("Commands:")); _results = []; for (cmd in commands) { desc = commands[cmd]; _results.push(console.log("" + cmd + ":\t" + desc)); } return _results; }; do_deploy = function(config_path) { var config, e, _ref; if (config_path == null) { config_path = (_ref = process.env["MINA_CONFIG"]) != null ? _ref : "deploy.json"; } if (!fs.existsSync(config_path)) { log_err("Config file '" + config_path + "' not found"); process.exit(1); } log_info("Using config file '" + config_path + "'"); try { config = parse_config(config_path); } catch (_error) { e = _error; log_err("Error parsing config file: " + e); process.exit(1); } return deploy(config); }; init_config = function() { var config_path, example_conf, f; example_conf = { server: "user@host", port: 22, server_dir: "/path/to/dir/on/server", repo: "git@github.com:user/repo.git", prj_git_relative_dir: "", branch: "master", force_regenerate_git_dir: false, shared_dirs: ["node_modules", "db"], prerun: ["npm install", "npm test"], run_cmd: "npm start" }; config_path = "deploy.json"; if (fs.existsSync(config_path)) { log_err("File " + config_path + " already exists. I better dont't touch it!"); process.exit(1); } f = fs.createWriteStream(config_path); return f.end(JSON.stringify(example_conf, null, 2)); }; }).call(this);