-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
49 lines (37 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* jshint node: true */
'use strict';
function readContent(name) {
var fs = require('fs');
var path = require('path');
return fs.readFileSync(path.join(process.cwd(), 'node_modules', name, 'vendor/newrelic.js'), {
encoding: 'UTF-8'
});
}
module.exports = {
name: 'ember-analytics',
contentFor: function(type, config) {
var content = '';
var newRelicConfig;
if (config.environment !== 'test' && type === 'head') {
if (!config.newRelic) {
console.warn('`config.newRelic` is not defined, using environment variables instead.');
var envLicenseKey = process.env['NEWRELIC_LICENSE_KEY'];
var envApplicationId = process.env['NEWRELIC_APPLICATION_ID'];
if (!envLicenseKey || !envApplicationId) {
console.error('Environment variables `NEWRELIC_LICENSE_KEY` and `NEWRELIC_APPLICATION_ID` are not specfied. NewRelic will not be injected.');
return content;
}
newRelicConfig = {
licenseKey: envLicenseKey,
applicationId: envApplicationId
};
} else {
newRelicConfig = config.newRelic;
}
content = readContent(this.name);
content = content.replace(/{{applicationID}}/g, newRelicConfig.applicationId);
content = content.replace(/{{licenseKey}}/g, newRelicConfig.licenseKey);
}
return content;
}
};