Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for FastBoot 1.0 #21

Merged
merged 7 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ env:
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default
- EMBER_TRY_SCENARIO=fastboot
- EMBER_TRY_SCENARIO=fastboot-ember-2.9

matrix:
fast_finish: true
Expand All @@ -25,9 +27,10 @@ matrix:
before_install:
- npm config set spin false
- export PATH=$HOME/.yarn/bin:$PATH
- yarn global add phantomjs-prebuilt
- yarn global add phantomjs-prebuilt bower
- npm --version
- yarn --version
- bower --version
- phantomjs --version

install:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ember from 'ember';
import ENV from '../../config/environment';
import ENV from '../config/environment';

export function initialize(instance) {
if (ENV['ember-cli-head'] && ENV['ember-cli-head']['suppressBrowserRender']) { return true; }
Expand All @@ -17,5 +17,9 @@ export function initialize(instance) {

export default {
name: 'head-browser',
initialize: initialize
initialize() {
if (typeof FastBoot === 'undefined') {
initialize(...arguments);
}
}
};
2 changes: 1 addition & 1 deletion app/instance-initializers/fastboot/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export function initialize(owner) {

export default {
name: 'head-fastboot',
initialize: initialize
initialize
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ember from 'ember';
import ENV from '../../config/environment';
import ENV from '../config/environment';

export function initialize(owner) {
if (ENV['ember-cli-head'] && ENV['ember-cli-head']['suppressBrowserRender']) { return true; }
Expand All @@ -16,5 +16,9 @@ export function initialize(owner) {

export default {
name: 'head-browser',
initialize: initialize
initialize() {
if (typeof FastBoot === 'undefined') {
initialize(...arguments);
}
}
};
18 changes: 18 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ module.exports = {
npm: {
devDependencies: {}
}
},
{
name: 'fastboot',
command: 'ember fastboot:test',
npm: {
devDependencies: {
'ember-source': null
}
}
},
{
name: 'fastboot-ember-2.9',
command: 'ember fastboot:test --ember-version 2.9.0',
npm: {
devDependencies: {
'ember-source': null
}
}
}
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export function initialize(instance) {

export default {
name: 'head-fastboot',
initialize: initialize

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initialize function needs to be wrapped in a if (typeof FastBoot != 'undefined') {...} check to make sure ember-cli-head works in apps without ember-cli-fastboot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had a look at it again... I think this is not needed, as this is not part of app

And the ember 2.4 test scenario seems to be ok!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Missed the filterInitializers again 👍

initialize
};
36 changes: 36 additions & 0 deletions fastboot-tests/fastboot-1.0-beta-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const expect = require('chai').expect;
const setupTest = require('ember-fastboot-addon-tests').setupTest;

describe('FastBoot pre 1.0', function() {
setupTest('fastboot-beta', {
emberCliFastbootVersion: '1.0.0-beta.18'
}
);

it('index page', function() {
return this.visit('/')
.then(function(res) {
let $ = res.jQuery;
let response = res.response;

expect(response.statusCode).to.equal(200);
expect($('h1').text().trim()).to.equal('Hello page');
expect($('meta[property="og:title"]', 'head').attr('content')).to.equal('Hello page');
});
});

it('other page', function() {
return this.visit('/other-page')
.then(function(res) {
let $ = res.jQuery;
let response = res.response;

expect(response.statusCode).to.equal(200);
expect($('h1').text().trim()).to.equal('Other page');
expect($('meta[property="og:title"]', 'head').attr('content')).to.equal('Other page');
});
});

});
35 changes: 35 additions & 0 deletions fastboot-tests/fastboot-1.0-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const expect = require('chai').expect;
const setupTest = require('ember-fastboot-addon-tests').setupTest;

describe('FastBoot 1.0', function() {
setupTest('fastboot', {
emberCliFastbootVersion: '1.0.0-rc.1'
});

it('index page', function() {
return this.visit('/')
.then(function(res) {
let $ = res.jQuery;
let response = res.response;

expect(response.statusCode).to.equal(200);
expect($('h1').text().trim()).to.equal('Hello page');
expect($('meta[property="og:title"]', 'head').attr('content')).to.equal('Hello page');
});
});

it('other page', function() {
return this.visit('/other-page')
.then(function(res) {
let $ = res.jQuery;
let response = res.response;

expect(response.statusCode).to.equal(200);
expect($('h1').text().trim()).to.equal('Other page');
expect($('meta[property="og:title"]', 'head').attr('content')).to.equal('Other page');
});
});

});
13 changes: 13 additions & 0 deletions fastboot-tests/fixtures/fastboot-beta/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
this.route('other-page');
});

export default Router;
10 changes: 10 additions & 0 deletions fastboot-tests/fixtures/fastboot-beta/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Ember from 'ember';

const { set } = Ember;

export default Ember.Route.extend({
headData: Ember.inject.service(),
afterModel() {
set(this, 'headData.title', "Hello page");
}
});
10 changes: 10 additions & 0 deletions fastboot-tests/fixtures/fastboot-beta/app/routes/other-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Ember from 'ember';

const { set } = Ember;

export default Ember.Route.extend({
headData: Ember.inject.service(),
afterModel() {
set(this, 'headData.title', "Other page");
}
});
5 changes: 5 additions & 0 deletions fastboot-tests/fixtures/fastboot-beta/app/templates/head.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Add content you wish automatically added to the documents head-->
<!-- here. The 'model' available in this template can be populated by-->
<!-- setting values on the 'head-data' service. -->

<meta property="og:title" content={{model.title}} />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello page</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Other page</h1>
13 changes: 13 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
this.route('other-page');
});

export default Router;
10 changes: 10 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Ember from 'ember';

const { set } = Ember;

export default Ember.Route.extend({
headData: Ember.inject.service(),
afterModel() {
set(this, 'headData.title', "Hello page");
}
});
10 changes: 10 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/routes/other-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Ember from 'ember';

const { set } = Ember;

export default Ember.Route.extend({
headData: Ember.inject.service(),
afterModel() {
set(this, 'headData.title', "Other page");
}
});
5 changes: 5 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/templates/head.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Add content you wish automatically added to the documents head-->
<!-- here. The 'model' available in this template can be populated by-->
<!-- setting values on the 'head-data' service. -->

<meta property="og:title" content={{model.title}} />
1 change: 1 addition & 0 deletions fastboot-tests/fixtures/fastboot/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello page</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Other page</h1>
55 changes: 39 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
/* eslint-env node */
'use strict';

var path = require('path');
var filterInitializers = require('fastboot-filter-initializers');
var VersionChecker = require('ember-cli-version-checker');
var mergeTrees = require('broccoli-merge-trees');
const path = require('path');
const filterInitializers = require('fastboot-filter-initializers');
const VersionChecker = require('ember-cli-version-checker');
const mergeTrees = require('broccoli-merge-trees');

module.exports = {
name: 'ember-cli-head',

treeForApp: function(defaultTree) {
var checker = new VersionChecker(this);
var emberVersion = checker.for('ember-source', 'npm');
treeForApp(defaultTree) {
if (!process.env.FASTBOOT_NEW_BUILD) {
let trees = [defaultTree];

if (!this.hasGlimmer2()) {
trees.push(this.treeGenerator(path.resolve(this.root, 'app-lt-2-10')));
trees.push(this.treeGenerator(path.resolve(this.root, 'fastboot-lt-2-10')));
}

let tree = mergeTrees(trees, { overwrite: true });

return filterInitializers(tree);
} else {
let trees = [defaultTree];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you do this in treeForFastBoot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's just for the browser. That's covering the new FastBoot, but with an pre 2.10 ember, where we need to merge the app-lt-2-10 browser initializer!

if (!this.hasGlimmer2()) {
trees.push(this.treeGenerator(path.resolve(this.root, 'app-lt-2-10')));
}

return mergeTrees(trees, { overwrite: true });
}
},

treeForFastBoot(tree) {
// this hook will be invoked in post FastBoot 1.0
if (!this.hasGlimmer2) {
let fastBootHtmlBarsTree = this.treeGenerator(path.resolve(this.root, 'fastboot-lt-2-10'));
return tree ? mergeTrees([tree, fastBootHtmlBarsTree], { overwrite: true }) : fastBootHtmlBarsTree;
}
return tree;
},

hasGlimmer2() {
let checker = new VersionChecker(this);
let emberVersion = checker.for('ember-source', 'npm');

if (!emberVersion.version) {
emberVersion = checker.for('ember', 'bower');
}

var trees = [defaultTree];

// 2.9.0-beta.1 - 2.9.0-beta.5 used glimmer2 (but 2.9.0 did not)
// 2.10.0-beta.1+ includes glimmer2
if (!(emberVersion.gt('2.9.0-beta') && emberVersion.lt('2.9.0')) && !emberVersion.gt('2.10.0-beta')) {
trees.push(this.treeGenerator(path.resolve(this.root, 'app-lt-2-10')));
}

var tree = mergeTrees(trees, { overwrite: true });

return filterInitializers(tree);
return (emberVersion.gt('2.9.0-beta') && emberVersion.lt('2.9.0')) || emberVersion.gt('2.10.0-beta');
}
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"chai": "^3.5.0",
"ember-ajax": "^2.4.1",
"ember-cli": "2.12.2",
"ember-cli-app-version": "^1.0.0",
Expand All @@ -36,6 +37,7 @@
"ember-disable-prototype-extensions": "^1.1.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.5",
"ember-fastboot-addon-tests": "^0.4.0",
"ember-load-initializers": "^0.6.0",
"ember-resolver": "^2.0.3",
"ember-source": "~2.12.0",
Expand All @@ -49,7 +51,7 @@
"ember-cli-babel": "^6.0.0",
"ember-cli-htmlbars": "^1.3.0",
"ember-cli-version-checker": "^1.1.6",
"fastboot-filter-initializers": "0.0.1"
"fastboot-filter-initializers": "^0.0.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caret here does nothing, we should bump to 0.1.0 (upstream) so that we can use caret deps...

},
"engines": {
"node": ">= 4"
Expand Down
Loading