Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow Lottefile to be written in CoffeeScript.

Supported Lottefile languages are now: JavaScript, CoffeeScript.
  • Loading branch information...
commit 317f88fcce4c558bc974f69e4eb9ebb2f1b9a0ca 1 parent 859476e
@StanAngeloff authored
Showing with 57 additions and 38 deletions.
  1. +5 −6 Lottefile
  2. +1 −1  bin/cli.js
  3. +7 −31 lib/lotte.js
  4. +44 −0 lib/utils.js
View
11 Lottefile
@@ -1,7 +1,6 @@
-path = 'test'
-include = '**/test_*.coffee'
-timeout = 5000
+@path = 'test'
+@include = '**/test_*.coffee'
+@timeout = 5000
-on('hello', function(value, resume) {
- resume(value + '!');
-});
+@on 'hello', (value, resume) ->
+ resume "#{value}!"
View
2  bin/cli.js
@@ -117,7 +117,7 @@ path.exists(lotteFile, function(exists) {
});
function load(options, file, block) {
- require('fs').readFile(file, 'utf8', function(e, code) {
+ require('../lib/utils').toJavaScript(options, file, function(e, code) {
if (e) {
return block(e);
}
View
38 lib/lotte.js
@@ -3,28 +3,17 @@ const STATUS_EXITED = 'exited';
const STATUS_KILLED = 'killed';
var childProcess = require('child_process'),
- fs = require('fs'),
- path = require('path'),
- console = require('./console'),
- events = require('./events');
+ fs = require('fs'),
+ path = require('path'),
+ console = require('./console'),
+ events = require('./events'),
+ utils = require('./utils');
var __basename = path.basename(__filename, '.js');
-function exec(command, resume) {
- childProcess.exec(command, function(e, stdout, stderr) {
- if (e) {
- return resume(e);
- }
- if (stderr) {
- return resume(new Error("Command '" + command + "' failed: " + stderr.trim()));
- }
- resume(null, stdout);
- });
-};
-
function mktemp(options, resume) {
options.garbage || (options.garbage = []);
- exec((options.mktemp) + ' -t ' + __basename + '.XXXXXX', function(e, stdout) {
+ utils.exec((options.mktemp) + ' -t ' + __basename + '.XXXXXX', function(e, stdout) {
if (e) {
return resume(e);
}
@@ -191,7 +180,7 @@ function processOne(file, template, options, resume) {
if (e) {
return resume(e);
}
- toJavaScript(options, file, function(e, code) {
+ utils.toJavaScript(options, file, function(e, code) {
if (e) {
return resume(e);
}
@@ -262,17 +251,4 @@ function cleanup(options, resume) {
});
};
-function toJavaScript(options, file, resume) {
- if (/\.coffee$/i.exec(file)) {
- exec((options.coffee) + ' -p "' + file + '"', function(e, stdout) {
- if (e) {
- return resume(e);
- }
- resume(null, stdout.trim());
- });
- } else {
- fs.readFile(file, 'utf8', resume);
- }
-};
-
exports.process = process_;
View
44 lib/utils.js
@@ -0,0 +1,44 @@
+var childProcess = require('child_process'),
+ fs = require('fs'),
+ vm = require('vm');
+
+function exec(command, resume) {
+ childProcess.exec(command, function(e, stdout, stderr) {
+ if (e) {
+ return resume(e);
+ }
+ if (stderr) {
+ return resume(new Error("Command '" + command + "' failed: " + stderr.trim()));
+ }
+ resume(null, stdout);
+ });
+};
+
+function toJavaScript(options, file, resume) {
+ if (file.treatAs === 'coffee' || /\.coffee$/i.exec(file)) {
+ exec((options.coffee) + ' -b -p "' + (file.file || file) + '"', function(e, stdout) {
+ if (e) {
+ return resume(e);
+ }
+ resume(null, stdout.trim());
+ });
+ } else {
+ fs.readFile(file, 'utf8', function(e, code) {
+ if (e) {
+ return resume(e);
+ }
+ try {
+ vm.createScript(code, file);
+ resume(e, code);
+ } catch (e) {
+ toJavaScript(options, {
+ treatAs: 'coffee',
+ file: file
+ }, resume);
+ }
+ });
+ }
+};
+
+exports.exec = exec;
+exports.toJavaScript = toJavaScript;

0 comments on commit 317f88f

Please sign in to comment.
Something went wrong with that request. Please try again.