-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
88 lines (75 loc) · 2.3 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
'use strict';
const Favicon = require('broccoli-favicon').default;
const mergeTrees = require('broccoli-merge-trees');
const deepMerge = require('lodash.merge');
let htmlCache = null;
module.exports = {
name: require('./package').name,
included(parent) {
this._super.included.apply(this, arguments);
// Set default options
let isProductionEnv = parent.env === 'production';
let defaultOptions = {
enabled: parent.env != 'test',
faviconsConfig: {
path: parent.project.config(parent.env).rootURL,
appName: parent.project.pkg.name,
appShortName: parent.project.pkg.name,
appDescription: parent.project.pkg.description,
developerName: parent.project.pkg.author,
version: parent.project.version,
icons: {
favicons: true,
android: isProductionEnv,
appleIcon: isProductionEnv,
appleStartup: isProductionEnv,
coast: isProductionEnv,
firefox: isProductionEnv,
windows: isProductionEnv,
yandex: isProductionEnv,
},
},
};
this.addonConfig = deepMerge(
{},
defaultOptions,
parent.options['ember-cli-favicon'] || {}
);
// Set success callback
let currentCallback = this.addonConfig.onSuccess || function () {};
this.addonConfig.onSuccess = function (html) {
htmlCache = html;
return currentCallback(...arguments);
};
// Support for fingerprint
parent.options.fingerprint = parent.options.fingerprint || {};
parent.options.fingerprint.exclude =
parent.options.fingerprint.exclude || [];
parent.options.fingerprint.exclude.push(
'android-chrome',
'apple-touch-icon',
'apple-touch-startup-image',
'coast',
'favicon',
'mstile',
'firefox_app',
'yandex-browser'
);
this.publicTree = parent.options.trees.public;
},
treeForPublic(tree) {
if (this.addonConfig.enabled) {
let faviconTree = new Favicon(this.publicTree, this.addonConfig);
return mergeTrees([faviconTree, tree].filter(Boolean), {
overwrite: true,
});
} else {
return tree;
}
},
contentFor(type) {
if (this.addonConfig.enabled && type === 'head-footer') {
return ' ' + (htmlCache || []).join('\n ') + '\n';
}
},
};