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

Commit

Permalink
split vulcan.js into vulcanize bin and lib/vulcan.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Oct 15, 2013
1 parent add2e37 commit 37d8a25
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
35 changes: 35 additions & 0 deletions vulcanize/bin/vulcanize
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node
var path = require('path');
var nopt = require('nopt');
var vulcan = require('../lib/vulcan.js');

var options = nopt(
{
'output': path,
'verbose': Boolean,
'csp': Boolean,
'inline': Boolean
},
{
'o': ['--output'],
'v': ['--verbose']
}
);

options.input = path.resolve(options.argv.remain[0]);

if (!options.input) {
console.error('No input file given!');
process.exit(1);
}

var DEFAULT_OUTPUT = 'vulcanized.html';
if (!options.output) {
console.warn('Default output to vulcanized.html' + (options.csp ? ' and vulcanized.js' : '') + ' in the input directory.');
options.output = path.resolve(path.dirname(options.input), DEFAULT_OUTPUT);
}

options.outputDir = path.dirname(options.output);

vulcan.setOptions(options);
vulcan.processDocument();
34 changes: 6 additions & 28 deletions vulcanize/vulcan.js → vulcanize/lib/vulcan.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,12 @@ var URL_TEMPLATE = '{{.*}}';
var import_buffer = [];
var imports_before_polymer = [];
var read = {};
var options = {};

var options = nopt(
{
'output': path,
'input': path,
'verbose': Boolean,
'csp': Boolean,
'inline': Boolean
},
{
'o': ['--output'],
'i': ['--input'],
'v': ['--verbose']
}
);

if (!options.input) {
console.error('No input file given!');
process.exit(1);
function setOptions(optHash) {
options = optHash;
}

var DEFAULT_OUTPUT = 'vulcanized.html';
if (!options.output) {
console.warn('Default output to vulcanized.html' + (options.csp ? ' and vulcanized.js' : '') + ' in the input directory.');
options.output = path.resolve(path.dirname(options.input), DEFAULT_OUTPUT);
}

var outputDir = path.dirname(options.output);

function resolvePaths($, input, output) {
var assetPath = path.relative(output, input);
assetPath = assetPath.split(path.sep).join('/') + '/';
Expand Down Expand Up @@ -124,7 +101,7 @@ function concat(filename) {
var dir = path.dirname(filename);
processImports($, dir);
inlineSheets($, dir);
resolvePaths($, dir, outputDir);
resolvePaths($, dir, options.outputDir);
import_buffer.push($.html());
} else {
if (options.verbose) {
Expand Down Expand Up @@ -248,4 +225,5 @@ function handleMainDocument() {
fs.writeFileSync(options.output, outhtml, 'utf8');
}

handleMainDocument();
exports.processDocument = handleMainDocument;
exports.setOptions = setOptions;

0 comments on commit 37d8a25

Please sign in to comment.