This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2013 The Polymer Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var ABS_URL = require('./contants.js').ABS_URL; | ||
var DEFAULT = 'vulcanized.html'; | ||
|
||
// validate options with boolean return | ||
function processOptions(optHash, callback) { | ||
excludes = { | ||
imports: [ABS_URL], | ||
scripts: [ABS_URL], | ||
styles: [ABS_URL] | ||
}; | ||
|
||
var options = { | ||
csp: '', | ||
input: '', | ||
excludes: excludes, | ||
output: '', | ||
outputDir: '' | ||
}; | ||
|
||
if (!optHash.input) { | ||
return callback('No input file given!'); | ||
} | ||
|
||
options.input = optHash.input; | ||
|
||
if (optHash.excludes) { | ||
var e = optHash.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'); | ||
} | ||
} | ||
|
||
if (!optHash.output) { | ||
options.output = path.resolve(path.dirname(optHash.input), DEFAULT); | ||
options.outputDir = path.dirname(options.output); | ||
} else { | ||
options.output = optHash.output; | ||
} | ||
|
||
if (optHash.csp) { | ||
options.csp = options.output.replace(/\.html$/, '.js'); | ||
} | ||
|
||
callback(null, options); | ||
} | ||
|
||
exports.processOptions = processOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters