Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: node_modules/vulcanize/lib/optparser.js

Issue 800513006: Added vulcanize under third_party/npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « node_modules/vulcanize/lib/constants.js ('k') | node_modules/vulcanize/lib/pathresolver.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /**
2 * @license
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at http://polyme r.github.io/LICENSE.txt
5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS. txt
6 * The complete set of contributors may be found at http://polymer.github.io/CON TRIBUTORS.txt
7 * Code distributed by Google as part of the polymer project is also
8 * subject to an additional IP rights grant found at http://polymer.github.io/PA TENTS.txt
9 */
10
11 var fs = require('fs');
12 var path = require('path');
13
14 var CONSTANTS = require('./constants.js');
15 var ABS_URL = CONSTANTS.ABS_URL;
16 var REMOTE_ABS_URL = CONSTANTS.REMOTE_ABS_URL;
17 var DEFAULT = 'vulcanized.html';
18
19 // validate options with boolean return
20 function processOptions(options, callback) {
21 var config = {};
22 var excludes = {
23 imports: [],
24 scripts: [],
25 styles: []
26 };
27
28 options = options || Object.create(null);
29
30 if (options.config) {
31 var configBlob;
32 try {
33 // TODO(dfreedm): Make this async
34 configBlob = fs.readFileSync(options.config, 'utf8');
35 } catch(e) {
36 return callback('Config file not found!');
37 }
38 try {
39 config = JSON.parse(configBlob);
40 } catch(e) {
41 return callback('Malformed config JSON!');
42 }
43 }
44
45 options.input = options.input || config.input;
46 if (!options.input && !options.inputSrc) {
47 return callback('No input file or source string given!');
48 }
49
50 options.excludes = options.excludes || config.excludes;
51 if (options.excludes) {
52 var e = options.excludes;
53 try {
54 if (e.imports) {
55 e.imports.forEach(function(r) {
56 excludes.imports.push(new RegExp(r));
57 });
58 }
59 if (e.scripts) {
60 e.scripts.forEach(function(r) {
61 excludes.scripts.push(new RegExp(r));
62 });
63 }
64 if (e.styles) {
65 e.styles.forEach(function(r) {
66 excludes.styles.push(new RegExp(r));
67 });
68 }
69 } catch(_) {
70 return callback('Malformed import exclude config');
71 }
72 }
73
74 options.output = options.output || config.output;
75 if (!options.output) {
76 options.output = path.resolve(path.dirname(options.input), DEFAULT);
77 }
78 options.outputDir = path.dirname(options.output);
79
80 options.csp = options.csp || config.csp;
81 if (options.csp) {
82 options.csp = options.output.replace(/\.html$/, '.js');
83 }
84
85 options.abspath = options.abspath || config.abspath;
86 if (options.abspath) {
87 options.abspath = path.resolve(options.abspath);
88 excludes.imports.push(REMOTE_ABS_URL);
89 excludes.scripts.push(REMOTE_ABS_URL);
90 excludes.styles.push(REMOTE_ABS_URL);
91 } else {
92 excludes.imports.push(ABS_URL);
93 excludes.scripts.push(ABS_URL);
94 excludes.styles.push(ABS_URL);
95 }
96
97 options.excludes = excludes;
98
99 options.keepExcludes = options['strip-excludes'] === false || config['strip-ex cludes'] === false;
100
101 callback(null, options);
102 }
103
104 exports.processOptions = processOptions;
OLDNEW
« no previous file with comments | « node_modules/vulcanize/lib/constants.js ('k') | node_modules/vulcanize/lib/pathresolver.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698