Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
Write bundled html to file 👉🏻
Browse files Browse the repository at this point in the history
  • Loading branch information
dunnkers committed Oct 12, 2017
1 parent 41593a5 commit a9a9edd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
4 changes: 1 addition & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"name": "ember-polymer",
"dependencies": {
"paper-button": "PolymerElements/paper-button#^2.0.0",
"iron-icons": "PolymerElements/iron-icons#^2.0.1",
"polymer": "^2.1.0",
"webcomponentsjs": "^1.0.13",
"vaadin-date-picker": "^2.0.5"
"webcomponentsjs": "^1.0.13"
}
}
45 changes: 23 additions & 22 deletions bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ const Plugin = require('broccoli-plugin');
const path = require('path');

const RSVP = require('rsvp');
const PolymerBundler = require('polymer-bundler');
const mkdirp = require('mkdirp');
const clone = require('clone');
const fs = require('fs');

const { Bundler } = require('polymer-bundler');
const parse5 = require('parse5');

module.exports = Bundler;
Bundler.prototype = Object.create(Plugin.prototype);
Bundler.prototype.constructor = Bundler;
module.exports = ElementBundler;
ElementBundler.prototype = Object.create(Plugin.prototype);
ElementBundler.prototype.constructor = ElementBundler;

function Bundler(inputTree, options) {
if (!(this instanceof Bundler)) {
return new Bundler(inputTree, options);
function ElementBundler(inputTree, options) {
if (!(this instanceof ElementBundler)) {
return new ElementBundler(inputTree, options);
}

// Clone the options otherwise any alterations after this writer is called
Expand All @@ -26,36 +28,35 @@ function Bundler(inputTree, options) {
Plugin.call(this, [inputTree]);
}

Bundler.prototype.bundle = function (options) {
ElementBundler.prototype.bundle = function (options) {
return new RSVP.Promise(function (resolve, reject) {
mkdirp(path.dirname(options.output), function (error) {
if (error) {
reject(error);
}

console.log(options.input);
// console.log(options);
// console.log('relative:');
// console.log('from:', options.input);
// console.log('to:', process.cwd());
// console.log(path.relative(process.cwd(), options.input));

let inputPath = path.join('.', path.relative(process.cwd(), options.input));

const bundler = new PolymerBundler.Bundler(options);
bundler.generateManifest([options.input]).then((manifest) => {
const bundler = new Bundler(options);
bundler.generateManifest([ options.input ]).then((manifest) => {
bundler.bundle(manifest).then((result) => {
console.log('<!-- BUNDLED VERSION OF elements.html: -->');
console.log(parse5.serialize(result.documents.get('elements.html').ast));
let html = parse5.serialize(result.documents.get(path.basename(options.input)).ast);

fs.writeFileSync(options.output, html);
resolve();
}, (error) => reject(error)).catch((error) => reject(error));
}, (error) => reject(error)).catch((error) => reject(error));
// new Vulcan(options).process(options.input, function (error, html) {
// if (error) {
// reject(error);
// }

// fs.writeFileSync(options.output, html);
// resolve();
// });
});
});
};

Bundler.prototype.build = function () {
ElementBundler.prototype.build = function () {
// We have to clone options again as bundle changes the hash which causes
// the hash grow when called repeatedly.
let options = clone(this.options);
Expand Down
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ let fs = require('fs');
let fileExists = fs.existsSync;
let writeFile = fs.writeFileSync;
let MergeTrees = require('broccoli-merge-trees');
let Vulcanize = require('broccoli-vulcanize');
let quickTemp = require('quick-temp');
let Importer = require('./lib/importer');
let Config = require('./lib/config');
let Bundler = require('./bundler');
let ElementBundler = require('./bundler');

module.exports = {
name: 'ember-polymer',
Expand Down Expand Up @@ -61,15 +60,15 @@ module.exports = {
return tree;
}

let bundler = new Bundler(this.options.htmlImportsDir,
let bundler = new ElementBundler(this.options.htmlImportsDir,
this.options.vulcanizeOptions);

// merge normal tree and our vulcanize tree
// let vulcanize = new Vulcanize(this.options.htmlImportsDir,
// this.options.vulcanizeOptions);
return new MergeTrees([ tree, bundler ], {
overwrite: true,
annotation: 'Merge (ember-polymer merge vulcanize with addon tree)'
annotation: 'Merge (ember-polymer merge bundler with addon tree)'
});
}
};

0 comments on commit a9a9edd

Please sign in to comment.