Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = Builder;
* @api private
*/

function Builder(dir, parent) {
function Builder(dir, parent, config) {
var self = this;
this._cache = {};
this._hooks = {};
Expand All @@ -57,7 +57,7 @@ function Builder(dir, parent) {
};

// load config
this.config = this.json();
this.config = config || this.json();
this.config.paths = this.config.paths || [];

this.basename = this.root
Expand Down
67 changes: 67 additions & 0 deletions test/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ describe('Builder', function(){
})
})

it('should build js with config injected', function(done){
var builder = new Builder('test/fixtures/hello-no-json', null, require('./fixtures/hello-no-json/no-component.json'));
builder.addLookup('test/fixtures');
builder.build(function(err, res){
if (err) return done(err);
var out = read('test/fixtures/hello.js', 'utf8');
res.js.trim().should.equal(out.trim());
done();
})
})



it('should build css', function(done){
var builder = new Builder('test/fixtures/hello');
builder.addLookup('test/fixtures');
Expand All @@ -114,6 +127,18 @@ describe('Builder', function(){
})
})

it('should build css with config injected', function(done){
var builder = new Builder('test/fixtures/hello', null, require('./fixtures/hello-no-json/no-component.json'));
builder.addLookup('test/fixtures');
builder.build(function(err, res){
if (err) return done(err);
var out = read('test/fixtures/hello.css', 'utf8');
res.css.should.equal(out);
done();
})
})


it('should load the require.js script', function(done){
var builder = new Builder('test/fixtures/hello');
builder.addLookup('test/fixtures');
Expand Down Expand Up @@ -167,6 +192,25 @@ describe('Builder', function(){
});
})

it('should symlink .images with config injected', function(done){
var builder = new Builder('test/fixtures/assets-no-json', null, require('./fixtures/assets-no-json/no-component.json'));
builder.addLookup('test/fixtures');
builder.copyAssetsTo('/tmp/build');
builder.build(function(err, res){
if (err) return done(err);
assert(3 == res.images.length);
assert('/tmp/build/assets/images/logo.png' == res.images[0]);
assert('/tmp/build/assets/images/maru.jpeg' == res.images[1]);
assert('/tmp/build/assets/images/npm.png' == res.images[2]);
assert(exists('/tmp/build/assets/images/maru.jpeg'));
assert(exists('/tmp/build/assets/images/logo.png'));
assert(exists('/tmp/build/assets/images/npm.png'));
done();
});
})



it('should symlink .files', function(done){
var builder = new Builder('test/fixtures/assets-parent');
builder.addLookup('test/fixtures');
Expand Down Expand Up @@ -205,6 +249,29 @@ describe('Builder', function(){
});
})

it('should copy .images in copyFiles mode when config injected', function(done){
var builder = new Builder('test/fixtures/assets', null, require('./fixtures/assets-no-json/no-component.json'));
builder.copyFiles();
builder.addLookup('test/fixtures');
builder.copyAssetsTo('/tmp/build');
builder.build(function(err, res){
if (err) return done(err);
assert(3 == res.images.length);
assert('/tmp/build/assets/images/logo.png' == res.images[0]);
assert('/tmp/build/assets/images/maru.jpeg' == res.images[1]);
assert('/tmp/build/assets/images/npm.png' == res.images[2]);
assert(exists('/tmp/build/assets/images/maru.jpeg'));
assert(exists('/tmp/build/assets/images/logo.png'));
assert(exists('/tmp/build/assets/images/npm.png'));
// images aren't symlinks
fs.lstat('/tmp/build/assets/images/npm.png', function(err, stats) {
assert(stats.isSymbolicLink() == false);
done();
});
});
})


it('should copy .files in copyFiles mode', function(done){
var builder = new Builder('test/fixtures/assets-parent');
builder.copyFiles();
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/assets-no-json/css/sub.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-image: url(../images/npm.png);
}
Binary file added test/fixtures/assets-no-json/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/assets-no-json/images/maru.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/assets-no-json/images/npm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions test/fixtures/assets-no-json/no-component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "assets",
"description": "a bunch of assets",
"images": [
"images/logo.png",
"images/maru.jpeg",
"images/npm.png"
],
"files": [
"some.txt"
],
"styles": [
"style.css",
"css/sub.css"
]
}
1 change: 1 addition & 0 deletions test/fixtures/assets-no-json/some.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text
21 changes: 21 additions & 0 deletions test/fixtures/assets-no-json/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.logo {
background: url(images/logo.png);
}

#maru {
width: 500px;
height: 500px;
background: url("images/maru.jpeg") no-repeat;
}

#manny {
background: url(http://example.com/images/manny.png);
}

#bob {
background-image: url(data:image/png;base64,PNG DATA HERE)
}

#bar {
background-image: url(/public/images/foo.png)
}
3 changes: 3 additions & 0 deletions test/fixtures/hello-no-json/bar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bar {
baz: 'raz';
}
1 change: 1 addition & 0 deletions test/fixtures/hello-no-json/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'bar';
3 changes: 3 additions & 0 deletions test/fixtures/hello-no-json/foo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo {
bar: 'baz';
}
1 change: 1 addition & 0 deletions test/fixtures/hello-no-json/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'foo';
10 changes: 10 additions & 0 deletions test/fixtures/hello-no-json/no-component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "hello",
"description": "hello world component",
"version": "0.0.1",
"dependencies": {
"component/emitter": "*"
},
"scripts": ["foo.js", "bar.js"],
"styles": ["foo.css", "bar.css"]
}