UNPKG

load-cakefile

Version:

Load or require the contents of Cakefiles

67 lines (57 loc) 1.62 kB
// Generated by CoffeeScript 1.7.1 var CoffeeScript, exports, fs, loadCakefile, merge, path, requireCakefile, runTaskFromCakefile, tasksFromCakefile; fs = require('fs'); path = require('path'); CoffeeScript = require('coffee-script'); merge = require('xtend'); module.exports = exports = {}; exports.load = loadCakefile = function(filepath) { var options, sandbox, switches, tasks; if (filepath == null) { filepath = 'Cakefile'; } tasks = {}; options = {}; switches = []; sandbox = merge(global, { task: function(name, description, action) { var _ref; if (!action) { _ref = [description, action], action = _ref[0], description = _ref[1]; } return tasks[name] = { name: name, description: description, action: action }; }, option: function(letter, flag, description) { return switches.push([letter, flag, description]); }, invoke: function(name) { if (!tasks[name]) { missingTask(name); } return tasks[name].action(options); } }); CoffeeScript["eval"](fs.readFileSync(filepath).toString(), { filename: 'Cakefile', sandbox: sandbox }); return { tasks: tasks, options: options, switches: switches, exports: sandbox.module.exports }; }; exports.require = requireCakefile = function(filepath) { return loadCakefile(filepath).exports; }; exports.tasks = tasksFromCakefile = function(filepath) { return loadCakefile(filepath).tasks; }; exports.runTask = runTaskFromCakefile = function(filepath, options) { return loadCakefile(filepath).tasks; };