compileJoin should happen once after all files are read
This commit is contained in:
parent
25e7eeac8f
commit
dc272a680b
|
@ -55,12 +55,27 @@
|
|||
return compileScripts();
|
||||
};
|
||||
compileScripts = function() {
|
||||
var base, compile, source, _i, _len, _results;
|
||||
_results = [];
|
||||
var base, compile, source, unprocessed, _i, _j, _len, _len2, _results;
|
||||
unprocessed = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _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);
|
||||
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) {
|
||||
if (topLevel && !exists) {
|
||||
throw new Error("File not found: " + source);
|
||||
|
@ -71,20 +86,23 @@
|
|||
}
|
||||
if (stats.isDirectory()) {
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, _j, _len2, _results2;
|
||||
_results2 = [];
|
||||
for (_j = 0, _len2 = files.length; _j < _len2; _j++) {
|
||||
file = files[_j];
|
||||
_results2.push(compile(path.join(source, file), sourceIndex));
|
||||
var file, _k, _len3;
|
||||
unprocessed[sourceIndex] += files.length;
|
||||
for (_k = 0, _len3 = files.length; _k < _len3; _k++) {
|
||||
file = files[_k];
|
||||
compile(path.join(source, file), sourceIndex);
|
||||
}
|
||||
return _results2;
|
||||
return unprocessed[sourceIndex] -= 1;
|
||||
});
|
||||
} else if (topLevel || path.extname(source) === '.coffee') {
|
||||
fs.readFile(source, function(err, code) {
|
||||
unprocessed[sourceIndex] -= 1;
|
||||
if (opts.join) {
|
||||
contents[sourceIndex] = helpers.compact([contents[sourceIndex], code.toString()]).join('\n');
|
||||
if (helpers.compact(contents).length > 0) {
|
||||
return compileJoin();
|
||||
if (remaining() === 0) {
|
||||
if (helpers.compact(contents).length > 0) {
|
||||
return compileJoin();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return compileScript(source, code.toString(), base);
|
||||
|
@ -93,6 +111,8 @@
|
|||
if (opts.watch && !opts.join) {
|
||||
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
|
||||
# '.coffee' extension source files in it and all subdirectories.
|
||||
compileScripts = ->
|
||||
unprocessed = []
|
||||
for source in sources
|
||||
unprocessed[sources.indexOf(source)]=1
|
||||
for source in sources
|
||||
base = path.join(source)
|
||||
compile = (source, sourceIndex, topLevel) ->
|
||||
remaining_files = ->
|
||||
total = 0
|
||||
total += x for x in unprocessed
|
||||
total
|
||||
path.exists source, (exists) ->
|
||||
throw new Error "File not found: #{source}" if topLevel and not exists
|
||||
fs.stat source, (err, stats) ->
|
||||
throw err if err
|
||||
if stats.isDirectory()
|
||||
fs.readdir source, (err, files) ->
|
||||
unprocessed[sourceIndex] += files.length
|
||||
for file in files
|
||||
compile path.join(source, file), sourceIndex
|
||||
unprocessed[sourceIndex] -= 1
|
||||
else if topLevel or path.extname(source) is '.coffee'
|
||||
fs.readFile source, (err, code) ->
|
||||
unprocessed[sourceIndex] -= 1
|
||||
if opts.join
|
||||
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
|
||||
compileScript(source, code.toString(), base)
|
||||
watch source, base if opts.watch and not opts.join
|
||||
else
|
||||
unprocessed[sourceIndex] -= 1
|
||||
compile source, sources.indexOf(source), true
|
||||
|
||||
# Compile a single source script, containing the given code, according to the
|
||||
|
|
Loading…
Reference in New Issue