Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

feature: Optional configuration target #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 5 additions & 3 deletions lib/configwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,18 @@ ConfigWriter.prototype.process = function(file, config) {
context.inDir = block.searchPath[0];
}
self.forEachStep(block.type, function(writer, last) {
// Use the default 'generated' target unless a configuration target was specified
var target = block.target || 'generated';

// If this is the last writer of the pipe, we need to output
// in the destination directory
context.outDir = last ? self.dest : path.join(self.staging, writer.name);
context.last = last;
config[writer.name] = config[writer.name] || {};
config[writer.name].generated = config[writer.name].generated || {};
config[writer.name][target] = config[writer.name][target] || {};
context.options = config[writer.name];
// config[writer.name].generated = _.extend(config[writer.name].generated, writer.createConfig(context, block));
config[writer.name].generated = deepMerge(config[writer.name].generated, writer.createConfig(context, block));
// config[writer.name][target] = _.extend(config[writer.name][target], writer.createConfig(context, block));
config[writer.name][target] = deepMerge(config[writer.name][target], writer.createConfig(context, block));
context.inDir = context.outDir;
context.inFiles = context.outFiles;
context.outFiles = [];
Expand Down
30 changes: 20 additions & 10 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ var fs = require('fs');
//
var getBlocks = function (content) {
// start build pattern: will match
// * <!-- build:[target] output -->
// * <!-- build:[target](alternate search path) output -->
// * <!-- build:[type] output -->
// * <!-- build:[type]:[target] output -->
// * <!-- build:[type](alternate search path) output -->
// * <!-- build:[type]:[target](alternate search path) output -->

// The following matching param are set when there's match
// * 0 : the whole matched expression
// * 1 : the target (ie. type)
// * 2 : the alternate search path
// * 3 : the output
// * 1 : the type (ie. js, css)
// * 2 : an optional configuration target
// * 3 : the alternate search path
// * 4 : the output
//
var regbuild = /<!--\s*build:(\w+)(?:\(([^\)]+)\))?\s*([^\s]+)\s*-->/;
var regbuild = /<!--\s*build:(\w+)(?::(\w+))?(?:\(([^\)]+)\))?\s*([^\s]+)\s*-->/;

// end build pattern -- <!-- endbuild -->
var regend = /<!--\s*endbuild\s*-->/;

Expand All @@ -62,13 +67,13 @@ var getBlocks = function (content) {
if (build) {
block = true;
// Handle absolute path (i.e. with respect to the server root)
// if (build[3][0] === '/') {
// if (build[4][0] === '/') {
// startFromRoot = true;
// build[3] = build[3].substr(1);
// build[4] = build[4].substr(1);
// }
last = {
type: build[1],
dest: build[3],
dest: build[4],
startFromRoot: startFromRoot,
indent: indent,
searchPath: [],
Expand All @@ -77,8 +82,13 @@ var getBlocks = function (content) {
};

if (build[2]) {
// Optional configuration target
last.target = build[2];
}

if (build[3]) {
// Alternate search path
last.searchPath.push(build[2]);
last.searchPath.push(build[3]);
}
}
// Check IE conditionals
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/optional_configuration_target.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="styles/main.css">
<script src="scripts/vendor/modernizr.min.js"></script>
</head>
<body>

<!-- build:js:thirdparty scripts/thirdparty.js -->
<script src="scripts/bar.js"></script>
<script src="scripts/baz.js"></script>
<!-- endbuild -->
</body>
</html>
7 changes: 7 additions & 0 deletions test/test-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,12 @@ describe('File', function() {
assert.equal('(min-width:980px)', file.blocks[0].media);
});

it('should detect an optional configuration target', function() {
var filename = __dirname + '/fixtures/optional_configuration_target.html';
var file = new File(filename);
assert.equal(1, file.blocks.length);
assert.ok(file.blocks[0].target);
assert.equal('thirdparty', file.blocks[0].target);
});

});