Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Treat config file as "defaults", commandline flags override
Browse files Browse the repository at this point in the history
Now any option can be in the config, fixes excludes block in grunt-vulcanize not
being used unless it was in the config file.

Bump version
  • Loading branch information
dfreedm committed Apr 2, 2014
1 parent 527e4e0 commit 0851180
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
55 changes: 30 additions & 25 deletions lib/optparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ var DEFAULT = 'vulcanized.html';

// validate options with boolean return
function processOptions(options, callback) {
var config = {};
var excludes = {
imports: [ABS_URL],
scripts: [ABS_URL],
styles: [ABS_URL]
};

if (!options.input) {
return callback('No input file given!');
}

if (options.config) {
var configBlob;
var config;
try {
// TODO(dfreedm): Make this async
configBlob = fs.readFileSync(options.config, 'utf8');
Expand All @@ -36,36 +32,45 @@ function processOptions(options, callback) {
} catch(e) {
return callback('Malformed config JSON!');
}
if (config.excludes) {
var e = config.excludes;
try {
if (e.imports) {
e.imports.forEach(function(r) {
excludes.imports.push(new RegExp(r));
});
}
if (e.scripts) {
e.scripts.forEach(function(r) {
excludes.scripts.push(new RegExp(r));
});
}
if (e.styles) {
e.styles.forEach(function(r) {
excludes.styles.push(new RegExp(r));
});
}
} catch(_) {
return callback('Malformed import exclude config');
}

options.input = options.input || config.input;
if (!options.input) {
return callback('No input file given!');
}

options.excludes = options.excludes || config.excludes;
if (options.excludes) {
var e = options.excludes;
try {
if (e.imports) {
e.imports.forEach(function(r) {
excludes.imports.push(new RegExp(r));
});
}
if (e.scripts) {
e.scripts.forEach(function(r) {
excludes.scripts.push(new RegExp(r));
});
}
if (e.styles) {
e.styles.forEach(function(r) {
excludes.styles.push(new RegExp(r));
});
}
} catch(_) {
return callback('Malformed import exclude config');
}
}
options.excludes = excludes;

options.output = options.output || config.output;
if (!options.output) {
options.output = path.resolve(path.dirname(options.input), DEFAULT);
}
options.outputDir = path.dirname(options.output);

options.csp = options.csp || config.csp;
if (options.csp) {
options.csp = options.output.replace(/\.html$/, '.js');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vulcanize",
"version": "0.2.3",
"version": "0.2.4",
"description": "Process Web Components into one output file",
"main": "lib/vulcan.js",
"bin": {
Expand Down

0 comments on commit 0851180

Please sign in to comment.