component-builder
Advanced tools
Comparing version 0.5.1 to 0.5.2
0.5.2 / 2012-12-20 | ||
================== | ||
* add initial plugin support | ||
* fix: do not rewrite urls relative to host (closes #45) | ||
* fix: .addFile(type) should always add files to conf[type] | ||
0.5.1 / 2012-12-04 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -35,2 +35,5 @@ | ||
var self = this; | ||
this._hooks = {}; | ||
this._files = {}; | ||
this._js = ''; | ||
this.dir = dir; | ||
@@ -92,2 +95,3 @@ this.root = ! parent; | ||
Builder.prototype.inherit = function(dep){ | ||
dep._hooks = this._hooks; | ||
dep.paths = this.paths; | ||
@@ -210,2 +214,5 @@ dep.ignored = this.ignored; | ||
* | ||
* This method is used internally to prevent | ||
* buffering of duplicate components. | ||
* | ||
* @param {String} name | ||
@@ -264,2 +271,30 @@ * @param {String} type | ||
/** | ||
* Add file `type` `filename` contents of `val`. | ||
* | ||
* @param {String} type | ||
* @param {String} filename | ||
* @param {String} val | ||
* @return {Type} | ||
* @api public | ||
*/ | ||
Builder.prototype.addFile = function(type, filename, val){ | ||
debug('add %s "%s"', type, filename); | ||
var files = this.conf[type] || (this.conf[type] = []); | ||
files.push(filename); | ||
this._files[filename] = val; | ||
}; | ||
/** | ||
* Append the given `str` of javascript. | ||
* | ||
* @param {String} str | ||
* @api public | ||
*/ | ||
Builder.prototype.append = function(str){ | ||
this._js += str; | ||
}; | ||
/** | ||
* Load JSON and invoke `fn(err, obj)`. | ||
@@ -279,3 +314,9 @@ * | ||
try { | ||
fn(null, self.conf = JSON.parse(str)); | ||
self.conf = JSON.parse(str); | ||
// TODO: lame, remove me | ||
if (!self._emittedConfig) { | ||
self._emittedConfig = true; | ||
self.emit('config'); | ||
} | ||
fn(null, self.conf); | ||
} catch (err) { | ||
@@ -304,2 +345,3 @@ fn(err); | ||
Builder.prototype.build = function(fn){ | ||
var self = this; | ||
var batch = new Batch; | ||
@@ -316,3 +358,3 @@ debug('building %s', this.dir); | ||
fn(null, { | ||
js: res.shift() + '\n' + res.shift(), | ||
js: res.shift() + '\n' + res.shift() + '\n' + self._js, | ||
css: res.shift(), | ||
@@ -475,2 +517,5 @@ images: res.shift(), | ||
// "before <type>" hook | ||
self.hook('before ' + type, self); | ||
// build files | ||
@@ -481,6 +526,16 @@ if (conf[type]) { | ||
batch.push(function(done){ | ||
fs.readFile(path, 'utf8', function(err, str){ | ||
if (err) return fn(err); | ||
done(null, process(self, file, str)); | ||
}); | ||
var val = self._files[file]; | ||
// on disk | ||
if (null == val) { | ||
debug('read file %s', path); | ||
fs.readFile(path, 'utf8', function(err, str){ | ||
if (err) return fn(err); | ||
done(null, process(self, file, str)); | ||
}); | ||
return | ||
} | ||
// fabricated | ||
done(null, process(self, file, val)); | ||
}); | ||
@@ -520,6 +575,6 @@ }); | ||
if (self.ignoring(dep, type)) return debug('ignoring %s', dep); | ||
// ignore it so we dont have dups | ||
self.ignore(dep, type); | ||
// lookup dep | ||
@@ -635,2 +690,60 @@ batch.push(function(done){ | ||
/** | ||
* Use the given plugin `fn`. | ||
* | ||
* @param {Function} fn | ||
* @return {Builder} | ||
* @api public | ||
*/ | ||
Builder.prototype.use = function(fn){ | ||
fn(this); | ||
return this; | ||
}; | ||
/** | ||
* Define or perform hook `name`. | ||
* | ||
* @param {String} name | ||
* @param {Mixed} fn | ||
* @return {Mixed} | ||
* @api private | ||
*/ | ||
Builder.prototype.hook = function(name, fn){ | ||
if ('function' == typeof fn) return this.defineHook(name, fn); | ||
return this.performHook(name, fn); | ||
}; | ||
/** | ||
* Perform hook `name` with `arg` reduced. | ||
* | ||
* @param {String} name | ||
* @return {Mixed} | ||
* @api priate | ||
*/ | ||
Builder.prototype.performHook = function(name, arg){ | ||
debug('invoke hook "%s"', name); | ||
var fns = this._hooks[name] || []; | ||
for (var i = 0, len = fns.length; i < len; ++i) { | ||
arg = fns[i](arg); | ||
} | ||
return arg; | ||
}; | ||
/** | ||
* Define hook `name` with callback `fn()`. | ||
* | ||
* @param {String} name | ||
* @param {String} fn | ||
* @api private | ||
*/ | ||
Builder.prototype.defineHook = function(name, fn){ | ||
debug('hook into "%s"', name); | ||
this._hooks[name] = this._hooks[name] || []; | ||
this._hooks[name].push(fn); | ||
}; | ||
/** | ||
* No-op processor function. | ||
@@ -694,9 +807,9 @@ */ | ||
function isAbsolute(url) { | ||
return ~url.indexOf('://'); | ||
return ~url.indexOf('://') || url[0] == '/'; | ||
} | ||
function isData(url) { | ||
return 0 == url.indexOf('data:'); | ||
} | ||
function rewrite(url) { | ||
@@ -708,3 +821,3 @@ if (isData(url)) return url; | ||
} | ||
return rework(css) | ||
@@ -711,0 +824,0 @@ .use(rework.url(rewrite)) |
{ | ||
"name": "component-builder", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Component build tool", | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
"batch": "0.2.1", | ||
"rework": "0.7.0", | ||
"rework": "0.9.1", | ||
"mkdirp": "0.3.4", | ||
@@ -21,5 +21,6 @@ "debug": "*", | ||
"mocha": "*", | ||
"should": "*" | ||
"should": "*", | ||
"ejs": "~0.8.3" | ||
}, | ||
"main": "index" | ||
} |
@@ -21,2 +21,16 @@ # builder.js | ||
### Builder#conf | ||
The component.json contents. | ||
### Builder#addSourceURLs() | ||
Add "sourceURL" support, wrapping the module functions | ||
in `Function()` calls so that browsers may assign a | ||
name to the scripts to aid in debugging. | ||
### Builder#addLookup(path) | ||
Add the given dependency lookup `path`. | ||
### Builder#development() | ||
@@ -26,2 +40,13 @@ | ||
### Builder#addFile(type, filename, val) | ||
Add a fabricated file of the given `type`, `filename`, | ||
and contents `val`. For example if you were translating | ||
a Stylus file to .css, or a Jade template to .js you may | ||
do something like: | ||
```js | ||
builder.addFile('scripts', 'view.js', 'compiled view js'); | ||
``` | ||
### Builder#ignore(name, [type]) | ||
@@ -41,25 +66,11 @@ | ||
## License | ||
## Hooks | ||
(The MIT License) | ||
A build "hook" is like an event that lets you manipulate the build in process. For | ||
example you may use a hook to translate coffee script files to javascript automatically, | ||
or compile a template to javascript so that it may be loaded with `require()`, or use | ||
CSS pre-processors such as [rework](github.com/visionmedia/rework). | ||
Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca> | ||
## License | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22168
727
74
3
+ Addedcolor-parser@0.0.1(transitive)
+ Addedcss@1.0.7(transitive)
+ Addedcss-stringify@1.0.4(transitive)
+ Addedrework@0.9.1(transitive)
- Removedcss@1.0.5(transitive)
- Removedcss-stringify@1.0.3(transitive)
- Removedrework@0.7.0(transitive)
Updatedrework@0.9.1