Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

component-builder

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

component-builder - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

6

History.md
0.4.0 / 2012-11-04
==================
* add `url()` rewriting. Closes #28
* add asset symlinking for `.files`, `.images`, and `.fonts`
0.3.0 / 2012-10-31

@@ -3,0 +9,0 @@ ==================

201

lib/builder.js

@@ -13,2 +13,5 @@

, requirejs = require('component-require')
, mkdir = require('mkdirp')
, rework = require('rework')
, dirname = path.dirname
, basename = path.basename;

@@ -39,5 +42,8 @@

scripts: [],
styles: []
styles: [],
files: [],
images: [],
fonts: []
};
this.on('dependency', this.inheritLookupPaths.bind(this));
this.on('dependency', this.inherit.bind(this));
}

@@ -52,5 +58,31 @@

/**
* Inherit lookup paths from so that subsequent
* utilize the same lookup path(s).
* Copy assets to the given `dir`.
*
* @param {String} dir
* @api public
*/
Builder.prototype.copyAssetsTo = function(dir){
this.assetsDest = dir;
};
/**
* Prefix css `url()`s with `str`. For example
* when building in development and serving from ./build
* you'll typically want "./" so they become relative
* and work well with `file://`. However when serving
* from your application you may want "/public", or
* no prefix at all such as `/mycomponent/images/foo.png`.
*
* @param {String} str
* @api public
*/
Builder.prototype.prefixUrls = function(str){
this.urlPrefix = str;
};
/**
* Inherit lookup paths, ignored, and asset dest dir.
*
* @param {Builder} dep

@@ -60,4 +92,7 @@ * @api private

Builder.prototype.inheritLookupPaths = function(dep){
Builder.prototype.inherit = function(dep){
dep.paths = this.paths;
dep.ignored = this.ignored;
dep.prefixUrls(this.urlPrefix);
dep.copyAssetsTo(this.assetsDest);
};

@@ -245,2 +280,5 @@

* - `js`
* - `images`
* - `fonts`
* - `files`
*

@@ -259,2 +297,5 @@ * NOTE: Batch maintains result ordering (res.shift()s here)

batch.push(this.buildStyles.bind(this));
batch.push(this.buildImages.bind(this));
batch.push(this.buildFonts.bind(this));
batch.push(this.buildFiles.bind(this));
batch.end(function(err, res){

@@ -265,2 +306,5 @@ if (err) return fn(err);

css: res.shift(),
images: res.shift(),
fonts: res.shift(),
files: res.shift(),
require: requirejs

@@ -412,3 +456,2 @@ });

var builder = new Builder(dir, self);
builder.ignored = self.ignored;
self.emit('dependency', builder);

@@ -442,2 +485,115 @@ builder.buildType(type, done, process);

/**
* Build asset `type` and invoke `fn(err, paths)`.
*
* @param {String} type
* @param {Function} fn
* @api private
*/
Builder.prototype.buildAsset = function(type, fn){
var self = this;
debug('build asset %s', type);
this.json(function(err, conf){
if (err) return fn(err);
var batch = new Batch;
// build dependencies
if (self.hasDependencies()) {
Object.keys(self.dependencies()).forEach(function(dep){
dep = normalize(dep);
// ignored
if (self.ignoring(dep, type)) return debug('ignoring %s', dep);
// ignore it so we dont have dups
self.ignore(dep, type);
// lookup dep
batch.push(function(done){
self.lookup(dep, function(err, dir){
if (err) return done(err);
var builder = new Builder(dir, self);
self.emit('dependency', builder);
builder.buildAsset(type, done);
});
});
});
}
// copy assets
if (conf[type]) {
conf[type].forEach(function(file){
var path = self.path(file);
var name = normalize(self.name);
var dest = join(self.assetsDest, name, file);
batch.push(function(done){
self.copyTo(path, dest, done);
});
});
}
batch.end(function(err, res){
if (err) return fn(err);
fn(null, res);
});
});
};
/**
* Copy `file` to `dest` and invoke `fn(err, path)`.
*
* @param {String} file
* @param {String} dest
* @param {Function} fn
* @api private
*/
Builder.prototype.copyTo = function(file, dest, fn){
var dir = dirname(dest);
debug('mkdir -p %s', dir);
mkdir(dir, function(err){
if (err) return fn(err);
debug('link %s -> %s', file, dest);
fs.symlink(file, dest, function(err){
if (err && 'EEXIST' == err.code) return fn(null, dest);
fn(err, dest);
});
});
};
/**
* Build `.files` array and invoke `fn(err, paths)`.
*
* @param {Function} fn
* @api private
*/
Builder.prototype.buildFiles = function(fn){
this.buildAsset('files', fn);
};
/**
* Build `.images` array and invoke `fn(err, paths)`.
*
* @param {Function} fn
* @api private
*/
Builder.prototype.buildImages = function(fn){
this.buildAsset('images', fn);
};
/**
* Build `.fonts` array and invoke `fn(err, paths)`.
*
* @param {Function} fn
* @api private
*/
Builder.prototype.buildFonts = function(fn){
this.buildAsset('fonts', fn);
};
/**
* Build scripts and invoke `fn(err, js)`.

@@ -461,3 +617,4 @@ *

Builder.prototype.buildStyles = function(fn){
this.buildType('styles', fn, noop);
var self = this;
this.buildType('styles', fn, rewriteUrls);
};

@@ -503,2 +660,32 @@

/**
* Return css with urls rewritten relative
* to the `.assetDest` directory. This allows
* the consumer to serve the asset destination
* directory (typically `./build`) to match
* the symlinks made.
*
* @param {Builder} builder
* @param {String} file
* @param {String} css
* @return {String}
* @api private
*/
function rewriteUrls(builder, file, css) {
function isAbsolute(url) {
return ~url.indexOf('://');
}
function rewrite(url) {
if (isAbsolute(url)) return url;
var name = normalize(builder.name);
return join(builder.urlPrefix, '/', name, url);
}
return rework(css)
.use(rework.url(rewrite))
.toString();
}
/**
* Merge `b` into `a`.

@@ -505,0 +692,0 @@ *

14

package.json
{
"name": "component-builder",
"version": "0.3.0",
"version": "0.4.0",
"description": "Component build tool",
"keywords": ["component", "build"],
"keywords": [
"component",
"build"
],
"author": "TJ Holowaychuk <tj@vision-media.caa>",

@@ -10,3 +13,6 @@ "dependencies": {

"batch": "0.1.1",
"debug": "*"
"rework": "0.7.0",
"mkdirp": "0.3.4",
"debug": "*",
"better-assert": "~0.1.0"
},

@@ -18,2 +24,2 @@ "devDependencies": {

"main": "index"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc