-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (93 loc) · 3.12 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
'use strict';
var fs = require('fs');
const path = require('path');
const resolve = require('resolve');
const Funnel = require('broccoli-funnel');
const BroccoliMergeTrees = require('broccoli-merge-trees');
const os = require('os');
const 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: require('./package').name,
treeForAddonStyles() {
const tree = this._super.treeForStyles.apply(this, arguments);
const trees = tree ? [tree]: []
const paceThemeName = path.join(this.emberPaceConfig.color, 'pace-theme-' + this.emberPaceConfig.theme + '.css');
const emberPaceThemeFile = path.join('themes', paceThemeName);
const fullThemeFilePath = path.join(this.pathBase('pace-progressbar'), emberPaceThemeFile);
let isWin = process.platform === 'win32';
if (fs.existsSync(fullThemeFilePath)) {
if (isWin) {
let basePath = path.join(this.pathBase('pace-progressbar'), 'themes');
basePath = path.join(basePath, this.emberPaceConfig.color);
const tmpFolderPath = path.join(os.tmpdir(), 'ember_pace_');
let tmpFolder = '';
fs.mkdtemp(tmpFolderPath, (err, folder) => {
if (err) throw err;
tmpFolder = folder;
});
const emberPaceCssFiles = new Funnel(basePath, {
files: ['pace-theme-' + this.emberPaceConfig.theme + '.css'],
destDir: path.join(tmpFolder, 'styles'),
annotation: 'EmberPaceThemeFunnel'
});
trees.push(emberPaceCssFiles);
const mergedTrees = new BroccoliMergeTrees(trees, { overwrite: true });
return mergedTrees;
} else {
const emberPaceCssFiles = new Funnel(this.pathBase('pace-progressbar'), {
files: [emberPaceThemeFile],
destDir: 'app/styles',
annotation: 'EmberPaceThemeFunnel'
});
trees.push(emberPaceCssFiles);
const mergedTrees = new BroccoliMergeTrees(trees, { overwrite: true });
return mergedTrees;
}
}
throw new Error('Pace theme CSS file was not found: ' + paceThemeName);
},
config(environment, appConfig) {
const appPaceConfig = appConfig.pace || {};
const emberPaceConfig = Object.keys(
defaultPaceConfig
).reduce(function(config, key) {
const value = appPaceConfig.hasOwnProperty(key) ? appPaceConfig[key] : defaultPaceConfig[key];
config[key] = value;
return config;
}, {});
this.emberPaceConfig = emberPaceConfig;
return {
'pace': emberPaceConfig
};
},
pathBase(packageName) {
return path.dirname(resolve.sync(`${packageName}/package.json`, { basedir: __dirname }));
},
};