Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 37d8a25

Browse files
committed
split vulcan.js into vulcanize bin and lib/vulcan.js
1 parent add2e37 commit 37d8a25

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

vulcanize/bin/vulcanize

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
var path = require('path');
3+
var nopt = require('nopt');
4+
var vulcan = require('../lib/vulcan.js');
5+
6+
var options = nopt(
7+
{
8+
'output': path,
9+
'verbose': Boolean,
10+
'csp': Boolean,
11+
'inline': Boolean
12+
},
13+
{
14+
'o': ['--output'],
15+
'v': ['--verbose']
16+
}
17+
);
18+
19+
options.input = path.resolve(options.argv.remain[0]);
20+
21+
if (!options.input) {
22+
console.error('No input file given!');
23+
process.exit(1);
24+
}
25+
26+
var DEFAULT_OUTPUT = 'vulcanized.html';
27+
if (!options.output) {
28+
console.warn('Default output to vulcanized.html' + (options.csp ? ' and vulcanized.js' : '') + ' in the input directory.');
29+
options.output = path.resolve(path.dirname(options.input), DEFAULT_OUTPUT);
30+
}
31+
32+
options.outputDir = path.dirname(options.output);
33+
34+
vulcan.setOptions(options);
35+
vulcan.processDocument();

vulcanize/vulcan.js renamed to vulcanize/lib/vulcan.js

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,12 @@ var URL_TEMPLATE = '{{.*}}';
1717
var import_buffer = [];
1818
var imports_before_polymer = [];
1919
var read = {};
20+
var options = {};
2021

21-
var options = nopt(
22-
{
23-
'output': path,
24-
'input': path,
25-
'verbose': Boolean,
26-
'csp': Boolean,
27-
'inline': Boolean
28-
},
29-
{
30-
'o': ['--output'],
31-
'i': ['--input'],
32-
'v': ['--verbose']
33-
}
34-
);
35-
36-
if (!options.input) {
37-
console.error('No input file given!');
38-
process.exit(1);
22+
function setOptions(optHash) {
23+
options = optHash;
3924
}
4025

41-
var DEFAULT_OUTPUT = 'vulcanized.html';
42-
if (!options.output) {
43-
console.warn('Default output to vulcanized.html' + (options.csp ? ' and vulcanized.js' : '') + ' in the input directory.');
44-
options.output = path.resolve(path.dirname(options.input), DEFAULT_OUTPUT);
45-
}
46-
47-
var outputDir = path.dirname(options.output);
48-
4926
function resolvePaths($, input, output) {
5027
var assetPath = path.relative(output, input);
5128
assetPath = assetPath.split(path.sep).join('/') + '/';
@@ -124,7 +101,7 @@ function concat(filename) {
124101
var dir = path.dirname(filename);
125102
processImports($, dir);
126103
inlineSheets($, dir);
127-
resolvePaths($, dir, outputDir);
104+
resolvePaths($, dir, options.outputDir);
128105
import_buffer.push($.html());
129106
} else {
130107
if (options.verbose) {
@@ -248,4 +225,5 @@ function handleMainDocument() {
248225
fs.writeFileSync(options.output, outhtml, 'utf8');
249226
}
250227

251-
handleMainDocument();
228+
exports.processDocument = handleMainDocument;
229+
exports.setOptions = setOptions;

0 commit comments

Comments
 (0)