Comparing version 0.0.0 to 0.0.1
53
index.js
@@ -109,2 +109,3 @@ 'use strict'; | ||
ignoreDupes: opts.ignoreDupes || true, | ||
joiner: '\n\n' | ||
}; | ||
@@ -119,3 +120,3 @@ | ||
extend(Galvatron.prototype, { | ||
all: function (path, joiner) { | ||
all: function (path) { | ||
var code = []; | ||
@@ -125,6 +126,6 @@ var that = this; | ||
this.trace(path).forEach(function (file) { | ||
code.push(that.postTransform(file, code)); | ||
code.push(that.postTransform(file, that.filePreTransformCache[file])); | ||
}); | ||
return code.join(joiner || '\n\n'); | ||
return code.join(this.options.joiner); | ||
}, | ||
@@ -142,3 +143,6 @@ | ||
preTransform: function (file, code) { | ||
this.emit('pre-tansform', file, code); | ||
if (this.filePreTransformCache[file]) { | ||
return this.filePreTransformCache[file]; | ||
} | ||
this.preTransformers.forEach(function (transformer) { | ||
@@ -148,2 +152,3 @@ code = transformer(file, code); | ||
this.emit('pre-transform', file, code); | ||
return this.filePreTransformCache[file] = code; | ||
@@ -158,3 +163,6 @@ }, | ||
postTransform: function (file, code) { | ||
this.emit('post-tansform', file, code); | ||
if (this.postTransformers[file]) { | ||
return this.postTransformers[file]; | ||
} | ||
this.postTransformers.forEach(function (transformer) { | ||
@@ -164,2 +172,3 @@ code = transformer(file, code); | ||
this.emit('post-transform', file, code); | ||
return this.filePostTransformCache[file] = code; | ||
@@ -171,4 +180,4 @@ }, | ||
this.filePreTransformCache = {}; | ||
this.filePostTransformMap = {}; | ||
this.fileTraceCache = {}; | ||
this.filePostTransformCache = {}; | ||
this.fileTraceCache = []; | ||
this.preTransformers = []; | ||
@@ -188,13 +197,9 @@ this.postTransformers = []; | ||
trace: function (paths, depth) { | ||
trace: function (paths) { | ||
var that = this; | ||
var traced = []; | ||
var tracedNames = []; | ||
eachFileInPaths(paths, function (file) { | ||
that.traceRecursive(file, [], depth).forEach(function (dep) { | ||
if (tracedNames.indexOf(dep.path) === -1) { | ||
traced.push(dep); | ||
tracedNames.push(dep.path); | ||
} | ||
that.traceRecursive(file).forEach(function (dep) { | ||
traced.push(dep); | ||
}); | ||
@@ -206,22 +211,20 @@ }); | ||
traceRecursive: function (file, files, depth, currentDepth) { | ||
traceRecursive: function (file, files) { | ||
var that = this; | ||
var code = getFile(file); | ||
currentDepth = currentDepth || 1; | ||
files = files || []; | ||
if (file in this.fileTraceCache) { | ||
return this.fileTraceCache[file]; | ||
} | ||
code = this.preTransform(file, code); | ||
this.emit('trace', file, currentDepth); | ||
this.emit('trace', file, code); | ||
getRequires(code).forEach(function (match) { | ||
if (typeof depth === 'undefined' || depth >= currentDepth) { | ||
files.concat(that.traceRecursive(normalizePath(match[1], file), files, depth, depth + 1)); | ||
var dependency = normalizePath(match[1], file); | ||
if (files.indexOf(dependency) === -1 && (!that.options.ignoreDupes || that.fileTraceCache.indexOf(dependency) === -1)) { | ||
that.traceRecursive(dependency, files); | ||
files.push(dependency); | ||
that.fileTraceCache.push(dependency); | ||
} | ||
}); | ||
return this.fileTraceCache[file] = files; | ||
return files; | ||
}, | ||
@@ -228,0 +231,0 @@ |
{ | ||
"name": "galvatron", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Library that applies pre and post transforms to CommonJS files, traces their dependencies and concatenates them.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
9657
211