-
Notifications
You must be signed in to change notification settings - Fork 30
/
index.js
103 lines (91 loc) · 2.85 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* jshint node: true */
'use strict';
var fs = require('fs');
var path = require('path');
var UglifyJS = require("uglify-js");
var PACE_DIR = 'PACE';
var _paceConfig = {};
var _defaultPaceConfig = {
color: 'blue',
theme: 'minimal',
catchupTime: 50,
initialRate: 0.01,
minTime: 100,
ghostTime: 50,
maxProgressPerFrame: 20,
easeFactor: 1.25,
startOnPageLoad: true,
restartOnPushState: true,
restartOnRequestAfter: 500,
target: 'body',
elements: {
checkInterval: 100,
selectors: ['body', '.ember-view']
},
eventLag: {
minSamples: 10,
sampleCount: 3,
lagThreshold: 3
},
ajax: {
trackMethods: ['GET', 'POST', 'DELETE', 'OPTIONS'],
trackWebSockets: true,
ignoreURLs: []
}
};
module.exports = {
name: 'ember-cli-pace',
config: function (environment, baseConfig) {
if ('pace' in baseConfig) {
if (!baseConfig.pace) {
_paceConfig = false;
} else {
Object.keys(_defaultPaceConfig).forEach(function (key) {
_paceConfig[key] = baseConfig.pace.hasOwnProperty(key) ? baseConfig.pace[key] : _defaultPaceConfig[key];
});
}
} else {
_paceConfig = _defaultPaceConfig;
}
if (environment === 'development') {
return {
pace: _paceConfig,
contentSecurityPolicy: {
'script-src': "'self' 'unsafe-eval' 'unsafe-inline'"
}
};
}
return {
pace: _paceConfig
};
},
treeFor: function (name) {
if (_paceConfig && name === 'styles') {
var paceThemeName = path.join(_paceConfig.color, 'pace-theme-' _paceConfig.theme '.css'),
originalPaceThemePath = path.join(this.app.bowerDirectory, PACE_DIR, 'themes', paceThemeName),
addonPaceThemePath = path.join('vendor', 'ember-cli-pace', 'themes', paceThemeName);
if (fs.existsSync(originalPaceThemePath)) {
this.app.import(originalPaceThemePath);
} else if (fs.existsSync(addonPaceThemePath)) {
this.app.import(addonPaceThemePath);
} else {
throw new Error('Pace theme CSS file was not found: ' paceThemeName);
}
}
},
contentFor: function (name) {
if (_paceConfig && name === 'head') {
var paceScriptPath = path.join(this.app.bowerDirectory, PACE_DIR, 'pace.js'),
addonScriptPath = path.resolve(__dirname, 'vendor', 'ember-cli-pace', 'script-loader.js'),
paceScript, addonScript;
if (this.app.env === 'production') {
paceScript = UglifyJS.minify(paceScriptPath).code;
addonScript = UglifyJS.minify(addonScriptPath).code;
} else {
paceScript = fs.readFileSync(paceScriptPath, 'utf8');
addonScript = fs.readFileSync(addonScriptPath, 'utf8');
}
return '<script type="text/javascript" data-pace-options=\'' JSON.stringify(_paceConfig) '\'>' paceScript ';\n' addonScript '</script>';
}
}
};