Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

addition of copy.EXCLUDES experiment

  • Loading branch information...
commit 549a5a107b73154308d2685e95dc0121c8e13626 1 parent dc214a2
Joe Walker joewalker authored
Showing with 40 additions and 22 deletions.
  1. +40 −22 lib/dryice/index.js
62 lib/dryice/index.js
View
@@ -56,6 +56,10 @@ function copy(obj) {
// Run filters where onRead=false
value = runFilters(value, obj.filter, false);
+ if (value === copy.EXCLUDE) {
+ console.log('Entire output dropped via copy.EXCLUDE.');
+ value = '';
+ }
// Output
// TODO: for now we're ignoring the concept of directory destinations.
@@ -101,7 +105,10 @@ function addSource(obj, source) {
source.value = runFilters(source.value, obj.filter, true, source.name);
source.filtered = true;
}
- obj.sources.push(source);
+
+ if (source.value !== copy.EXCLUDE) {
+ obj.sources.push(source);
+ }
}
else {
throw new Error('Can\'t handle type of source: ' + typeof source);
@@ -110,18 +117,18 @@ function addSource(obj, source) {
function addSourceFile(obj, filename) {
var read = fs.readFileSync(filename);
- obj.sources.push({
- name: filename,
- value: runFilters(read, obj.filter, true, filename)
- });
+ var value = runFilters(read, obj.filter, true, filename);
+ if (value !== copy.EXCLUDE) {
+ obj.sources.push({ name: filename, value: value });
+ }
}
function addSourceBase(obj, baseObj) {
var read = fs.readFileSync(baseObj.base + baseObj.path);
- obj.sources.push({
- name: baseObj,
- value: runFilters(read, obj.filter, true, baseObj)
- });
+ var value = runFilters(read, obj.filter, true, baseObj);
+ if (value !== copy.EXCLUDE) {
+ obj.sources.push({ name: baseObj, value: value });
+ }
}
function runFilters(value, filter, reading, name) {
@@ -130,9 +137,12 @@ function runFilters(value, filter, reading, name) {
}
if (Array.isArray(filter)) {
- filter.forEach(function(f) {
- value = runFilters(value, f, reading, name);
- }, this);
+ for (var i = 0; i < filter.length; i++) {
+ value = runFilters(value, filter[i], reading, name);
+ if (value === copy.EXCLUDE) {
+ return copy.EXCLUDE;
+ }
+ }
return value;
}
@@ -145,6 +155,11 @@ function runFilters(value, filter, reading, name) {
}
/**
+ * A constant which filters can return to exclude the source from the output
+ */
+copy.EXCLUDE = { __copyExclude__: '__copyExclude__' };
+
+/**
* A holder is an in-memory store of a result of a copy operation.
* <pre>
* var holder = copy.createDataObject();
@@ -271,18 +286,18 @@ function CommonJsProject(roots) {
CommonJsProject.prototype.clone = function() {
var clone = new CommonJsProject(this.roots);
-
+
Object.keys(this.currentFiles).forEach(function(module) {
clone.currentFiles[module] = this.currentFiles[module];
}, this);
-
+
Object.keys(this.ignoredFiles).forEach(function(module) {
clone.ignoredFiles[module] = this.ignoredFiles[module];
}, this);
-
+
return clone;
};
-
+
CommonJsProject.prototype.addRoot = function(root) {
this.roots.push(root);
};
@@ -365,7 +380,9 @@ function CommonJsProject(roots) {
}, this);
if (!baseObj) {
- console.error('Failed to find module: ' + module);
+ if (module.indexOf('text!') !== 0) {
+ console.error('Failed to find module: ' + module);
+ }
}
else {
var deps = baseObj.deps = {};
@@ -380,7 +397,7 @@ function CommonJsProject(roots) {
};
CommonJsProject.prototype.getCurrentSources = function() {
- return Object.keys(this.currentFiles).map(function(module) {
+ return Object.keys(this.currentFiles).map(function(module) {
return this.currentFiles[module];
}, this);
};
@@ -555,23 +572,24 @@ copy.filter.base64.onRead = true;
/**
* Munge define lines to add module names
*/
-copy.filter.moduleDefines = function(input, source) {
+copy.filter.moduleDefines = function(input, source) {
if (typeof input !== 'string') {
input = input.toString();
}
if (!source) {
- throw new Error('Missing filename for moduleDefines');
+ console.log('Missing filename for moduleDefines');
+ return input;
}
var deps = source.deps ? Object.keys(source.deps) : [];
deps = deps.length ? (", '" + deps.join("', '") + "'") : "";
-
+
if (source.base) {
source = source.path;
}
source = source.replace(/\.js$/, '');
-
+
return input.replace(/\bdefine\(\s*function\(require,\s*exports,\s*module\)\s*\{/,
"define('" + source + "', ['require', 'exports', 'module' " + deps + "], function(require, exports, module) {");
};
Please sign in to comment.
Something went wrong with that request. Please try again.