Skip to content

Commit

Permalink
Merge pull request #41 from davewasmer/feature-refactor-plugin
Browse files Browse the repository at this point in the history
Raw object
  • Loading branch information
Exelord authored Sep 2, 2018
2 parents 0ea8b9a + ca466b5 commit db9aa8e
Show file tree
Hide file tree
Showing 5 changed files with 744 additions and 12 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"broccoli-caching-writer": "3.0.3",
"favicons": "~5.1.1",
"heimdalljs-logger": "~0.1.10",
"himalaya": "1.1.0",
"lodash.merge": "~4.6.1"
},
"devDependencies": {
Expand Down
24 changes: 15 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Plugin from 'broccoli-caching-writer';
import FaviconsJs from 'favicons';

import deepMerge from 'lodash.merge';
import path from 'path';
import fs from 'fs';

import config from './config';

import fs from 'fs';
import path from 'path';
import deepMerge from 'lodash.merge';
import { parse as parseHtml } from 'himalaya';
import { default as _logger } from 'heimdalljs-logger';

const logger = _logger('broccoli-favicon');
Expand All @@ -21,18 +22,23 @@ export default class Favicon extends Plugin {
}

build() {
let { iconPath, onSuccess, faviconsConfig } = this.config;
let { iconPath, faviconsConfig } = this.config;
iconPath = path.join(this.inputPaths[0], iconPath);

if (!fs.existsSync(iconPath)) {
logger.warn(`Favicon file has been not detected in specified path: "${iconPath}"`);
return Promise.resolve()
}

return this._generateFavicons(iconPath, faviconsConfig).then((response) => {
this._saveFiles(response.images.concat(response.files))
return onSuccess(response);
});
return this._generateFavicons(iconPath, faviconsConfig).then(this._onSuccess.bind(this));
}

_onSuccess(response) {
let parsedHtml = parseHtml(response.html.join(''));

this._saveFiles(response.images.concat(response.files))

return this.config.onSuccess(response.html, parsedHtml);
}

_generateFavicons(imagePath, options = {}) {
Expand Down
Loading

0 comments on commit db9aa8e

Please sign in to comment.