UNPKG

3.01 kBJavaScriptView Raw
1/* eslint-env node */
2'use strict';
3
4const path = require('path');
5const getManifestConfiguration = require('./lib/get-manifest-configuration');
6const BroccoliMergeTrees = require('broccoli-merge-trees');
7
8const MANIFEST_NAME = 'manifest.webmanifest';
9const BROWSERCONFIG_NAME = 'browserconfig.xml';
10
11module.exports = {
12 name: 'ember-web-app',
13
14 shouldIncludeChildAddon(childAddon) {
15 if (childAddon.name === 'broccoli-asset-rev') {
16 return false;
17 }
18
19 return this._super.shouldIncludeChildAddon.apply(this, arguments);
20 },
21
22 included(app) {
23 this.app = app;
24 app.options = app.options || {};
25
26 this.addonBuildConfig = this.app.options['ember-web-app'] || {};
27
28 if (!this._disabled()) {
29 this._configureFingerprint();
30 this.manifestConfiguration = getManifestConfiguration(this.app.project, this.app.env);
31 }
32
33 this._super.included.apply(this, arguments);
34 },
35
36 treeFor() {
37 if (this._disabled()) {
38 return;
39 }
40
41 return this._super.treeFor.apply(this, arguments);
42 },
43
44 treeForPublic() {
45 const configPath = path.join(this.app.project.root, 'config');
46
47 const GenerateManifest = require('./lib/broccoli/generate-manifest-json');
48 const manifest = new GenerateManifest(configPath, {
49 manifestName: MANIFEST_NAME,
50 project: this.app.project,
51 env: this.app.env,
52 ui: this.ui
53 });
54
55 const GenerateBrowserconfig = require('./lib/broccoli/generate-browserconfig-xml');
56 const browserconfig = new GenerateBrowserconfig(configPath, {
57 browserconfigName: BROWSERCONFIG_NAME,
58 project: this.app.project,
59 env: this.app.env,
60 ui: this.ui
61 });
62
63 return new BroccoliMergeTrees([manifest, browserconfig]);
64 },
65
66 contentFor(section, config) {
67 if (this._disabled()) {
68 return;
69 }
70
71 if (section === 'head') {
72 let tags = [];
73
74 tags = tags.concat(require('./lib/android-link-tags')(config, MANIFEST_NAME));
75 tags = tags.concat(require('./lib/apple-link-tags')(this.manifestConfiguration, config));
76 tags = tags.concat(require('./lib/safari-pinned-tab-tags')(this.manifestConfiguration, config));
77 tags = tags.concat(require('./lib/favicon-link-tags')(this.manifestConfiguration, config));
78
79 tags = tags.concat(require('./lib/android-meta-tags')(this.manifestConfiguration, config));
80 tags = tags.concat(require('./lib/apple-meta-tags')(this.manifestConfiguration, config));
81 tags = tags.concat(require('./lib/ms-meta-tags')(this.manifestConfiguration, config, BROWSERCONFIG_NAME));
82
83 return tags.join('\n');
84 }
85 },
86
87 _configureFingerprint() {
88 let configureFingerprint = require('./lib/configure-fingerprint');
89
90 this.app.options.fingerprint = configureFingerprint(
91 this.app.options.fingerprint, MANIFEST_NAME
92 );
93
94 this.app.options.fingerprint = configureFingerprint(
95 this.app.options.fingerprint, BROWSERCONFIG_NAME
96 );
97 },
98
99 _disabled() {
100 return this.addonBuildConfig.enabled === false;
101 }
102};