Skip to content
Browse files

Added coffeescript support

  • Loading branch information...
1 parent b163a5c commit cb937acc0140fb6487fde39d5b0eacd831ededf3 @Qard committed Jan 25, 2012
Showing with 31 additions and 11 deletions.
  1. +30 −10 lib/index.js
  2. +1 −1 package.json
View
40 lib/index.js
@@ -5,6 +5,7 @@ var helper = require('./helper')
, path = require('path')
, jsp = uglify.parser
, pro = uglify.uglify
+ , coffee = null
/**
* Construct a Crsh block
@@ -23,8 +24,10 @@ function Crsh (path, list) {
}
this.path = path
- // Prepare watcher
- this.watcher = new Watch(path)
+ // Don't use watcher in production
+ if (process.env.NODE_ENV !== 'production') {
+ this.watcher = new Watch(path)
+ }
// Populate list
this.list = []
@@ -48,6 +51,12 @@ Crsh.path = process.cwd() + '/tmp'
*/
Crsh.prototype.add = function (f) {
f = helper.realPath(f, this.path)
+
+ // If we add any coffee files, require coffee-script
+ if (path.extname(f) === '.coffee') {
+ coffee = require('coffee-script')
+ }
+
this.list.push(f)
this.watcher.add(f)
return this
@@ -73,22 +82,26 @@ Crsh.prototype.remove = function (f) {
*/
Crsh.prototype.start = function () {
var self = this
-
- // Add list of files to watcher
- for (var i = 0; i > this.list.length; i++) {
- this.watcher.add(this.list[i])
- }
+ // Run the first 'change' event right away
function onChange () {
self.compile(function (err) {
if (err) return console.error(err)
self.lastChange = Date.now()
})
}
-
- // Run the compiler when a change occurs
- this.watcher.on('change', onChange)
onChange()
+
+ // The watcher is disabled in production
+ if (this.watcher) {
+ // Add list of files to watcher
+ for (var i = 0; i > this.list.length; i++) {
+ this.watcher.add(this.list[i])
+ }
+
+ // Run the compiler when a change occurs
+ this.watcher.on('change', onChange)
+ }
}
@@ -105,6 +118,13 @@ Crsh.prototype.compile = function (cb) {
// Merge all the files
var merged = list.map(function (file) {
+
+ // Compile coffeescript files
+ if (path.extname(file) === '.coffee') {
+ return coffee.compile(files[file].toString())
+ }
+
+ // Return regular javascript as-is
return files[file]
}).join('')
View
2 package.json
@@ -2,7 +2,7 @@
"author": "Stephen Belanger <admin@stephenbelanger.com> (http://stephenbelanger.com)",
"name": "crsh",
"description": "crsh your javascript into tiny blocks.",
- "version": "0.0.2",
+ "version": "0.0.3",
"repository": {
"url": "git://github.com/Qard/crsh.git"
},

0 comments on commit cb937ac

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