mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-04-23 16:14:52 +00:00
1 line
No EOL
1.7 KiB
JavaScript
1 line
No EOL
1.7 KiB
JavaScript
var combinerFactory=function(a,b,c){var d=function(b,c){this.findPatterns=b,this.replacePatterns=c,a.bindAll(this)};return d.prototype.combine=function(a,d){var e=this,f=[],g;if(!a.combined&&a.imports.length>0){for(g in a.imports)f.push(this.getStep(g));b.read([a.workingPath,a.name],function(e){c.pipeline(e,f,function(c){b.write([a.workingPath,a.name],c,d)})})}else d()},d.prototype.combineFile=function(a,b){var d=this,e=a.imports,f=function(){a.combined=!0,b()},g=function(){d.combine(a,f)};a.combined?b():e&&e.length>0?c.parallel(e,this.combineFile,g):g()},d.prototype.combineList=function(a,b){var d=this,e=function(b,c){d.findImports(b,a,c)},f=function(){d.onImports(a,b)};c.parallel(a,e,f)},d.prototype.findDependents=function(b,c){var d=function(a){return b.name===a.name},e;for(e in c)a.any(e.imports,d)&&b.dependents++},d.prototype.findImports=function(c,d,e){var f=this,g=[];b.read([c.workingPath,c.name],function(b){var h,i,j;for(h in f.findPatterns)g=g.concat(b.match(h));g=a.filter(g,function(a){return a});for(i in g)j=i.match(/['\"].*['\"]/)[0].replace(/['\"]/g,""),importedFile=a.find(d,function(a){return a.name==j}),c.imports.push(importedFile);e()})},d.prototype.getStep=function(a){var b=this;return function(c,d){b.replace(c,a,d)}},d.prototype.onImports=function(b,d){var e=a.bind(function(a,c){self.findDependents(a,b,c)}),f;for(f in b)e(f,b);c.parallel(b,this.combineFile,d)},d.prototype.replace=function(a,d,e){var f=this,g=d.name,h=d.workingPath;b.read([h,g],function(b){var d=[],h;for(h in f.replacePatterns)d.push(function(c,d){var e=h.toString().replace(/replace/,g),f=e.substring(1,e.length-2),i=new RegExp(f,"g"),j=i.exec(a),k;j&&j.length>1&&(k=j[1],b=k+b.replace(/\n/g,"\n"+k)),d(c.replace(i,b))}),c.pipeline(a,d,e)})},d};module.exports=combinerFactory |