Skip to content

Commit

Permalink
added support for jakefiles written in livescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew-Davey committed Apr 3, 2015
1 parent 67750b9 commit 554d0f4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
25 changes: 25 additions & 0 deletions docs/overview.md
Expand Up @@ -1026,6 +1026,7 @@ By default, it will watch the current directory for these files:
```javascript
[ './**/*.js'
, './**/*.coffee'
, './**/*.ls'
, './**/*.css'
, './**/*.less'
, './**/*.scss'
Expand Down Expand Up @@ -1123,6 +1124,30 @@ namespace 'foo', ->
console.log 'ello from next with param: ' + param
```
## LiveScript Jakefiles
Jake can also handle Jakefiles in LiveScript. Be sure to make it Jakefile.ls so Jake knows it's in LiveScript.
Here's an example:
```livescript
require! \util

desc 'This is the default task.'
task \default, (params) !->
console.log 'This is the default task.'
console.log (util.inspect arguments)
jake.Task[\new].invoke []

task \new !->
console.log 'ello from new'
jake.Task[\foo:next].invoke [\param]

namespace \foo ->
task \next (param) !->
console.log "ello from next with param: #param"
```
## Related projects
James Coglan's "Jake": <http://github.com/jcoglan/jake>
Expand Down
25 changes: 22 additions & 3 deletions lib/loader.js
Expand Up @@ -22,12 +22,13 @@ var path = require('path')
fs.existsSync : path.existsSync
, utils = require('utilities')
, CoffeeScript
, LiveScript
, Loader;


Loader = function () {

var JAKEFILE_PAT = /\.jake(\.js|\.coffee)?$/;
var JAKEFILE_PAT = /\.jake(\.js|\.coffee|\.ls)?$/;

var _requireCoffee = function () {
try {
Expand All @@ -43,20 +44,31 @@ Loader = function () {
return(cs);
};

var _requireLiveScript = function () {
try {
var ls = require('LiveScript');
}
catch (e) {
fail('LiveScript is missing! Try `npm install LiveScript`');
}
return(ls);
}

this.loadFile = function (file) {
var jakefile = file ?
file.replace(/\.js$/, '').replace(/\.coffee$/, '') : 'Jakefile'
file.replace(/\.js$/, '').replace(/\.coffee$/, '').replace(/\.ls/, '') : 'Jakefile'
, fileSpecified = !!file
// Dear God, why?
, isCoffee = false
, isLiveScript = false
// Warning, recursive
, exists
, oldCwd = process.cwd();

exists = function () {
var cwd = process.cwd();
if (existsSync(jakefile) || existsSync(jakefile + '.js') ||
existsSync(jakefile + '.coffee')) {
existsSync(jakefile + '.coffee') || existsSync(jakefile + '.ls')) {
return true;
}
if (!fileSpecified) {
Expand All @@ -75,9 +87,13 @@ Loader = function () {
}

isCoffee = existsSync(jakefile + '.coffee');
isLiveScript = existsSync(jakefile + '.ls');
if (isCoffee) {
CoffeeScript = _requireCoffee();
}
if (isLiveScript) {
LiveScript = _requireLiveScript();
}
require(utils.file.absolutize(jakefile));
return true;
};
Expand All @@ -93,6 +109,9 @@ Loader = function () {
if (/\.coffee$/.test(filePath)) {
CoffeeScript = _requireCoffee();
}
if (/\.ls$/.test(filePath)) {
LiveScript = _requireLiveScript();
}
require(path.join(dirname, filePath));
}
});
Expand Down
1 change: 1 addition & 0 deletions lib/watch_task.js
Expand Up @@ -82,6 +82,7 @@ var WatchTask = function () {
WatchTask.DEFAULT_INCLUDE_FILES = [
'./**/*.js'
, './**/*.coffee'
, './**/*.ls'
, './**/*.css'
, './**/*.less'
, './**/*.scss'
Expand Down

0 comments on commit 554d0f4

Please sign in to comment.