diff --git a/examples/blocks.coffee b/examples/blocks.coffee index 6edf4e6b..45b188ca 100644 --- a/examples/blocks.coffee +++ b/examples/blocks.coffee @@ -8,7 +8,7 @@ get '/hello', -> # Append. append = (location, data) -> path = new Pathname location - throw new Error("Location does not exist") unless path.exists() + throw new Error("Location does not exist") unless fs.exists() File.open path, 'a', (file) -> file.console.log YAML.dump data @@ -31,7 +31,7 @@ File.open = (path, mode, block) -> # Write. write = (location, data) -> path = new Pathname location - raise "Location does not exist" unless path.exists() + raise "Location does not exist" unless fs.exists() File.open path, 'w', (file) -> return false if Digest.MD5.hexdigest(file.read()) is data.hash() diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js index 1523418f..2ad09284 100644 --- a/lib/coffee-script/cake.js +++ b/lib/coffee-script/cake.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.3.3 (function() { - var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; + var CoffeeScript, cakefileDirectory, existsSync, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; fs = require('fs'); @@ -12,6 +12,8 @@ CoffeeScript = require('./coffee-script'); + existsSync = fs.existsSync || path.existsSync; + tasks = {}; options = {}; @@ -98,7 +100,7 @@ cakefileDirectory = function(dir) { var parent; - if (path.existsSync(path.join(dir, 'Cakefile'))) { + if (existsSync(path.join(dir, 'Cakefile'))) { return dir; } parent = path.normalize(path.join(dir, '..')); diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index e02da9fe..49346174 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.3.3 (function() { - var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, hidden, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref; + var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref; fs = require('fs'); @@ -16,6 +16,8 @@ EventEmitter = require('events').EventEmitter; + exists = fs.exists || path.exists; + helpers.extend(CoffeeScript, new EventEmitter); printLine = function(line) { @@ -372,8 +374,8 @@ sourceCode.splice(index, 1); if (removeJs && !opts.join) { jsPath = outputPath(source, base); - return path.exists(jsPath, function(exists) { - if (exists) { + return exists(jsPath, function(itExists) { + if (itExists) { return fs.unlink(jsPath, function(err) { if (err && err.code !== 'ENOENT') { throw err; @@ -410,8 +412,8 @@ } }); }; - return path.exists(jsDir, function(exists) { - if (exists) { + return exists(jsDir, function(itExists) { + if (itExists) { return compile(); } else { return exec("mkdir -p " + jsDir, compile); diff --git a/src/cake.coffee b/src/cake.coffee index 93b2c731..bd26322f 100644 --- a/src/cake.coffee +++ b/src/cake.coffee @@ -13,6 +13,8 @@ helpers = require './helpers' optparse = require './optparse' CoffeeScript = require './coffee-script' +existsSync = fs.existsSync or path.existsSync + # Keep track of the list of defined tasks, the accepted options, and so on. tasks = {} options = {} @@ -79,7 +81,7 @@ missingTask = (task) -> fatalError "No such task: #{task}" # When `cake` is invoked, search in the current and all parent directories # to find the relevant Cakefile. cakefileDirectory = (dir) -> - return dir if path.existsSync path.join dir, 'Cakefile' + return dir if existsSync path.join dir, 'Cakefile' parent = path.normalize path.join dir, '..' return cakefileDirectory parent unless parent is dir throw new Error "Cakefile not found in #{process.cwd()}" diff --git a/src/command.coffee b/src/command.coffee index c8c9071c..f94fafb2 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -13,6 +13,8 @@ CoffeeScript = require './coffee-script' {spawn, exec} = require 'child_process' {EventEmitter} = require 'events' +exists = fs.exists or path.exists + # Allow CoffeeScript to emit Node.js events. helpers.extend CoffeeScript, new EventEmitter @@ -247,8 +249,8 @@ removeSource = (source, base, removeJs) -> sourceCode.splice index, 1 if removeJs and not opts.join jsPath = outputPath source, base - path.exists jsPath, (exists) -> - if exists + exists jsPath, (itExists) -> + if itExists fs.unlink jsPath, (err) -> throw err if err and err.code isnt 'ENOENT' timeLog "removed #{source}" @@ -274,8 +276,8 @@ writeJs = (source, js, base) -> printLine err.message else if opts.compile and opts.watch timeLog "compiled #{source}" - path.exists jsDir, (exists) -> - if exists then compile() else exec "mkdir -p #{jsDir}", compile + exists jsDir, (itExists) -> + if itExists then compile() else exec "mkdir -p #{jsDir}", compile # Convenience for cleaner setTimeouts. wait = (milliseconds, func) -> setTimeout func, milliseconds