diff --git a/vulcanize/bin/vulcanize b/vulcanize/bin/vulcanize new file mode 100755 index 0000000..3014daf --- /dev/null +++ b/vulcanize/bin/vulcanize @@ -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(); diff --git a/vulcanize/vulcan.js b/vulcanize/lib/vulcan.js similarity index 90% rename from vulcanize/vulcan.js rename to vulcanize/lib/vulcan.js index 697dadc..0799db6 100644 --- a/vulcanize/vulcan.js +++ b/vulcanize/lib/vulcan.js @@ -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('/') + '/'; @@ -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) { @@ -248,4 +225,5 @@ function handleMainDocument() { fs.writeFileSync(options.output, outhtml, 'utf8'); } -handleMainDocument(); +exports.processDocument = handleMainDocument; +exports.setOptions = setOptions;