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 2 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
2 changes: 2 additions & 0 deletions .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 Down
6 changes: 5 additions & 1 deletion app-lt-2-10/instance-initializers/fastboot/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ export function initialize(instance) {

export default {
name: 'head-fastboot',
initialize: initialize
initialize() {
if (typeof FastBoot !== 'undefined') {
initialize(...arguments);
}
}
};
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);
}
}
};
6 changes: 5 additions & 1 deletion app/instance-initializers/fastboot/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ export function initialize(owner) {

export default {
name: 'head-fastboot',
initialize: initialize
initialize() {
if (typeof FastBoot !== 'undefined') {
initialize(...arguments);
}
}
};
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
}
}
}
]
};
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>
21 changes: 21 additions & 0 deletions fastboot-tests/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

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

describe('index', function() {
setupTest('fastboot'/*, options */);

it('renders', 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');
});
});

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

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

describe('otherPage', function() {
setupTest('fastboot'/*, options */);

it('renders', 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');
});
});

});
19 changes: 8 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
/* 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 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) {
let checker = new VersionChecker(this);
Copy link

@kratiahuja kratiahuja Apr 27, 2017

Choose a reason for hiding this comment

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

My PR exposes a process environment process.env.FASTBOOT_NEW_BUILD and addToFastBootTree for these cases. Instead of merging here you can just do this:

Let me know if this doesn't work or you feel this may not be needed but I exposed those hooks in my PR to have this in mind. More than happy to drop code 😄

treeForApp(defaultTree) {
  if (!process.env.FASTBOOT_NEW_BUILD) {
      var 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);
  } else {
     return defaultTree;
 }
}

addToFastBootTree() {
  // this hook will be invoked in post fastboot 1.0 (after my PR is merged)
  var fastbootBuilder = require('ember-cli-fastboot/lib/build-utilities/fastboot-builder');
  
  let checker = new VersionChecker(this);
  let emberVersion = checker.for('ember-source', 'npm');
 
  if (!emberVersion.version) {
     emberVersion = checker.for('ember', 'bower');
   }

  // 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')) {
      return fastbootBuilder.addFastBootPath(path.resolve(this.root, 'fastboot-app-lt-2-9'));
    }
}

When FastBoot 1.0 is released, we can remove treeForApp.

let emberVersion = checker.for('ember-source', 'npm');

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

var trees = [defaultTree];
let 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 mergeTrees(trees, { overwrite: true });
}
};
5 changes: 3 additions & 2 deletions 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.3.1",
"ember-load-initializers": "^0.6.0",
"ember-resolver": "^2.0.3",
"ember-source": "~2.12.0",
Expand All @@ -48,8 +50,7 @@
"broccoli-merge-trees": "^1.1.4",
"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"
"ember-cli-version-checker": "^1.1.6"
},
"engines": {
"node": ">= 4"
Expand Down
Loading