diff --git a/.travis.yml b/.travis.yml index fa8617ca9..2e7e3fdbf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ --- language: node_js node_js: - - "4" + - "6" sudo: false diff --git a/addon/instance-initializers/browser/responsive-meta.js b/addon/instance-initializers/browser/responsive-meta.js deleted file mode 100644 index 45671261e..000000000 --- a/addon/instance-initializers/browser/responsive-meta.js +++ /dev/null @@ -1,14 +0,0 @@ -import ResponsiveImage from '../../services/responsive-image'; -import Ember from 'ember'; - -export function initialize(/* appInstance */) { - let meta = JSON.parse(Ember.$('#ember_responsive_image_meta').text()); - ResponsiveImage.reopen({ - meta - }); -} - -export default { - name: 'responsive-meta', - initialize -}; diff --git a/addon/instance-initializers/responsive-meta.js b/addon/instance-initializers/responsive-meta.js new file mode 100644 index 000000000..8945a0d93 --- /dev/null +++ b/addon/instance-initializers/responsive-meta.js @@ -0,0 +1,16 @@ +import ResponsiveImage from '../services/responsive-image'; +import Ember from 'ember'; + +export function initialize(/* appInstance */) { + if (typeof FastBoot === 'undefined') { + let meta = JSON.parse(Ember.$('#ember_responsive_image_meta').text()); + ResponsiveImage.reopen({ + meta + }); + } +} + +export default { + name: 'responsive-meta', + initialize +}; diff --git a/app/instance-initializers/browser/responsive-meta.js b/app/instance-initializers/responsive-meta.js similarity index 59% rename from app/instance-initializers/browser/responsive-meta.js rename to app/instance-initializers/responsive-meta.js index 00318a166..9a7f7a557 100644 --- a/app/instance-initializers/browser/responsive-meta.js +++ b/app/instance-initializers/responsive-meta.js @@ -1 +1 @@ -export { default, initialize } from 'ember-responsive-image/instance-initializers/browser/responsive-meta'; +export { default, initialize } from 'ember-responsive-image/instance-initializers/responsive-meta'; diff --git a/index.js b/index.js index 5de70bbd6..16cfc83eb 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +/*jshint node:true*/ 'use strict'; const path = require('path'); const Funnel = require('broccoli-funnel'); @@ -5,22 +6,18 @@ const Writer = require('./broccoli-image-writer'); const rimraf = require('rimraf'); const extend = require('util')._extend; const map = require('broccoli-stew').map; -const filterInitializers = require('fastboot-filter-initializers'); +const find = require('broccoli-stew').find; const mergeTrees = require('broccoli-merge-trees'); - -/*jshint node:true*/ - - function defaultConfig(env) { let defaultConfig = { - sourceDir: 'assets/images/generate', - destinationDir: 'assets/images/responsive', - quality: 80, - supportedWidths: [2048, 1536, 1080, 750, 640], - removeSourceDir: true, - justCopy: false, - extensions: ['jpg', 'jpeg', 'png', 'gif'] + sourceDir: 'assets/images/generate', + destinationDir: 'assets/images/responsive', + quality: 80, + supportedWidths: [2048, 1536, 1080, 750, 640], + removeSourceDir: true, + justCopy: false, + extensions: ['jpg', 'jpeg', 'png', 'gif'] }; //if (env !== 'production') { @@ -46,8 +43,9 @@ module.exports = { }, config(env, baseConfig) { - if (!env) + if (!env) { return; + } let config = baseConfig['responsive-image']; let url = baseConfig.rootURL || baseConfig.baseURL || ''; this.addonOptions = []; @@ -59,11 +57,7 @@ module.exports = { let extendedConfig = extend(defaultConfig(env), item); extendedConfig.rootURL = url; this.addonOptions.push(extendedConfig); - }) - }, - - preconcatTree: function(tree) { - return filterInitializers(tree, this.app.name); + }); }, resizeImages(tree, options) { @@ -101,18 +95,13 @@ module.exports = { }); let pattern = /["']__ember_responsive_image_meta__["']/; - if (process.env.EMBER_CLI_FASTBOOT) { - tree = map(tree, '**/*.js', (content, path) => { - let metaData = JSON.stringify(this.metaData); - return content.replace(pattern, metaData); - }); - } else { - tree = map(tree, '**/index.html', (content, path) => { - let metaData = JSON.stringify(this.metaData); - return content.replace(pattern, metaData); - }); - } - trees.push(tree); + let mapMeta = (content) => content.replace(pattern, JSON.stringify(this.metaData)); + + trees = trees.concat([ + map(find(tree, '**/*.js'), mapMeta), + map(find(tree, '**/index.html'), mapMeta) + ] + ); return mergeTrees(trees); } diff --git a/package.json b/package.json index f3436d200..822bb6635 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "broccoli-stew": "^1.4.0", "chalk": "^1.1.1", "ember-cli-babel": "^5.1.7", - "fastboot-filter-initializers": "^0.0.2", "fs-extra": "^0.26.5", "gm": "^1.21.1", "mkdirp": "^0.5.1", diff --git a/tests/integration/components/responsive-background-test.js b/tests/integration/components/responsive-background-test.js index d7d3cd091..d04873747 100644 --- a/tests/integration/components/responsive-background-test.js +++ b/tests/integration/components/responsive-background-test.js @@ -1,6 +1,6 @@ /* jshint expr:true */ import { expect } from 'chai'; -import { initialize } from 'ember-responsive-image/instance-initializers/browser/responsive-meta'; +import { initialize } from 'ember-responsive-image/instance-initializers/responsive-meta'; import { setupComponentTest, it diff --git a/tests/integration/components/responsive-image-test.js b/tests/integration/components/responsive-image-test.js index 43f2423f7..7a3f589c4 100644 --- a/tests/integration/components/responsive-image-test.js +++ b/tests/integration/components/responsive-image-test.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { initialize } from 'ember-responsive-image/instance-initializers/browser/responsive-meta'; +import { initialize } from 'ember-responsive-image/instance-initializers/responsive-meta'; import { setupComponentTest, it diff --git a/tests/unit/instance-initializers/browser/responsive-meta-test.js b/tests/unit/instance-initializers/responsive-meta-test.js similarity index 94% rename from tests/unit/instance-initializers/browser/responsive-meta-test.js rename to tests/unit/instance-initializers/responsive-meta-test.js index 84480c4a5..95bf48021 100644 --- a/tests/unit/instance-initializers/browser/responsive-meta-test.js +++ b/tests/unit/instance-initializers/responsive-meta-test.js @@ -6,7 +6,7 @@ import { beforeEach } from 'mocha'; import Ember from 'ember'; -import { initialize } from 'ember-responsive-image/instance-initializers/browser/responsive-meta'; +import { initialize } from 'ember-responsive-image/instance-initializers/responsive-meta'; describe('ResponsiveMetaInstanceInitializer', function() { let appInstance; diff --git a/yarn.lock b/yarn.lock index f24663908..8b2e93199 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2302,7 +2302,7 @@ fastboot-express-middleware@1.0.0-rc.7: chalk "^1.1.3" fastboot "^1.0.0-rc.3" -fastboot-filter-initializers@0.0.2, fastboot-filter-initializers@^0.0.2: +fastboot-filter-initializers@0.0.2: version "0.0.2" resolved "https://registry.yarnpkg.com/fastboot-filter-initializers/-/fastboot-filter-initializers-0.0.2.tgz#67aa9e8b22ca4b0e6a244f2450fd1cc6befa45e7" dependencies: