Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Dependency updates and decouple the addon from the rollbar library #108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ env:
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default
# - EMBER_TRY_SCENARIO=fastboot-addon-tests

matrix:
fast_finish: true
Expand Down
84 changes: 44 additions & 40 deletions app/initializers/rollbar.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
/* global Rollbar */
import Ember from 'ember';

export default {
name: 'rollbar',
initialize: function() {
var errorLogger = Ember.Logger.error;
Ember.Logger.error = function() {
var args = Array.prototype.slice.call(arguments),
err = isError(args[0]) ? args[0] : new Error(stringify(args));
const { typeOf, Logger } = Ember;

if (window.Rollbar) {
Rollbar.error.call(Rollbar, err);
}
errorLogger.apply(this, arguments);
};
var warnLogger = Ember.Logger.warn;
Ember.Logger.warn = function() {
if (window.Rollbar) {
Rollbar.warning.apply(Rollbar, arguments);
}
warnLogger.apply(this, arguments);
};
var infoLogger = Ember.Logger.info;
Ember.Logger.info = function() {
if (window.Rollbar) {
Rollbar.info.apply(Rollbar, arguments);
}
infoLogger.apply(this, arguments);
};
var debugLogger = Ember.Logger.debug;
Ember.Logger.debug = function() {
if (window.Rollbar) {
Rollbar.debug.apply(Rollbar, arguments);
}
debugLogger.apply(this, arguments);
};
}
};

var stringify = function(object){
function stringify(object) {
return JSON ? JSON.stringify(object) : object.toString();
};
}

var isError = function(object){
return Ember.typeOf(object) === 'error';
function isError(object) {
return typeOf(object) === 'error';
}

function initialize() {
let errorLogger = Logger.error;
Logger.error = function() {
let args = Array.prototype.slice.call(arguments);
let err = isError(args[0]) ? args[0] : new Error(stringify(args));

if (window.Rollbar) {
Rollbar.error.call(Rollbar, err);
}
errorLogger.apply(this, arguments);
};
let warnLogger = Logger.warn;
Logger.warn = function() {
if (window.Rollbar) {
Rollbar.warning(...arguments);
}
warnLogger.apply(this, arguments);
};
let infoLogger = Logger.info;
Logger.info = function() {
if (window.Rollbar) {
Rollbar.info(...arguments);
}
infoLogger.apply(this, arguments);
};
let debugLogger = Logger.debug;
Logger.debug = function() {
if (window.Rollbar) {
Rollbar.debug(...arguments);
}
debugLogger.apply(this, arguments);
};
}

export default {
name: 'rollbar',
initialize
};
13 changes: 13 additions & 0 deletions blueprints/ember-cli-rollbar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-env node */
/* eslint-disable object-shorthand */

module.exports = {
description: 'Default ember-cli-rollbar blueprint.',
normalizeEntityName: function() {},

afterInstall: function() {
return this.addPackagesToProject([
{ name: 'rollbar' }
]);
}
};
Empty file removed client/.gitkeep
Empty file.
3 changes: 0 additions & 3 deletions client/rollbar.js

This file was deleted.

8 changes: 8 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,13 @@ module.exports = {
devDependencies: {}
}
}
/*,
{
name: 'fastboot-addon-tests',
command: 'ember fastboot:test',
bower: {
dependencies: {}
}
}*/
]
};
14 changes: 14 additions & 0 deletions fastboot-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
extends: [
'eslint:recommended'
],
env: {
node: true,
mocha: true
}
};
12 changes: 12 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
import config from './config/environment';

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

Router.map(function() {
});

export default Router;
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>ember-fastboot-addon-tests</h1>
22 changes: 22 additions & 0 deletions fastboot-tests/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'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;

// add your real tests here
expect(response.statusCode).to.equal(200);
expect($('body').length).to.equal(1);
expect($('h1').text().trim()).to.equal('ember-fastboot-addon-tests');
});
});

});
83 changes: 45 additions & 38 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
/* eslint-env node */
/* eslint no-var: "off", object-shorthand: "off" */
/* eslint-disable object-shorthand */
'use strict';

var merge = require('lodash/merge');
var replace = require('broccoli-string-replace');
var mergeTrees = require('broccoli-merge-trees');
var path = require('path');
const fastbootTransform = require('fastboot-transform');
const mergeTrees = require('broccoli-merge-trees');
const writeFile = require('broccoli-file-creator');

module.exports = {
name: 'ember-cli-rollbar',
included: function(app) {
var config = this.project.config(this.app.env).rollbar || {};
var defaultEnabled = this.app.env !== 'development' && this.app.env !== 'test';
var enabled = config.enabled == null ? defaultEnabled : config.enabled;
if (process.env.EMBER_CLI_FASTBOOT !== 'true') {
app.import('vendor/rollbar.js', {
prepend: true
});
app.import('vendor/rollbar-module.js');
options: {
nodeAssets: {
'rollbar': function() {
return {
vendor: {
srcDir: 'dist',
include: ['*.js'],
processTree(input) {
return fastbootTransform(input);
}
}
};
}
}
},
treeForVendor: function(vt) {
var vendorTree = this._super.treeForVendor(vt);

if (process.env.EMBER_CLI_FASTBOOT !== 'true') {
var config = this.project.config(this.app.env).rollbar || {};
config = merge({
enabled: this.app.env !== 'development' && this.app.env !== 'test',
captureUncaught: true,
payload: {
environment: this.app.env
}
}, config);
var clientTree = replace(path.join(__dirname, 'client'), {
files: ['rollbar.js'],
pattern: {
match: /ROLLBAR_CONFIG/g,
replacement: JSON.stringify(config)
}
});
_getConfig() {
let env = this.app.env;
// If 'enabled' is not defined in the config, it is intelligently decided on.
// Note that this doesn't affect whether the snipped it *included*.
// It is always included, but this determines whether or not it's enabled.
let defaultEnabled = env !== 'development' && env !== 'test';
let config = this.project.config(env).rollbar || {};
config.enabled = typeof config.enabled !== 'undefined' ? config.enabled : defaultEnabled;
return config;
},

return mergeTrees([vendorTree, clientTree], {
overwrite: true
});
} else {
return vendorTree;
}
_generateConfigTree() {
return writeFile('ember-cli-rollbar/config.js', `
window._rollbarConfig = ${JSON.stringify(this._getConfig())};
`);
},

treeForVendor(tree) {
tree = mergeTrees([tree, this._generateConfigTree()]);
return this._super.treeForVendor.call(this, tree);
},

included: function(app) {
this._super.included.apply(this, arguments);

// Always include, but it may be disabled based on the configuration.
app.import('vendor/rollbar/rollbar.snippet.js', { prepend: true });
app.import('vendor/ember-cli-rollbar/config.js', { prepend: true });
app.import('vendor/rollbar-module.js');
}
};
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,37 @@
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember try:each",
"update-snippet": "tasks/update-snippet.sh"
"test": "ember try:each"
},
"dependencies": {
"broccoli-merge-trees": "^1.1.1",
"broccoli-string-replace": "^0.1.1",
"broccoli-file-creator": "^1.1.1",
"broccoli-merge-trees": "^2.0.0",
"ember-cli-babel": "^6.3.0",
"lodash": "^4.11.1"
"ember-cli-node-assets": "^0.2.2",
"fastboot-transform": "^0.1.2"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^3.0.0",
"chai": "^4.1.2",
"ember-cli": "~2.15.1",
"ember-cli-dependency-checker": "^2.0.0",
"ember-cli-eslint": "^4.0.0",
"ember-cli-htmlbars": "^2.0.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.0",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-qunit": "^4.0.0",
"ember-cli-qunit": "^4.0.1",
"ember-cli-shims": "^1.1.0",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-disable-prototype-extensions": "^1.1.2",
"ember-export-application-global": "^2.0.0",
"ember-fastboot-addon-tests": "^0.4.0",
"ember-load-initializers": "^1.0.0",
"ember-resolver": "^4.0.0",
"ember-try": "^0.2.17",
"ember-source": "~2.15.0",
"ember-welcome-page": "^3.0.0",
"loader.js": "^4.2.3"
"loader.js": "^4.2.3",
"rollbar": "^2.2.8"
},
"engines": {
"node": "^4.5 || 6.* || >= 7.*"
Expand Down
22 changes: 0 additions & 22 deletions tasks/update-snippet.sh

This file was deleted.

4 changes: 2 additions & 2 deletions vendor/rollbar-module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function() {
/* globals define, Rollbar */
/* globals define */

function generateModule(name, values) {
define(name, [], function() {
Expand All @@ -9,5 +9,5 @@
});
}

generateModule('rollbar', { 'default': Rollbar });
generateModule('rollbar', { 'default': window.Rollbar });
})();