UNPKG

easy-bake

Version:

EasyBake provides an efficient environment for CoffeeScript library developers: CoffeeScript/Javascript-based configuration files (no coding needed), workflow (build, watch, clean, preview) tests (QUnit, Jasime, NodeUnit, server-side emulation with ModuleBundler), publishing (git, npm, NuGet). Replace your Cakefile with a Bakefile today!

514 lines (479 loc) 17.7 kB
// Generated by CoffeeScript 1.6.3 (function() { var INTERNAL_MODES, INTERNAL_SETS, MAX_MESSAGE_LENGTH, RUNNERS_ROOT, TEST_DEFAULT_TIMEOUT, coffeescript, eb, existsSync, fs, path, print, spawn, timeLog, _, _base; fs = require('fs'); path = require('path'); existsSync = fs.existsSync || path.existsSync; MAX_MESSAGE_LENGTH = 128; timeLog = function(message) { return console.log("" + ((new Date).toLocaleTimeString()) + " - " + message); }; String.prototype.startsWith = function(start) { return this.indexOf(start) === 0; }; String.prototype.endsWith = function(end) { return this.indexOf(end) === this.length - end.length; }; print = require('util').print; spawn = require('child_process').spawn; coffeescript = require('coffee-script'); if (!global.option) { require('coffee-script/lib/coffee-script/cake'); } _ = require('underscore'); TEST_DEFAULT_TIMEOUT = 60000; RUNNERS_ROOT = "" + __dirname + "/lib/test_runners"; INTERNAL_SETS = ['_postinstall']; INTERNAL_MODES = ['_build', '_test']; eb = this.eb = typeof exports !== 'undefined' ? exports : {}; eb.utils = require('./lib/easy-bake-utils'); eb.command = require('./lib/easy-bake-commands'); if ((_base = require.extensions)['.coffee'] == null) { _base['.coffee'] = function(module, filename) { var content; content = coffeescript.compile(fs.readFileSync(filename, 'utf8', { filename: filename })); return module._compile(content, filename); }; } eb.Oven = (function() { function Oven(config, options) { var config_pathed_filename, error, length; if (options == null) { options = {}; } if (_.isString(config)) { config_pathed_filename = fs.realpathSync(config); this.config_dir = path.dirname(config_pathed_filename); try { this.config = require(config_pathed_filename); } catch (_error) { error = _error; throw "couldn\'t load config " + config + ". " + error; } } else { if (!options.cwd) { throw "options are missing current working directory (cwd)"; } this.config = config; this.config_dir = path.normalize(options.cwd); length = this.config_dir.length; if (this.config_dir[length - 1] === '/') { this.config_dir = this.config_dir.slice(0, length - 1); } } this._validateConfig(); } Oven.prototype._validateConfig = function() { var mode_name, set, set_name, _ref; if (!_.size(this.config)) { console.log("warning: an empty config file was loaded: " + config_pathed_filename); } _ref = this.config; for (set_name in _ref) { set = _ref[set_name]; if (set_name.startsWith('_') && !_.contains(INTERNAL_SETS, set_name)) { console.log("warning: set name '" + set_name + "' is not a recognized internal set. It will be skipped."); } for (mode_name in set) { if (mode_name.startsWith('_') && !_.contains(INTERNAL_MODES, mode_name)) { console.log("warning: mode name '" + mode_name + "' is not a recognized internal mode. It will be skipped."); } } } return this; }; Oven.prototype.postinstall = function(options, callback) { var command_queue, set, set_name, _ref; if (options == null) { options = {}; } command_queue = options.queue ? options.queue : new eb.command.Queue(); _ref = this.config; for (set_name in _ref) { set = _ref[set_name]; if (set_name !== '_postinstall') { continue; } eb.utils.extractSetCommands(set, command_queue, this.config_dir); } if (options.verbose) { command_queue.push({ run: function(run_options, callback, queue) { console.log("postinstall completed with " + (queue.errorCount()) + " error(s)"); return typeof callback === "function" ? callback() : void 0; } }); } if (!options.queue) { command_queue.run(options, callback); } return this; }; Oven.prototype.clean = function(options, callback) { var build_queue, command, command_queue, output_directory, pathed_build_name, pathed_targets, postinstall_queue, _i, _j, _k, _len, _len1, _len2, _ref, _ref1; if (options == null) { options = {}; } command_queue = options.queue ? options.queue : new eb.command.Queue(); if (options.verbose) { command_queue.push({ run: function(run_options, callback, queue) { console.log("------------clean " + (options.preview ? 'started (PREVIEW)' : 'started') + "------------"); return typeof callback === "function" ? callback() : void 0; } }); } build_queue = new eb.command.Queue(); this.build(_.defaults({ clean: false, queue: build_queue }, options)); _ref = build_queue.commands(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { command = _ref[_i]; if (!(command instanceof eb.command.Coffee)) { continue; } output_directory = command.targetDirectory(); pathed_targets = command.pathedTargets(); for (_j = 0, _len1 = pathed_targets.length; _j < _len1; _j++) { pathed_build_name = pathed_targets[_j]; command_queue.push(new eb.command.Remove(["" + pathed_build_name], { cwd: this.config_dir })); if (command.isCompressed()) { command_queue.push(new eb.command.Remove(["" + (eb.utils.compressedName(pathed_build_name))], { cwd: this.config_dir })); } } } postinstall_queue = new eb.command.Queue(); this.postinstall(_.defaults({ clean: false, queue: postinstall_queue }, options)); _ref1 = postinstall_queue.commands(); for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { command = _ref1[_k]; if (!command.createUndoCommand) { continue; } command_queue.push(command.createUndoCommand()); } if (options.verbose) { command_queue.push({ run: function(run_options, callback, queue) { console.log("clean completed with " + (queue.errorCount()) + " error(s)"); return typeof callback === "function" ? callback() : void 0; } }); } if (!options.queue) { command_queue.run(options, callback); } return this; }; Oven.prototype.build = function(options, callback) { var args, command_queue, file_group, file_groups, set, set_name, set_options, _i, _len, _ref; if (options == null) { options = {}; } command_queue = options.queue ? options.queue : new eb.command.Queue(); if (options.clean) { this.clean(_.defaults({ queue: command_queue }, options)); } this.postinstall(options, command_queue); if (options.verbose) { command_queue.push({ run: function(run_options, callback, queue) { console.log("------------build " + (options.preview ? 'started (PREVIEW)' : 'started') + "------------"); return typeof callback === "function" ? callback() : void 0; } }); } _ref = this.config; for (set_name in _ref) { set = _ref[set_name]; if (set_name.startsWith('_')) { continue; } set_options = eb.utils.extractSetOptions(set, '_build'); file_groups = eb.utils.getOptionsFileGroups(set_options, this.config_dir, options); for (_i = 0, _len = file_groups.length; _i < _len; _i++) { file_group = file_groups[_i]; args = []; if (set_options.join) { args.push('-j'); args.push(set_options.join); } args.push('-o'); if (set_options.output) { args.push(set_options.output); } else { args.push(this.config_dir); } args.push('-c'); if (file_group.files) { args = args.concat(_.map(file_group.files, function(file) { return path.join(file_group.directory, file); })); } else { args.push(file_group.directory); } command_queue.push(new eb.command.Coffee(args, _.defaults(_.defaults({ cwd: file_group.directory }, set_options), options))); } eb.utils.extractSetCommands(set_options, command_queue, this.config_dir); if (set_options.bundles) { command_queue.push(new eb.command.Bundle(set_options.bundles, { cwd: this.config_dir })); } } if (options.verbose) { command_queue.push({ run: function(run_options, callback, queue) { console.log("build completed with " + (queue.errorCount()) + " error(s)"); return typeof callback === "function" ? callback() : void 0; } }); } if (!options.queue) { command_queue.run(options, callback); } return this; }; Oven.prototype.test = function(options, callback) { var args, command_queue, easy_bake_runner_used, file, file_group, file_groups, length_base, set, set_name, set_options, test_queue, _i, _j, _len, _len1, _ref, _ref1, _this = this; if (options == null) { options = {}; } command_queue = options.queue ? options.queue : new eb.command.Queue(); if (options.clean) { options = _.defaults({ build: true }, options); } if (options.build || options.watch) { this.build(_.defaults({ test: true, queue: command_queue }, options)); } test_queue = new eb.command.Queue(); command_queue.push(new eb.command.RunQueue(test_queue, 'tests')); if (options.verbose) { test_queue.push({ run: function(run_options, callback, queue) { console.log("------------test " + (options.preview ? 'started (PREVIEW)' : 'started') + "------------"); return typeof callback === "function" ? callback() : void 0; } }); } _ref = this.config; for (set_name in _ref) { set = _ref[set_name]; if (set_name.startsWith('_') || !set.hasOwnProperty('_test')) { continue; } set_options = eb.utils.extractSetOptions(set, '_test'); file_groups = eb.utils.getOptionsFileGroups(set_options, this.config_dir, options); if (set_options.runner && !existsSync(set_options.runner)) { set_options.runner = "" + RUNNERS_ROOT + "/" + set_options.runner; easy_bake_runner_used = true; } for (_i = 0, _len = file_groups.length; _i < _len; _i++) { file_group = file_groups[_i]; if (!file_group.files) { throw "missing files for test in set: " + set_name; } _ref1 = file_group.files; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { file = _ref1[_j]; args = []; if (set_options.runner) { args.push(set_options.runner); } args.push(path.join(file_group.directory, file)); if (set_options.args) { args = args.concat(set_options.args); } if (easy_bake_runner_used) { length_base = set_options.runner ? 2 : 1; if (args.length < (length_base + 1)) { args.push(TEST_DEFAULT_TIMEOUT); } if (args.length < (length_base + 2)) { args.push(true); } } test_queue.push(new eb.command.RunTest(set_options.command, args, { cwd: this.config_dir })); } } eb.utils.extractSetCommands(set, command_queue, this.config_dir); } if (!options.preview) { test_queue.push({ run: function(run_options, callback, queue) { var command, total_error_count, _k, _len2, _ref2; if (!(options.preview || options.verbose)) { total_error_count = 0; console.log("\n-------------GROUP TEST RESULTS--------"); _ref2 = test_queue.commands(); for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { command = _ref2[_k]; if (!(command instanceof eb.command.RunTest)) { continue; } total_error_count += command.exitCode() ? 1 : 0; console.log("" + (command.exitCode() ? '✖' : '✔') + " " + (eb.utils.relativePath(command.fileName(), _this.config_dir)) + (command.exitCode() ? ' (exit code: ' + command.exitCode() + ')' : '')); } console.log("--------------------------------------"); console.log(total_error_count ? "All tests ran with with " + total_error_count + " error(s)" : "All tests ran successfully!"); console.log("--------------------------------------"); } if (typeof callback === "function") { callback(0); } if (!options.watch && !options.no_exit) { return process.exit(queue.errorCount() > 0 ? 1 : 0); } } }); } if (!options.queue) { command_queue.run(options, callback); } return this; }; Oven.prototype.publishPrepare = function(options, callback, name, success_fn) { var command_queue, test_options, test_queue, _this = this; if (options == null) { options = {}; } command_queue = options.queue ? options.queue : new eb.command.Queue(); test_queue = new eb.command.Queue(); command_queue.push(new eb.command.RunQueue(test_queue, name)); if (!options.quick) { test_options = _.defaults({ queue: test_queue }, options); delete test_options['quick']; this.clean(test_options).postinstall(test_options).build(test_options).test(_.defaults({ no_exit: true }, test_options)); } test_queue.push({ run: function(run_options, local_callback, queue) { if (!(options.preview || options.verbose)) { if (queue.errorCount()) { console.log("" + name + " aborted due to " + (queue.errorCount()) + " error(s)"); if (typeof local_callback === "function") { local_callback(queue.errorCount()); } return; } } return success_fn(); } }); if (!options.queue) { command_queue.run(options, callback); } return this; }; Oven.prototype.publishGit = function(options, callback) { var _this = this; if (options == null) { options = {}; } this.publishPrepare(options, callback, 'publish_git', function() { var command; command = new eb.command.PublishGit({ cwd: _this.config_dir }); return command.run(options, function(code) { if (!options.verbose) { return console.log("publish_git completed with " + code + " error(s)"); } }); }); return this; }; Oven.prototype.publishNPM = function(options, callback) { var _this = this; if (options == null) { options = {}; } this.publishPrepare(options, callback, 'publish_npm', function() { var command; command = new eb.command.PublishNPM({ cwd: _this.config_dir, force: options.force }); return command.run(options, function(code) { if (!options.verbose) { return console.log("publish_npm completed with " + code + " error(s)"); } }); }); return this; }; Oven.prototype.publishNuGet = function(options, callback) { var _this = this; if (options == null) { options = {}; } this.publishPrepare(options, callback, 'publish_nuget', function() { var command; command = new eb.command.PublishNuGet({ cwd: _this.config_dir, force: options.force }); return command.run(options, function(code) { if (!options.verbose) { return console.log("publish_nuget completed with " + code + " error(s)"); } }); }); return this; }; Oven.prototype.publishAll = function(options, callback) { var _this = this; if (options == null) { options = {}; } this.publishPrepare(options, callback, 'publish_all', function() { var local_queue; local_queue = new eb.command.Queue(); local_queue.push(new eb.command.PublishNPM({ cwd: _this.config_dir, force: options.force })); local_queue.push(new eb.command.PublishGit({ cwd: _this.config_dir, force: options.force })); local_queue.push(new eb.command.PublishNuGet({ cwd: _this.config_dir, force: options.force })); return local_queue.run(options, function(queue) { return typeof callback === "function" ? callback(queue.errorCount(), this) : void 0; }); }); return this; }; return Oven; })(); }).call(this);