requirejs-module-build
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -79,10 +79,19 @@ var builder = require('../builder'), | ||
exports.module = function(config, module, filter, options, callback) { | ||
var buildFunc; | ||
if (options.placeholder === true) { | ||
buildFunc = buildPlaceholder; | ||
// If a module config has filters and the filter option is not set | ||
// we should build all filters | ||
if (!filter && config.getModuleFilters(module)) { | ||
async.each(config.getModuleFilters(module), function(filter, callback) { | ||
build(config, module, filter, options, callback); | ||
}, callback); | ||
} else { | ||
buildFunc = build; | ||
build(config, module, filter, options, callback); | ||
} | ||
// Build placeholders if enabled | ||
if (config.shouldBuildPlaceholder(module) === true) { | ||
exports.placeholder(config, module, filter, options, callback); | ||
} | ||
}; | ||
exports.placeholder = function(config, module, filter, options, callback) { | ||
// If a module config has filters and the filter option is not set | ||
@@ -92,7 +101,7 @@ // we should build all | ||
async.each(config.getModuleFilters(module), function(filter, callback) { | ||
buildFunc(config, module, filter, options, callback); | ||
buildPlaceholder(config, module, filter, options, callback); | ||
}, callback); | ||
} else { | ||
buildFunc(config, module, filter, options, callback); | ||
buildPlaceholder(config, module, filter, options, callback); | ||
} | ||
}; |
@@ -9,3 +9,3 @@ var loader = require('../loader'), | ||
' module Name of the module to build or "all" for all modules including', | ||
' all filters', | ||
' all filters and placeholders', | ||
'', | ||
@@ -16,3 +16,3 @@ 'Options:', | ||
' -o, --optimizer <name> Override RequireJS optimizer', | ||
' --p, --parallel <number> Number of parallel builds to run. Defaults is 5', | ||
' -p, --parallel <number> Number of parallel builds to run. Defaults is 5', | ||
' --placeholder Build placeholder', | ||
@@ -58,2 +58,4 @@ ' -v, --verbose Be verbose', | ||
build.all(config, options, callback); | ||
} else if (options.placeholder === true) { | ||
build.placeholder(config, module, filter, options, callback); | ||
} else { | ||
@@ -60,0 +62,0 @@ build.module(config, module, filter, options, callback); |
@@ -41,2 +41,16 @@ var fs = require('fs'), | ||
Config.prototype.shouldBuildPlaceholder = function(module) { | ||
if (!this.hasModule(module)) { | ||
throw new Error('Unknown module ' + module); | ||
} | ||
var config = this.getModuleConfig(module); | ||
if (!config.buildPlaceholder || typeof config.buildPlaceholder !== 'boolean') { | ||
return false; | ||
} | ||
return config.buildPlaceholder; | ||
}; | ||
Config.prototype.generate = function(module, filter, callback) { | ||
@@ -43,0 +57,0 @@ var config; |
{ | ||
"name": "requirejs-module-build", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Tool for configuring and building non-CommonJS requirejs modules", | ||
@@ -5,0 +5,0 @@ "main": "./lib/main", |
@@ -33,2 +33,3 @@ requirejs-module-build | ||
-o, --optimizer <name> Override RequireJS optimizer | ||
-p, --parallel <number> Number of parallel builds to run. Defaults is 5 | ||
--placeholder Build placeholder | ||
@@ -35,0 +36,0 @@ -v, --verbose Be verbose |
@@ -73,4 +73,8 @@ var test = require('tape'), | ||
sinon.stub(console, 'log'); | ||
cli({ _: ['instagram'], config: configFile, filter: 'mobile' }); | ||
console.log.restore(); | ||
stub.restore(); | ||
@@ -86,4 +90,8 @@ | ||
sinon.stub(console, 'log'); | ||
cli({ _: ['instagram'], config: configFile }); | ||
console.log.restore(); | ||
stub.restore(); | ||
@@ -95,2 +103,58 @@ | ||
test('module with placeholder cli option', function(t) { | ||
t.plan(2); | ||
var stub = sinon.stub(Config.prototype, 'generatePlaceholder'); | ||
sinon.stub(console, 'log'); | ||
cli({ _: ['instagram'], config: configFile, placeholder: true }); | ||
console.log.restore(); | ||
stub.restore(); | ||
t.ok(stub.firstCall.calledWith('instagram', 'desktop')); | ||
t.equals(stub.callCount, 3); | ||
}); | ||
test('module with placeholder and filter cli option', function(t) { | ||
t.plan(2); | ||
var stub = sinon.stub(Config.prototype, 'generatePlaceholder'); | ||
sinon.stub(console, 'log'); | ||
cli({ _: ['instagram'], config: configFile, placeholder: true, filter: 'mobile' }); | ||
console.log.restore(); | ||
stub.restore(); | ||
t.ok(stub.calledWith('instagram', 'mobile')); | ||
t.equals(stub.callCount, 1); | ||
}); | ||
test('module with buildPlaceholder config option', function(t) { | ||
t.plan(4); | ||
var generateStub = sinon.stub(Config.prototype, 'generate'); | ||
var placeholderStub = sinon.stub(Config.prototype, 'generatePlaceholder'); | ||
sinon.stub(console, 'log'); | ||
cli({ _: ['instagramWithPlaceholder'], config: configFile }); | ||
console.log.restore(); | ||
generateStub.restore(); | ||
placeholderStub.restore(); | ||
t.ok(generateStub.firstCall.calledWith('instagramWithPlaceholder', 'desktop')); | ||
t.ok(placeholderStub.firstCall.calledWith('instagramWithPlaceholder', 'desktop')); | ||
t.equals(generateStub.callCount, 3); | ||
t.equals(placeholderStub.callCount, 3); | ||
}); | ||
test('all modules', function(t) { | ||
@@ -104,3 +168,3 @@ t.plan(1); | ||
t.equals(stub.callCount, 19); | ||
t.equals(stub.callCount, 20); | ||
}); | ||
@@ -107,0 +171,0 @@ }); |
@@ -39,2 +39,11 @@ { | ||
}, | ||
"instagramWithPlaceholder": { | ||
"directory": "instagram", | ||
"filters": { | ||
"desktop": "!(*.mobile.*)", | ||
"mobile": "*.mobile.*", | ||
"all": "*" | ||
}, | ||
"buildPlaceholder": true | ||
}, | ||
"excludeModulesFaulty": { | ||
@@ -41,0 +50,0 @@ "excludeModules": {}, |
42424
1001
137
25