From 1404fe484c115ef057c311d8659460e5873b728b Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Fri, 30 Aug 2013 14:36:19 -0700 Subject: [PATCH] make everything from imports inlined --- vulcanize/vulcan.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/vulcanize/vulcan.js b/vulcanize/vulcan.js index c82a7dc..b561180 100644 --- a/vulcanize/vulcan.js +++ b/vulcanize/vulcan.js @@ -37,7 +37,7 @@ if (!options.input) { var DEFAULT_OUTPUT = 'vulcanized.html'; if (!options.output) { - console.warn('Default output to index-vulcanized.html' + (options.csp ? ', vulcanized.js,' : '') + ' and vulcanized.html in the input directory.'); + 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); } @@ -173,6 +173,15 @@ function insertImport($, storedPosition, importText) { pos[operation](importText); } +function insertInlinedImports($, importText) { + var pos = $('body').last(); + var operation = 'prepend'; + if (!pos.length) { + pos = $.root(); + } + pos[operation](importText); +} + function handleMainDocument() { var $ = readDocument(options.input); var dir = path.dirname(options.input); @@ -213,10 +222,9 @@ function handleMainDocument() { findScriptLocation($).append(EOL + scripts_after_polymer.join(EOL) + EOL); } - fs.writeFileSync(options.output, output, 'utf8'); - imports_before_polymer.push(''); insertImport($, import_pos, imports_before_polymer.join(EOL) + EOL); - fs.writeFileSync(path.resolve(outputDir, 'index-vulcanized.html'), $.html(), 'utf8'); + insertInlinedImports($, output); + fs.writeFileSync(options.output, $.html(), 'utf8'); } handleMainDocument();