1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Migrate from path.exists to fs.exists

Compatibility is kept for path.exists. Versions of node that have
made the change will use fs.exists, while older versions will fall
back to path.exists. The same goes for path.existsSync.
This commit is contained in:
Michael Smith 2012-07-02 00:20:13 -07:00
parent 6417cf4d1b
commit ace4837365
No known key found for this signature in database
GPG key ID: 74223E91A6ACAFA2
5 changed files with 22 additions and 14 deletions

View file

@ -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()

View file

@ -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, '..'));

View file

@ -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);

View file

@ -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()}"

View file

@ -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