Debian Codegraph @

util/build/transforms/writeCss.js

raw symbols SCIP
1 define([
2 "../buildControl",
3 "../fileUtils",
4 "../fs"
5 ], function(bc, fileUtils, fs){
6 return function(resource, callback){
7 var
8 waitCount = 0,
9
10 errors = [],
11
12 onWriteComplete = function(err){
13 if(err){
14 errors.push(err);
15 }
16 if(--waitCount==0){
17 callback(resource, errors.length && errors);
18 }
19 },
20
21 doWrite = function(filename, text, encoding){
22 fileUtils.ensureDirectoryByFilename(filename);
23 waitCount++;
24 fs.writeFile(filename, bc.newlineFilter(text, resource, "writeCss"), encoding || "utf8", onWriteComplete);
25 // this must go *after* the async call
26 },
27
28 wroteExterns = 0;
29
30 try{
31 doWrite(resource.dest, resource.text);
32 if(resource.compactDest!=resource.dest){
33 doWrite(resource.compactDest, resource.compactText);
34 }
35
36 // only need to tranverse bc.destDirToExternSet once...
37 if(wroteExterns){
38 return callback;
39 }
40 wroteExterns = 1;
41 // bc.destDirToExternSet is a map from dest directory name to resourceSet;
42 // resourceSet is a map from src filename (complete with path) to dest filename (name only)
43 // bc.destDirToExternSet[dir][src]= dest implies copy filename src to dir + "/" + dest
44 var
45 destDirToExternSet = bc.destDirToExternSet,
46 dir, resourceSet, src;
47 for(dir in destDirToExternSet){
48 resourceSet = destDirToExternSet[dir];
49 for(src in resourceSet){
50 doWrite(dir + "/" + resourceSet[src], bc.resources[src].text, resource.encoding);
51 }
52 }
53 }catch(e){
54 if(waitCount){
55 // can't return the error since there are async processes already going
56 errors.push(e);
57 return 0;
58 }else{
59 return e;
60 }
61 }
62 return callback;
63 };
64 });