-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathindex.js
109 lines (91 loc) · 3.44 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
102
103
104
105
106
107
108
109
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
'use strict';
var path = require('path');
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
module.exports = {
name: require('./package').name,
included(app) {
this._super.included.apply(this, arguments);
app.import('node_modules/codemirror/lib/codemirror.css');
app.import('node_modules/codemirror/theme/monokai.css');
app.import('node_modules/codemirror/addon/lint/lint.css');
app.import('node_modules/jsonlint/lib/jsonlint.js');
this.includeHDSStyles(app);
this.includeFlightIcons(app);
this.includePublic(app);
this.setupSVGO(app);
},
/**
* Due to a limitation in how ember treats nested addons (see https://github.com/ember-cli/ember-cli/issues/4475)
* this is neeeded to reach down into @hashicorp/design-system-components' contentFor hook to run the logic
* that injects the sprite into the DOM
*/
contentFor(type, config) {
return this.findOwnAddonByName(
'@hashicorp/design-system-components',
).contentFor(type, config);
},
/**
* Finds the HDS styles folder and includes it into the running
* application's `sassOptions.includePaths`.
*/
includeHDSStyles(app) {
const tokensPath =
'../../node_modules/@hashicorp/design-system-tokens/dist/products/css';
const hdsPath =
'../../node_modules/@hashicorp/design-system-components/dist/styles';
// Setup default sassOptions on the running application
app.options.sassOptions = app.options.sassOptions || {};
app.options.sassOptions.includePaths =
app.options.sassOptions.includePaths || [];
// Include the addon styles
app.options.sassOptions.includePaths.push(tokensPath);
app.options.sassOptions.includePaths.push(hdsPath);
},
/**
* Finds the structure-icons folder and includes it into the
* ember-inline-svg addon.
*/
includeFlightIcons(app) {
const iconPackagePath = path.resolve(
'../../node_modules/@hashicorp/flight-icons',
);
const iconsPath = path.resolve(iconPackagePath, '..');
app.options.svg = app.options.svg || {};
app.options.svg.paths = app.options.svg.paths || [];
app.options.svg.paths.push(iconsPath);
this.addons.forEach((addon) => {
if (addon.name === 'ember-inline-svg') addon.included(app);
});
},
/**
* Finds the public folder and includes it into the ember-inline-svg addon.
*/
includePublic(app) {
const publicPath = path.resolve('public');
const dummyPublicPath = path.resolve('tests/dummy/public');
app.options.svg = app.options.svg || {};
app.options.svg.paths = app.options.svg.paths || [];
app.options.svg.paths.push(publicPath);
if (this.isDevelopingAddon()) app.options.svg.paths.push(dummyPublicPath);
this.addons.forEach((addon) => {
if (addon.name === 'ember-inline-svg') addon.included(app);
});
},
/**
* Adjust SVG optimizer defaults (used by ember-inline-svg).
* Note: Currently, there is a svgo pre-release that disables removeViewBox
* by default. So, this extra setup can be discarded once ember-inline-svg
* is updated to svgo v4.
*/
setupSVGO(app) {
app.options.svg = app.options.svg || {};
app.options.svg.optimize = app.options.svg.optimize || {};
app.options.svg.optimize.plugins = app.options.svg.optimize.plugins || [];
app.options.svg.optimize.plugins.push({ removeViewBox: false });
},
};