mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
compileJoin should happen once after all files are read
This commit is contained in:
parent
25e7eeac8f
commit
dc272a680b
2 changed files with 44 additions and 11 deletions
|
@ -55,12 +55,27 @@
|
||||||
return compileScripts();
|
return compileScripts();
|
||||||
};
|
};
|
||||||
compileScripts = function() {
|
compileScripts = function() {
|
||||||
var base, compile, source, _i, _len, _results;
|
var base, compile, source, unprocessed, _i, _j, _len, _len2, _results;
|
||||||
_results = [];
|
unprocessed = [];
|
||||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||||
source = sources[_i];
|
source = sources[_i];
|
||||||
|
unprocessed[sources.indexOf(source)] = 1;
|
||||||
|
}
|
||||||
|
_results = [];
|
||||||
|
for (_j = 0, _len2 = sources.length; _j < _len2; _j++) {
|
||||||
|
source = sources[_j];
|
||||||
base = path.join(source);
|
base = path.join(source);
|
||||||
compile = function(source, sourceIndex, topLevel) {
|
compile = function(source, sourceIndex, topLevel) {
|
||||||
|
var remaining;
|
||||||
|
remaining = function() {
|
||||||
|
var total, x, _k, _len3;
|
||||||
|
total = 0;
|
||||||
|
for (_k = 0, _len3 = unprocessed.length; _k < _len3; _k++) {
|
||||||
|
x = unprocessed[_k];
|
||||||
|
total += x;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
};
|
||||||
return path.exists(source, function(exists) {
|
return path.exists(source, function(exists) {
|
||||||
if (topLevel && !exists) {
|
if (topLevel && !exists) {
|
||||||
throw new Error("File not found: " + source);
|
throw new Error("File not found: " + source);
|
||||||
|
@ -71,20 +86,23 @@
|
||||||
}
|
}
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
return fs.readdir(source, function(err, files) {
|
return fs.readdir(source, function(err, files) {
|
||||||
var file, _j, _len2, _results2;
|
var file, _k, _len3;
|
||||||
_results2 = [];
|
unprocessed[sourceIndex] += files.length;
|
||||||
for (_j = 0, _len2 = files.length; _j < _len2; _j++) {
|
for (_k = 0, _len3 = files.length; _k < _len3; _k++) {
|
||||||
file = files[_j];
|
file = files[_k];
|
||||||
_results2.push(compile(path.join(source, file), sourceIndex));
|
compile(path.join(source, file), sourceIndex);
|
||||||
}
|
}
|
||||||
return _results2;
|
return unprocessed[sourceIndex] -= 1;
|
||||||
});
|
});
|
||||||
} else if (topLevel || path.extname(source) === '.coffee') {
|
} else if (topLevel || path.extname(source) === '.coffee') {
|
||||||
fs.readFile(source, function(err, code) {
|
fs.readFile(source, function(err, code) {
|
||||||
|
unprocessed[sourceIndex] -= 1;
|
||||||
if (opts.join) {
|
if (opts.join) {
|
||||||
contents[sourceIndex] = helpers.compact([contents[sourceIndex], code.toString()]).join('\n');
|
contents[sourceIndex] = helpers.compact([contents[sourceIndex], code.toString()]).join('\n');
|
||||||
if (helpers.compact(contents).length > 0) {
|
if (remaining() === 0) {
|
||||||
return compileJoin();
|
if (helpers.compact(contents).length > 0) {
|
||||||
|
return compileJoin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return compileScript(source, code.toString(), base);
|
return compileScript(source, code.toString(), base);
|
||||||
|
@ -93,6 +111,8 @@
|
||||||
if (opts.watch && !opts.join) {
|
if (opts.watch && !opts.join) {
|
||||||
return watch(source, base);
|
return watch(source, base);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return unprocessed[sourceIndex] -= 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -74,25 +74,38 @@ exports.run = ->
|
||||||
# compile them. If a directory is passed, recursively compile all
|
# compile them. If a directory is passed, recursively compile all
|
||||||
# '.coffee' extension source files in it and all subdirectories.
|
# '.coffee' extension source files in it and all subdirectories.
|
||||||
compileScripts = ->
|
compileScripts = ->
|
||||||
|
unprocessed = []
|
||||||
|
for source in sources
|
||||||
|
unprocessed[sources.indexOf(source)]=1
|
||||||
for source in sources
|
for source in sources
|
||||||
base = path.join(source)
|
base = path.join(source)
|
||||||
compile = (source, sourceIndex, topLevel) ->
|
compile = (source, sourceIndex, topLevel) ->
|
||||||
|
remaining_files = ->
|
||||||
|
total = 0
|
||||||
|
total += x for x in unprocessed
|
||||||
|
total
|
||||||
path.exists source, (exists) ->
|
path.exists source, (exists) ->
|
||||||
throw new Error "File not found: #{source}" if topLevel and not exists
|
throw new Error "File not found: #{source}" if topLevel and not exists
|
||||||
fs.stat source, (err, stats) ->
|
fs.stat source, (err, stats) ->
|
||||||
throw err if err
|
throw err if err
|
||||||
if stats.isDirectory()
|
if stats.isDirectory()
|
||||||
fs.readdir source, (err, files) ->
|
fs.readdir source, (err, files) ->
|
||||||
|
unprocessed[sourceIndex] += files.length
|
||||||
for file in files
|
for file in files
|
||||||
compile path.join(source, file), sourceIndex
|
compile path.join(source, file), sourceIndex
|
||||||
|
unprocessed[sourceIndex] -= 1
|
||||||
else if topLevel or path.extname(source) is '.coffee'
|
else if topLevel or path.extname(source) is '.coffee'
|
||||||
fs.readFile source, (err, code) ->
|
fs.readFile source, (err, code) ->
|
||||||
|
unprocessed[sourceIndex] -= 1
|
||||||
if opts.join
|
if opts.join
|
||||||
contents[sourceIndex] = helpers.compact([contents[sourceIndex], code.toString()]).join('\n')
|
contents[sourceIndex] = helpers.compact([contents[sourceIndex], code.toString()]).join('\n')
|
||||||
compileJoin() if helpers.compact(contents).length > 0
|
if remaining_files() == 0
|
||||||
|
compileJoin() if helpers.compact(contents).length > 0
|
||||||
else
|
else
|
||||||
compileScript(source, code.toString(), base)
|
compileScript(source, code.toString(), base)
|
||||||
watch source, base if opts.watch and not opts.join
|
watch source, base if opts.watch and not opts.join
|
||||||
|
else
|
||||||
|
unprocessed[sourceIndex] -= 1
|
||||||
compile source, sources.indexOf(source), true
|
compile source, sources.indexOf(source), true
|
||||||
|
|
||||||
# Compile a single source script, containing the given code, according to the
|
# Compile a single source script, containing the given code, according to the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue