Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 738de33

Browse filesBrowse files
committed
Merge pull request #128 from ianstormtaylor/json
add native json support to scripts
2 parents 4afdb9f + 981ec77 commit 738de33
Copy full SHA for 738de33

File tree

Expand file treeCollapse file tree

5 files changed

+45
-3
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+45
-3
lines changed

‎lib/builder.js

Copy file name to clipboardExpand all lines: lib/builder.js
+19-3Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ function Builder(dir, parent) {
5353
files: [],
5454
images: [],
5555
fonts: [],
56-
templates: []
56+
templates: [],
57+
json: []
5758
};
5859

5960
// load config
@@ -456,6 +457,7 @@ Builder.prototype.build = function(fn){
456457
var batch = new Batch;
457458
debug('building %s', this.dir);
458459
batch.push(this.buildScripts.bind(this));
460+
batch.push(this.buildJson.bind(this));
459461
batch.push(this.buildTemplates.bind(this));
460462
batch.push(this.buildAliases.bind(this));
461463
batch.push(this.buildStyles.bind(this));
@@ -466,10 +468,11 @@ Builder.prototype.build = function(fn){
466468
if (err) return fn(err);
467469

468470
var scripts = res.shift();
469-
var require = res.shift();
471+
var json = res.shift();
470472
var templates = res.shift();
473+
var require = res.shift();
471474
var custom = self._js;
472-
var js = [scripts, require, templates, custom].filter(empty).join('\n')
475+
var js = [scripts, json, templates, require, custom].filter(empty).join('\n');
473476

474477
fn(null, {
475478
js: js,
@@ -817,6 +820,19 @@ Builder.prototype.buildScripts = function(fn){
817820
this.buildType('scripts', fn, register);
818821
};
819822

823+
/**
824+
* Build JSON and invoke `fn(err, js)`.
825+
*
826+
* @param {Function} fn
827+
* @api private
828+
*/
829+
830+
Builder.prototype.buildJson = function(fn){
831+
this.buildType('json', fn, function(builder, file, str){
832+
return register(builder, file, 'module.exports = ' + str);
833+
});
834+
};
835+
820836
/**
821837
* Build templates and invoke `fn(err, str)`
822838
*

‎test/builder.js

Copy file name to clipboardExpand all lines: test/builder.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ describe('Builder', function(){
5050
})
5151
})
5252

53+
describe('.buildJson(fn)', function(){
54+
it('should build the json files', function(done){
55+
var builder = new Builder('test/fixtures/json');
56+
builder.addLookup('test/fixtures');
57+
builder.buildJson(function(err, str){
58+
if (err) return done(err);
59+
var out = read('test/fixtures/json.js', 'utf8');
60+
str.trim().should.equal(out.trim());
61+
done();
62+
})
63+
})
64+
})
65+
5366
describe('.buildTemplates(fn)', function(){
5467
it('should build the templates', function(done){
5568
var builder = new Builder('test/fixtures/template-strings');

‎test/fixtures/json.js

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require.register("json/index.json", function(exports, require, module){
2+
module.exports = {
3+
"key": "value"
4+
}
5+
});

‎test/fixtures/json/component.json

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "json",
3+
"version": "0.0.1",
4+
"json": ["index.json"]
5+
}

‎test/fixtures/json/index.json

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"key": "value"
3+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.