mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
fixes #1537: ignore hidden files/directories in watched directories
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.2.1-pre
|
||||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, 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, 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');
|
||||
|
||||
@@ -26,7 +26,11 @@
|
||||
return process.stderr.write(line + '\n');
|
||||
};
|
||||
|
||||
BANNER = 'Usage: coffee [options] path/to/script.coffee -- [args]\n\nIf called without options, `coffee` will run your script.';
|
||||
hidden = function(file) {
|
||||
return /^\./.test(file);
|
||||
};
|
||||
|
||||
BANNER = 'Usage: coffee [options] path/to/script.coffee\n\nIf called without options, `coffee` will run your script.';
|
||||
|
||||
SWITCHES = [['-b', '--bare', 'compile without a top-level function wrapper'], ['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-e', '--eval', 'pass a string from the command line as input'], ['-h', '--help', 'display this help message'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-j', '--join [FILE]', 'concatenate the source CoffeeScript before compiling'], ['-l', '--lint', 'pipe the compiled JavaScript through JavaScript Lint'], ['-n', '--nodes', 'print out the parse tree that the parser produces'], ['--nodejs [ARGS]', 'pass options directly to the "node" binary'], ['-o', '--output [DIR]', 'set the output directory for compiled JavaScript'], ['-p', '--print', 'print out the compiled JavaScript'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-t', '--tokens', 'print out the tokens that the lexer/rewriter produce'], ['-v', '--version', 'display the version number'], ['-w', '--watch', 'watch scripts for changes and rerun commands']];
|
||||
|
||||
@@ -85,21 +89,28 @@
|
||||
if (stats.isDirectory()) {
|
||||
if (opts.watch) watchDir(source, base);
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, index, _i, _len, _ref2, _results;
|
||||
var file, index, _i, _len, _ref2, _ref3, _results;
|
||||
if (err && err.code !== 'ENOENT') throw err;
|
||||
if ((err != null ? err.code : void 0) === 'ENOENT') return;
|
||||
files = files.map(function(file) {
|
||||
return path.join(source, file);
|
||||
});
|
||||
index = sources.indexOf(source);
|
||||
[].splice.apply(sources, [index, index - index + 1].concat(files)), files;
|
||||
[].splice.apply(sourceCode, [index, index - index + 1].concat(_ref2 = files.map(function() {
|
||||
[].splice.apply(sources, [index, index - index + 1].concat(_ref2 = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
_results.push(path.join(source, file));
|
||||
}
|
||||
return _results;
|
||||
})())), _ref2;
|
||||
[].splice.apply(sourceCode, [index, index - index + 1].concat(_ref3 = files.map(function() {
|
||||
return null;
|
||||
}))), _ref2;
|
||||
}))), _ref3;
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
_results.push(compilePath(file, false, base));
|
||||
if (!hidden(file)) {
|
||||
_results.push(compilePath(path.join(source, file), false, base));
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
});
|
||||
@@ -255,13 +266,11 @@
|
||||
watcher.close();
|
||||
return unwatchDir(source, base);
|
||||
}
|
||||
files = files.map(function(file) {
|
||||
return path.join(source, file);
|
||||
});
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
if (!(!notSources[file])) continue;
|
||||
if (!(!hidden(file) && !notSources[file])) continue;
|
||||
file = path.join(source, file);
|
||||
if (sources.some(function(s) {
|
||||
return s.indexOf(file) >= 0;
|
||||
})) {
|
||||
|
||||
@@ -19,6 +19,8 @@ helpers.extend CoffeeScript, new EventEmitter
|
||||
printLine = (line) -> process.stdout.write line + '\n'
|
||||
printWarn = (line) -> process.stderr.write line + '\n'
|
||||
|
||||
hidden = (file) -> /^\.|~$/.test file
|
||||
|
||||
# The help banner that is printed when `coffee` is called without arguments.
|
||||
BANNER = '''
|
||||
Usage: coffee [options] path/to/script.coffee -- [args]
|
||||
@@ -95,11 +97,11 @@ compilePath = (source, topLevel, base) ->
|
||||
fs.readdir source, (err, files) ->
|
||||
throw err if err and err.code isnt 'ENOENT'
|
||||
return if err?.code is 'ENOENT'
|
||||
files = files.map (file) -> path.join source, file
|
||||
index = sources.indexOf source
|
||||
sources[index..index] = files
|
||||
sources[index..index] = (path.join source, file for file in files)
|
||||
sourceCode[index..index] = files.map -> null
|
||||
compilePath file, no, base for file in files
|
||||
for file in files when not hidden file
|
||||
compilePath (path.join source, file), no, base
|
||||
else if topLevel or path.extname(source) is '.coffee'
|
||||
watch source, base if opts.watch
|
||||
fs.readFile source, (err, code) ->
|
||||
@@ -220,8 +222,8 @@ watchDir = (source, base) ->
|
||||
throw err unless err.code is 'ENOENT'
|
||||
watcher.close()
|
||||
return unwatchDir source, base
|
||||
files = files.map (file) -> path.join source, file
|
||||
for file in files when not notSources[file]
|
||||
for file in files when not hidden(file) and not notSources[file]
|
||||
file = path.join source, file
|
||||
continue if sources.some (s) -> s.indexOf(file) >= 0
|
||||
sources.push file
|
||||
sourceCode.push null
|
||||
|
||||
Reference in New Issue
Block a user