react / wstein / node_modules / jest-cli / node_modules / coffee-script / lib / coffee-script / cake.js
80677 views// Generated by CoffeeScript 1.9.31(function() {2var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;34fs = require('fs');56path = require('path');78helpers = require('./helpers');910optparse = require('./optparse');1112CoffeeScript = require('./coffee-script');1314CoffeeScript.register();1516tasks = {};1718options = {};1920switches = [];2122oparse = null;2324helpers.extend(global, {25task: function(name, description, action) {26var ref;27if (!action) {28ref = [description, action], action = ref[0], description = ref[1];29}30return tasks[name] = {31name: name,32description: description,33action: action34};35},36option: function(letter, flag, description) {37return switches.push([letter, flag, description]);38},39invoke: function(name) {40if (!tasks[name]) {41missingTask(name);42}43return tasks[name].action(options);44}45});4647exports.run = function() {48var arg, args, e, i, len, ref, results;49global.__originalDirname = fs.realpathSync('.');50process.chdir(cakefileDirectory(__originalDirname));51args = process.argv.slice(2);52CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {53filename: 'Cakefile'54});55oparse = new optparse.OptionParser(switches);56if (!args.length) {57return printTasks();58}59try {60options = oparse.parse(args);61} catch (_error) {62e = _error;63return fatalError("" + e);64}65ref = options["arguments"];66results = [];67for (i = 0, len = ref.length; i < len; i++) {68arg = ref[i];69results.push(invoke(arg));70}71return results;72};7374printTasks = function() {75var cakefilePath, desc, name, relative, spaces, task;76relative = path.relative || path.resolve;77cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');78console.log(cakefilePath + " defines the following tasks:\n");79for (name in tasks) {80task = tasks[name];81spaces = 20 - name.length;82spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';83desc = task.description ? "# " + task.description : '';84console.log("cake " + name + spaces + " " + desc);85}86if (switches.length) {87return console.log(oparse.help());88}89};9091fatalError = function(message) {92console.error(message + '\n');93console.log('To see a list of all tasks/options, run "cake"');94return process.exit(1);95};9697missingTask = function(task) {98return fatalError("No such task: " + task);99};100101cakefileDirectory = function(dir) {102var parent;103if (fs.existsSync(path.join(dir, 'Cakefile'))) {104return dir;105}106parent = path.normalize(path.join(dir, '..'));107if (parent !== dir) {108return cakefileDirectory(parent);109}110throw new Error("Cakefile not found in " + (process.cwd()));111};112113}).call(this);114115116