-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathasset-map.js
48 lines (42 loc) · 1.12 KB
/
asset-map.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
import RSVP from 'rsvp';
import AssetMap from '../services/asset-map';
import { typeOf as getTypeOf } from '@ember/utils';
import getAssetMapData from 'ember-cli-ifa/utils/get-asset-map-data';
export function initialize(app) {
let assetMapFile = getAssetMapData();
if (!assetMapFile) {
app.register('service:asset-map', AssetMap);
return;
}
if (getTypeOf(assetMapFile) === 'object' && assetMapFile.assets) {
AssetMap.reopen({
map: assetMapFile.assets,
prepend: assetMapFile.prepend,
enabled: true
});
app.register('service:asset-map', AssetMap);
} else {
app.deferReadiness();
const promise = fetch(assetMapFile).then(response => response.json());
promise.then((map = {}) => {
AssetMap.reopen({
map: map.assets,
prepend: map.prepend,
enabled: true
});
})
.then(() => {
app.register('service:asset-map', AssetMap);
})
.catch((err) => {
console.error('Failed to register service:asset-map', err);
})
.finally(() => {
app.advanceReadiness();
});
}
}
export default {
name: 'asset-map',
initialize
};