Aucune description

cake.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Generated by CoffeeScript 1.3.3
  2. (function() {
  3. var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
  4. fs = require('fs');
  5. path = require('path');
  6. helpers = require('./helpers');
  7. optparse = require('./optparse');
  8. CoffeeScript = require('./coffee-script');
  9. tasks = {};
  10. options = {};
  11. switches = [];
  12. oparse = null;
  13. helpers.extend(global, {
  14. task: function(name, description, action) {
  15. var _ref;
  16. if (!action) {
  17. _ref = [description, action], action = _ref[0], description = _ref[1];
  18. }
  19. return tasks[name] = {
  20. name: name,
  21. description: description,
  22. action: action
  23. };
  24. },
  25. option: function(letter, flag, description) {
  26. return switches.push([letter, flag, description]);
  27. },
  28. invoke: function(name) {
  29. if (!tasks[name]) {
  30. missingTask(name);
  31. }
  32. return tasks[name].action(options);
  33. }
  34. });
  35. exports.run = function() {
  36. var arg, args, _i, _len, _ref, _results;
  37. global.__originalDirname = fs.realpathSync('.');
  38. process.chdir(cakefileDirectory(__originalDirname));
  39. args = process.argv.slice(2);
  40. CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
  41. filename: 'Cakefile'
  42. });
  43. oparse = new optparse.OptionParser(switches);
  44. if (!args.length) {
  45. return printTasks();
  46. }
  47. try {
  48. options = oparse.parse(args);
  49. } catch (e) {
  50. return fatalError("" + e);
  51. }
  52. _ref = options["arguments"];
  53. _results = [];
  54. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  55. arg = _ref[_i];
  56. _results.push(invoke(arg));
  57. }
  58. return _results;
  59. };
  60. printTasks = function() {
  61. var cakefilePath, desc, name, relative, spaces, task;
  62. relative = path.relative || path.resolve;
  63. cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
  64. console.log("" + cakefilePath + " defines the following tasks:\n");
  65. for (name in tasks) {
  66. task = tasks[name];
  67. spaces = 20 - name.length;
  68. spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
  69. desc = task.description ? "# " + task.description : '';
  70. console.log("cake " + name + spaces + " " + desc);
  71. }
  72. if (switches.length) {
  73. return console.log(oparse.help());
  74. }
  75. };
  76. fatalError = function(message) {
  77. console.error(message + '\n');
  78. console.log('To see a list of all tasks/options, run "cake"');
  79. return process.exit(1);
  80. };
  81. missingTask = function(task) {
  82. return fatalError("No such task: " + task);
  83. };
  84. cakefileDirectory = function(dir) {
  85. var parent;
  86. if (path.existsSync(path.join(dir, 'Cakefile'))) {
  87. return dir;
  88. }
  89. parent = path.normalize(path.join(dir, '..'));
  90. if (parent !== dir) {
  91. return cakefileDirectory(parent);
  92. }
  93. throw new Error("Cakefile not found in " + (process.cwd()));
  94. };
  95. }).call(this);