-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
41 lines (34 loc) · 1.32 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
/* eslint-env node */
'use strict';
var path = require('path');
var fs = require('fs');
var Funnel = require('broccoli-funnel');
var map = require('broccoli-stew').map;
var mergeTrees = require('broccoli-merge-trees');
var A2H_ASSET_PATH = path.join(require.resolve('add-to-homescreen'), '..', '..');
var A2H_JS_PATH = A2H_ASSET_PATH;
var A2H_CSS_PATH = path.join(A2H_ASSET_PATH, 'dist', 'style');
var A2H_JS_FILES = ['addtohomescreen.js'];
var A2H_CSS_FILES = ['addtohomescreen.css'];
function notInFastboot(tree) {
return map(tree, (content) => `if (typeof FastBoot === 'undefined') { ${content} }`);
}
module.exports = {
name: 'ember-add-to-homescreen',
included: function (app) {
this._super.included(app);
app.import('vendor/addtohomescreen.js');
app.import('vendor/addtohomescreen.css');
},
treeForVendor: function (defaultTree) {
var trees = defaultTree ? [defaultTree] : [];
if (fs.existsSync(A2H_ASSET_PATH)) {
var browserHomeScreenJS = notInFastboot(new Funnel(A2H_JS_PATH, { files: A2H_JS_FILES }));
var browserHomeScreenCSS = new Funnel(A2H_CSS_PATH, { files: A2H_CSS_FILES });
trees = trees.concat([browserHomeScreenJS, browserHomeScreenCSS]);
return new mergeTrees(trees);
} else {
throw new Error('add-to-homescreen was not found at ' + A2H_ASSET_PATH);
}
}
};