@makano/rew 1.1.7 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/README.md +1 -1
  2. package/bin/ui +0 -0
  3. package/build.sh +3 -1
  4. package/lib/coffeescript/browser.js +144 -139
  5. package/lib/coffeescript/cake.js +132 -133
  6. package/lib/coffeescript/coffeescript.js +437 -381
  7. package/lib/coffeescript/command.js +806 -724
  8. package/lib/coffeescript/grammar.js +1908 -2474
  9. package/lib/coffeescript/helpers.js +509 -473
  10. package/lib/coffeescript/index.js +228 -215
  11. package/lib/coffeescript/lexer.js +2282 -1909
  12. package/lib/coffeescript/nodes.js +9782 -9202
  13. package/lib/coffeescript/optparse.js +255 -227
  14. package/lib/coffeescript/parser.js +20305 -1265
  15. package/lib/coffeescript/register.js +107 -87
  16. package/lib/coffeescript/repl.js +307 -284
  17. package/lib/coffeescript/rewriter.js +1389 -1079
  18. package/lib/coffeescript/scope.js +176 -172
  19. package/lib/coffeescript/sourcemap.js +242 -227
  20. package/lib/rew/cli/cli.js +245 -186
  21. package/lib/rew/cli/log.js +31 -32
  22. package/lib/rew/cli/run.js +10 -12
  23. package/lib/rew/cli/utils.js +248 -175
  24. package/lib/rew/const/config_path.js +4 -0
  25. package/lib/rew/const/default.js +38 -35
  26. package/lib/rew/const/files.js +9 -9
  27. package/lib/rew/const/opt.js +8 -8
  28. package/lib/rew/css/theme.css +2 -2
  29. package/lib/rew/functions/core.js +55 -57
  30. package/lib/rew/functions/curl.js +23 -0
  31. package/lib/rew/functions/emitter.js +52 -55
  32. package/lib/rew/functions/exec.js +25 -21
  33. package/lib/rew/functions/export.js +18 -20
  34. package/lib/rew/functions/fs.js +55 -54
  35. package/lib/rew/functions/future.js +29 -21
  36. package/lib/rew/functions/id.js +8 -9
  37. package/lib/rew/functions/import.js +104 -93
  38. package/lib/rew/functions/map.js +13 -16
  39. package/lib/rew/functions/match.js +35 -26
  40. package/lib/rew/functions/path.js +8 -8
  41. package/lib/rew/functions/require.js +32 -33
  42. package/lib/rew/functions/sleep.js +2 -2
  43. package/lib/rew/functions/stdout.js +20 -20
  44. package/lib/rew/functions/types.js +96 -95
  45. package/lib/rew/html/ui.html +12 -13
  46. package/lib/rew/html/ui.js +205 -168
  47. package/lib/rew/main.js +14 -14
  48. package/lib/rew/misc/findAppInfo.js +16 -0
  49. package/lib/rew/misc/findAppPath.js +21 -0
  50. package/lib/rew/misc/seededid.js +13 -0
  51. package/lib/rew/models/enum.js +12 -12
  52. package/lib/rew/models/struct.js +30 -32
  53. package/lib/rew/modules/compiler.js +228 -177
  54. package/lib/rew/modules/context.js +35 -22
  55. package/lib/rew/modules/fs.js +10 -10
  56. package/lib/rew/modules/runtime.js +17 -21
  57. package/lib/rew/modules/yaml.js +27 -30
  58. package/lib/rew/pkgs/conf.js +82 -75
  59. package/lib/rew/pkgs/data.js +12 -7
  60. package/lib/rew/pkgs/date.js +27 -28
  61. package/lib/rew/pkgs/env.js +6 -8
  62. package/lib/rew/pkgs/modules/data/bintree.js +52 -52
  63. package/lib/rew/pkgs/modules/data/doublylinked.js +85 -85
  64. package/lib/rew/pkgs/modules/data/linkedList.js +73 -73
  65. package/lib/rew/pkgs/modules/data/queue.js +19 -20
  66. package/lib/rew/pkgs/modules/data/stack.js +19 -19
  67. package/lib/rew/pkgs/modules/threads/worker.js +36 -26
  68. package/lib/rew/pkgs/modules/ui/classes.js +182 -178
  69. package/lib/rew/pkgs/pkgs.js +9 -10
  70. package/lib/rew/pkgs/rune.js +422 -0
  71. package/lib/rew/pkgs/threads.js +57 -53
  72. package/lib/rew/pkgs/ui.js +148 -136
  73. package/meson.build +13 -0
  74. package/package.json +9 -2
package/README.md CHANGED
@@ -12,7 +12,7 @@ Rew
12
12
  <a href="https://www.npmjs.com/package/rayous"> <img src="https://img.shields.io/npm/v/@makano/rew?style=for-the-badge&logo=npm&color=b4befe&logoColor=9399b2&labelColor=181825" alt="npm version" /></a>
13
13
  </p>
14
14
 
15
- Rayous is a simple lightweight coffeescript runtime, made to simply using coffescript and revive it
15
+ Rew is a simple lightweight coffeescript runtime, made to simply using coffescript and revive it
16
16
  in the process.
17
17
 
18
18
  ## Getting Started
package/bin/ui CHANGED
Binary file
package/build.sh CHANGED
@@ -3,4 +3,6 @@ opath=./bin/ui
3
3
  if [ $1 ]; then
4
4
  opath=$1
5
5
  fi
6
- g++ ./cpp/ui.cpp -o $opath `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0 libwebsockets jsoncpp`
6
+ # g++ ./cpp/ui.cpp -o $opath `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0 libwebsockets jsoncpp`
7
+ meson build
8
+ cd build && ninja && mv ./ui $opath && cd ../ && rm -r ./build
@@ -1,151 +1,156 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- (function() {
3
- // This **Browser** compatibility layer extends core CoffeeScript functions
4
- // to make things work smoothly when compiling code directly in the browser.
5
- // We add support for loading remote Coffee scripts via **XHR**, and
6
- // `text/coffeescript` script tags, source maps via data-URLs, and so on.
7
- var CoffeeScript, compile,
8
- indexOf = [].indexOf;
2
+ (function () {
3
+ // This **Browser** compatibility layer extends core CoffeeScript functions
4
+ // to make things work smoothly when compiling code directly in the browser.
5
+ // We add support for loading remote Coffee scripts via **XHR**, and
6
+ // `text/coffeescript` script tags, source maps via data-URLs, and so on.
7
+ var CoffeeScript,
8
+ compile,
9
+ indexOf = [].indexOf;
9
10
 
10
- CoffeeScript = require('./coffeescript');
11
+ CoffeeScript = require('./coffeescript');
11
12
 
12
- ({compile} = CoffeeScript);
13
+ ({ compile } = CoffeeScript);
13
14
 
14
- // Use `window.eval` to evaluate code, rather than just `eval`, to run the
15
- // script in a clean global scope rather than inheriting the scope of the
16
- // CoffeeScript compiler. (So that `cake test:browser` also works in Node,
17
- // use either `window.eval` or `global.eval` as appropriate).
18
- CoffeeScript.eval = function(code, options = {}) {
19
- var globalRoot;
20
- if (options.bare == null) {
21
- options.bare = true;
22
- }
23
- globalRoot = typeof window !== "undefined" && window !== null ? window : global;
24
- return globalRoot['eval'](compile(code, options));
25
- };
15
+ // Use `window.eval` to evaluate code, rather than just `eval`, to run the
16
+ // script in a clean global scope rather than inheriting the scope of the
17
+ // CoffeeScript compiler. (So that `cake test:browser` also works in Node,
18
+ // use either `window.eval` or `global.eval` as appropriate).
19
+ CoffeeScript.eval = function (code, options = {}) {
20
+ var globalRoot;
21
+ if (options.bare == null) {
22
+ options.bare = true;
23
+ }
24
+ globalRoot = typeof window !== 'undefined' && window !== null ? window : global;
25
+ return globalRoot['eval'](compile(code, options));
26
+ };
26
27
 
27
- // Running code does not provide access to this scope.
28
- CoffeeScript.run = function(code, options = {}) {
29
- options.bare = true;
30
- options.shiftLine = true;
31
- return Function(compile(code, options))();
32
- };
28
+ // Running code does not provide access to this scope.
29
+ CoffeeScript.run = function (code, options = {}) {
30
+ options.bare = true;
31
+ options.shiftLine = true;
32
+ return Function(compile(code, options))();
33
+ };
33
34
 
34
- // Export this more limited `CoffeeScript` than what is exported by
35
- // `index.coffee`, which is intended for a Node environment.
36
- module.exports = CoffeeScript;
35
+ // Export this more limited `CoffeeScript` than what is exported by
36
+ // `index.coffee`, which is intended for a Node environment.
37
+ module.exports = CoffeeScript;
37
38
 
38
- // If we’re not in a browser environment, we’re finished with the public API.
39
- if (typeof window === "undefined" || window === null) {
40
- return;
41
- }
39
+ // If we’re not in a browser environment, we’re finished with the public API.
40
+ if (typeof window === 'undefined' || window === null) {
41
+ return;
42
+ }
42
43
 
43
- // Include source maps where possible. If we’ve got a base64 encoder, a
44
- // JSON serializer, and tools for escaping unicode characters, we’re good to go.
45
- // Ported from https://developer.mozilla.org/en-US/docs/DOM/window.btoa
46
- if ((typeof btoa !== "undefined" && btoa !== null) && (typeof JSON !== "undefined" && JSON !== null)) {
47
- compile = function(code, options = {}) {
48
- options.inlineMap = true;
49
- return CoffeeScript.compile(code, options);
50
- };
51
- }
44
+ // Include source maps where possible. If we’ve got a base64 encoder, a
45
+ // JSON serializer, and tools for escaping unicode characters, we’re good to go.
46
+ // Ported from https://developer.mozilla.org/en-US/docs/DOM/window.btoa
47
+ if (typeof btoa !== 'undefined' && btoa !== null && typeof JSON !== 'undefined' && JSON !== null) {
48
+ compile = function (code, options = {}) {
49
+ options.inlineMap = true;
50
+ return CoffeeScript.compile(code, options);
51
+ };
52
+ }
52
53
 
53
- // Load a remote script from the current domain via XHR.
54
- CoffeeScript.load = function(url, callback, options = {}, hold = false) {
55
- var xhr;
56
- options.sourceFiles = [url];
57
- xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new window.XMLHttpRequest();
58
- xhr.open('GET', url, true);
59
- if ('overrideMimeType' in xhr) {
60
- xhr.overrideMimeType('text/plain');
61
- }
62
- xhr.onreadystatechange = function() {
63
- var param, ref;
64
- if (xhr.readyState === 4) {
65
- if ((ref = xhr.status) === 0 || ref === 200) {
66
- param = [xhr.responseText, options];
67
- if (!hold) {
68
- CoffeeScript.run(...param);
69
- }
70
- } else {
71
- throw new Error(`Could not load ${url}`);
72
- }
73
- if (callback) {
74
- return callback(param);
75
- }
76
- }
77
- };
78
- return xhr.send(null);
79
- };
54
+ // Load a remote script from the current domain via XHR.
55
+ CoffeeScript.load = function (url, callback, options = {}, hold = false) {
56
+ var xhr;
57
+ options.sourceFiles = [url];
58
+ xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new window.XMLHttpRequest();
59
+ xhr.open('GET', url, true);
60
+ if ('overrideMimeType' in xhr) {
61
+ xhr.overrideMimeType('text/plain');
62
+ }
63
+ xhr.onreadystatechange = function () {
64
+ var param, ref;
65
+ if (xhr.readyState === 4) {
66
+ if ((ref = xhr.status) === 0 || ref === 200) {
67
+ param = [xhr.responseText, options];
68
+ if (!hold) {
69
+ CoffeeScript.run(...param);
70
+ }
71
+ } else {
72
+ throw new Error(`Could not load ${url}`);
73
+ }
74
+ if (callback) {
75
+ return callback(param);
76
+ }
77
+ }
78
+ };
79
+ return xhr.send(null);
80
+ };
80
81
 
81
- // Activate CoffeeScript in the browser by having it compile and evaluate
82
- // all script tags with a content-type of `text/coffeescript`.
83
- // This happens on page load.
84
- CoffeeScript.runScripts = function() {
85
- var coffees, coffeetypes, execute, i, index, j, len, s, script, scripts;
86
- scripts = window.document.getElementsByTagName('script');
87
- coffeetypes = ['text/coffeescript', 'text/literate-coffeescript'];
88
- coffees = (function() {
89
- var j, len, ref, results;
90
- results = [];
91
- for (j = 0, len = scripts.length; j < len; j++) {
92
- s = scripts[j];
93
- if (ref = s.type, indexOf.call(coffeetypes, ref) >= 0) {
94
- results.push(s);
95
- }
96
- }
97
- return results;
98
- })();
99
- index = 0;
100
- execute = function() {
101
- var param;
102
- param = coffees[index];
103
- if (param instanceof Array) {
104
- CoffeeScript.run(...param);
105
- index++;
106
- return execute();
107
- }
108
- };
109
- for (i = j = 0, len = coffees.length; j < len; i = ++j) {
110
- script = coffees[i];
111
- (function(script, i) {
112
- var options, source;
113
- options = {
114
- literate: script.type === coffeetypes[1]
115
- };
116
- source = script.src || script.getAttribute('data-src');
117
- if (source) {
118
- options.filename = source;
119
- return CoffeeScript.load(source, function(param) {
120
- coffees[i] = param;
121
- return execute();
122
- }, options, true);
123
- } else {
124
- // `options.filename` defines the filename the source map appears as
125
- // in Developer Tools. If a script tag has an `id`, use that as the
126
- // filename; otherwise use `coffeescript`, or `coffeescript1` etc.,
127
- // leaving the first one unnumbered for the common case that there’s
128
- // only one CoffeeScript script block to parse.
129
- options.filename = script.id && script.id !== '' ? script.id : `coffeescript${i !== 0 ? i : ''}`;
130
- options.sourceFiles = ['embedded'];
131
- return coffees[i] = [script.innerHTML, options];
132
- }
133
- })(script, i);
134
- }
135
- return execute();
136
- };
137
-
138
- // Listen for window load, both in decent browsers and in IE.
139
- // Only attach this event handler on startup for the
140
- // non-ES module version of the browser compiler, to preserve
141
- // backward compatibility while letting the ES module version
142
- // be importable without side effects.
143
- if (this === window) {
144
- if (window.addEventListener) {
145
- window.addEventListener('DOMContentLoaded', CoffeeScript.runScripts, false);
146
- } else {
147
- window.attachEvent('onload', CoffeeScript.runScripts);
148
- }
149
- }
82
+ // Activate CoffeeScript in the browser by having it compile and evaluate
83
+ // all script tags with a content-type of `text/coffeescript`.
84
+ // This happens on page load.
85
+ CoffeeScript.runScripts = function () {
86
+ var coffees, coffeetypes, execute, i, index, j, len, s, script, scripts;
87
+ scripts = window.document.getElementsByTagName('script');
88
+ coffeetypes = ['text/coffeescript', 'text/literate-coffeescript'];
89
+ coffees = (function () {
90
+ var j, len, ref, results;
91
+ results = [];
92
+ for (j = 0, len = scripts.length; j < len; j++) {
93
+ s = scripts[j];
94
+ if (((ref = s.type), indexOf.call(coffeetypes, ref) >= 0)) {
95
+ results.push(s);
96
+ }
97
+ }
98
+ return results;
99
+ })();
100
+ index = 0;
101
+ execute = function () {
102
+ var param;
103
+ param = coffees[index];
104
+ if (param instanceof Array) {
105
+ CoffeeScript.run(...param);
106
+ index++;
107
+ return execute();
108
+ }
109
+ };
110
+ for (i = j = 0, len = coffees.length; j < len; i = ++j) {
111
+ script = coffees[i];
112
+ (function (script, i) {
113
+ var options, source;
114
+ options = {
115
+ literate: script.type === coffeetypes[1],
116
+ };
117
+ source = script.src || script.getAttribute('data-src');
118
+ if (source) {
119
+ options.filename = source;
120
+ return CoffeeScript.load(
121
+ source,
122
+ function (param) {
123
+ coffees[i] = param;
124
+ return execute();
125
+ },
126
+ options,
127
+ true,
128
+ );
129
+ } else {
130
+ // `options.filename` defines the filename the source map appears as
131
+ // in Developer Tools. If a script tag has an `id`, use that as the
132
+ // filename; otherwise use `coffeescript`, or `coffeescript1` etc.,
133
+ // leaving the first one unnumbered for the common case that there’s
134
+ // only one CoffeeScript script block to parse.
135
+ options.filename = script.id && script.id !== '' ? script.id : `coffeescript${i !== 0 ? i : ''}`;
136
+ options.sourceFiles = ['embedded'];
137
+ return (coffees[i] = [script.innerHTML, options]);
138
+ }
139
+ })(script, i);
140
+ }
141
+ return execute();
142
+ };
150
143
 
144
+ // Listen for window load, both in decent browsers and in IE.
145
+ // Only attach this event handler on startup for the
146
+ // non-ES module version of the browser compiler, to preserve
147
+ // backward compatibility while letting the ES module version
148
+ // be importable without side effects.
149
+ if (this === window) {
150
+ if (window.addEventListener) {
151
+ window.addEventListener('DOMContentLoaded', CoffeeScript.runScripts, false);
152
+ } else {
153
+ window.attachEvent('onload', CoffeeScript.runScripts);
154
+ }
155
+ }
151
156
  }).call(this);
@@ -1,135 +1,134 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- (function() {
3
- // `cake` is a simplified version of [Make](http://www.gnu.org/software/make/)
4
- // ([Rake](http://rake.rubyforge.org/), [Jake](https://github.com/280north/jake))
5
- // for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
6
- // and can call them from the command line, or invoke them from other tasks.
7
-
8
- // Running `cake` with no arguments will print out a list of all the tasks in the
9
- // current directory's Cakefile.
10
-
11
- // External dependencies.
12
- var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
13
-
14
- fs = require('fs');
15
-
16
- path = require('path');
17
-
18
- helpers = require('./helpers');
19
-
20
- optparse = require('./optparse');
21
-
22
- CoffeeScript = require('./');
23
-
24
- // Register .coffee extension
25
- CoffeeScript.register();
26
-
27
- // Keep track of the list of defined tasks, the accepted options, and so on.
28
- tasks = {};
29
-
30
- options = {};
31
-
32
- switches = [];
33
-
34
- oparse = null;
35
-
36
- // Mixin the top-level Cake functions for Cakefiles to use directly.
37
- helpers.extend(global, {
38
- // Define a Cake task with a short name, an optional sentence description,
39
- // and the function to run as the action itself.
40
- task: function(name, description, action) {
41
- if (!action) {
42
- [action, description] = [description, action];
43
- }
44
- return tasks[name] = {name, description, action};
45
- },
46
- // Define an option that the Cakefile accepts. The parsed options hash,
47
- // containing all of the command-line options passed, will be made available
48
- // as the first argument to the action.
49
- option: function(letter, flag, description) {
50
- return switches.push([letter, flag, description]);
51
- },
52
- // Invoke another task in the current Cakefile.
53
- invoke: function(name) {
54
- if (!tasks[name]) {
55
- missingTask(name);
56
- }
57
- return tasks[name].action(options);
58
- }
59
- });
60
-
61
- // Run `cake`. Executes all of the tasks you pass, in order. Note that Node's
62
- // asynchrony may cause tasks to execute in a different order than you'd expect.
63
- // If no tasks are passed, print the help screen. Keep a reference to the
64
- // original directory name, when running Cake tasks from subdirectories.
65
- exports.run = function() {
66
- var arg, args, e, i, len, ref, results;
67
- global.__originalDirname = fs.realpathSync('.');
68
- process.chdir(cakefileDirectory(__originalDirname));
69
- args = process.argv.slice(2);
70
- CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
71
- filename: 'Cakefile'
72
- });
73
- oparse = new optparse.OptionParser(switches);
74
- if (!args.length) {
75
- return printTasks();
76
- }
77
- try {
78
- options = oparse.parse(args);
79
- } catch (error) {
80
- e = error;
81
- return fatalError(`${e}`);
82
- }
83
- ref = options.arguments;
84
- results = [];
85
- for (i = 0, len = ref.length; i < len; i++) {
86
- arg = ref[i];
87
- results.push(invoke(arg));
88
- }
89
- return results;
90
- };
91
-
92
- // Display the list of Cake tasks in a format similar to `rake -T`
93
- printTasks = function() {
94
- var cakefilePath, desc, name, relative, spaces, task;
95
- relative = path.relative || path.resolve;
96
- cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
97
- console.log(`${cakefilePath} defines the following tasks:\n`);
98
- for (name in tasks) {
99
- task = tasks[name];
100
- spaces = 20 - name.length;
101
- spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
102
- desc = task.description ? `# ${task.description}` : '';
103
- console.log(`cake ${name}${spaces} ${desc}`);
104
- }
105
- if (switches.length) {
106
- return console.log(oparse.help());
107
- }
108
- };
109
-
110
- // Print an error and exit when attempting to use an invalid task/option.
111
- fatalError = function(message) {
112
- console.error(message + '\n');
113
- console.log('To see a list of all tasks/options, run "cake"');
114
- return process.exit(1);
115
- };
116
-
117
- missingTask = function(task) {
118
- return fatalError(`No such task: ${task}`);
119
- };
120
-
121
- // When `cake` is invoked, search in the current and all parent directories
122
- // to find the relevant Cakefile.
123
- cakefileDirectory = function(dir) {
124
- var parent;
125
- if (fs.existsSync(path.join(dir, 'Cakefile'))) {
126
- return dir;
127
- }
128
- parent = path.normalize(path.join(dir, '..'));
129
- if (parent !== dir) {
130
- return cakefileDirectory(parent);
131
- }
132
- throw new Error(`Cakefile not found in ${process.cwd()}`);
133
- };
134
-
2
+ (function () {
3
+ // `cake` is a simplified version of [Make](http://www.gnu.org/software/make/)
4
+ // ([Rake](http://rake.rubyforge.org/), [Jake](https://github.com/280north/jake))
5
+ // for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
6
+ // and can call them from the command line, or invoke them from other tasks.
7
+
8
+ // Running `cake` with no arguments will print out a list of all the tasks in the
9
+ // current directory's Cakefile.
10
+
11
+ // External dependencies.
12
+ var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
13
+
14
+ fs = require('fs');
15
+
16
+ path = require('path');
17
+
18
+ helpers = require('./helpers');
19
+
20
+ optparse = require('./optparse');
21
+
22
+ CoffeeScript = require('./');
23
+
24
+ // Register .coffee extension
25
+ CoffeeScript.register();
26
+
27
+ // Keep track of the list of defined tasks, the accepted options, and so on.
28
+ tasks = {};
29
+
30
+ options = {};
31
+
32
+ switches = [];
33
+
34
+ oparse = null;
35
+
36
+ // Mixin the top-level Cake functions for Cakefiles to use directly.
37
+ helpers.extend(global, {
38
+ // Define a Cake task with a short name, an optional sentence description,
39
+ // and the function to run as the action itself.
40
+ task: function (name, description, action) {
41
+ if (!action) {
42
+ [action, description] = [description, action];
43
+ }
44
+ return (tasks[name] = { name, description, action });
45
+ },
46
+ // Define an option that the Cakefile accepts. The parsed options hash,
47
+ // containing all of the command-line options passed, will be made available
48
+ // as the first argument to the action.
49
+ option: function (letter, flag, description) {
50
+ return switches.push([letter, flag, description]);
51
+ },
52
+ // Invoke another task in the current Cakefile.
53
+ invoke: function (name) {
54
+ if (!tasks[name]) {
55
+ missingTask(name);
56
+ }
57
+ return tasks[name].action(options);
58
+ },
59
+ });
60
+
61
+ // Run `cake`. Executes all of the tasks you pass, in order. Note that Node's
62
+ // asynchrony may cause tasks to execute in a different order than you'd expect.
63
+ // If no tasks are passed, print the help screen. Keep a reference to the
64
+ // original directory name, when running Cake tasks from subdirectories.
65
+ exports.run = function () {
66
+ var arg, args, e, i, len, ref, results;
67
+ global.__originalDirname = fs.realpathSync('.');
68
+ process.chdir(cakefileDirectory(__originalDirname));
69
+ args = process.argv.slice(2);
70
+ CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
71
+ filename: 'Cakefile',
72
+ });
73
+ oparse = new optparse.OptionParser(switches);
74
+ if (!args.length) {
75
+ return printTasks();
76
+ }
77
+ try {
78
+ options = oparse.parse(args);
79
+ } catch (error) {
80
+ e = error;
81
+ return fatalError(`${e}`);
82
+ }
83
+ ref = options.arguments;
84
+ results = [];
85
+ for (i = 0, len = ref.length; i < len; i++) {
86
+ arg = ref[i];
87
+ results.push(invoke(arg));
88
+ }
89
+ return results;
90
+ };
91
+
92
+ // Display the list of Cake tasks in a format similar to `rake -T`
93
+ printTasks = function () {
94
+ var cakefilePath, desc, name, relative, spaces, task;
95
+ relative = path.relative || path.resolve;
96
+ cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
97
+ console.log(`${cakefilePath} defines the following tasks:\n`);
98
+ for (name in tasks) {
99
+ task = tasks[name];
100
+ spaces = 20 - name.length;
101
+ spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
102
+ desc = task.description ? `# ${task.description}` : '';
103
+ console.log(`cake ${name}${spaces} ${desc}`);
104
+ }
105
+ if (switches.length) {
106
+ return console.log(oparse.help());
107
+ }
108
+ };
109
+
110
+ // Print an error and exit when attempting to use an invalid task/option.
111
+ fatalError = function (message) {
112
+ console.error(message + '\n');
113
+ console.log('To see a list of all tasks/options, run "cake"');
114
+ return process.exit(1);
115
+ };
116
+
117
+ missingTask = function (task) {
118
+ return fatalError(`No such task: ${task}`);
119
+ };
120
+
121
+ // When `cake` is invoked, search in the current and all parent directories
122
+ // to find the relevant Cakefile.
123
+ cakefileDirectory = function (dir) {
124
+ var parent;
125
+ if (fs.existsSync(path.join(dir, 'Cakefile'))) {
126
+ return dir;
127
+ }
128
+ parent = path.normalize(path.join(dir, '..'));
129
+ if (parent !== dir) {
130
+ return cakefileDirectory(parent);
131
+ }
132
+ throw new Error(`Cakefile not found in ${process.cwd()}`);
133
+ };
135
134
  }).call(this);