Skip to content

Commit

Permalink
Merge pull request #18 from kaliber5/prepare-fastboot-1.0
Browse files Browse the repository at this point in the history
Prepare for upcoming breaking changes in FastBoot 1.0
  • Loading branch information
Andreas Schacht authored Apr 18, 2017
2 parents 9ce780f + 409163f commit 1648ade
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
language: node_js
node_js:
- "4"
- "6"

sudo: false

Expand Down
14 changes: 0 additions & 14 deletions addon/instance-initializers/browser/responsive-meta.js

This file was deleted.

16 changes: 16 additions & 0 deletions addon/instance-initializers/responsive-meta.js
Original file line number Diff line number Diff line change
@@ -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
};
Original file line number Diff line number Diff line change
@@ -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';
49 changes: 19 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
/*jshint node:true*/
'use strict';
const path = require('path');
const Funnel = require('broccoli-funnel');
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') {
Expand All @@ -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 = [];
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/responsive-background-test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/responsive-image-test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ [email protected]:
chalk "^1.1.3"
fastboot "^1.0.0-rc.3"

[email protected], fastboot-filter-initializers@^0.0.2:
[email protected]:
version "0.0.2"
resolved "https://registry.yarnpkg.com/fastboot-filter-initializers/-/fastboot-filter-initializers-0.0.2.tgz#67aa9e8b22ca4b0e6a244f2450fd1cc6befa45e7"
dependencies:
Expand Down

0 comments on commit 1648ade

Please sign in to comment.