-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.js
74 lines (61 loc) · 1.46 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
'use strict';
var fs = require('fs');
var merge = require('merge');
var mergeTrees = require('broccoli-merge-trees');
var flatiron = require('broccoli-flatiron');
var Funnel = require('broccoli-funnel');
var SVGOptmizer = require('./svg-optimizer');
module.exports = {
name: require('./package').name,
included(app) {
if (app.app) {
app = app.app;
}
this.app = app;
},
options() {
return merge(
true,
{},
{
paths: ['public'],
optimize: {
/* svgo defaults */
},
},
(this.app && this.app.options && this.app.options.svg) || {}
);
},
svgPaths() {
if (this.isDevelopingAddon()) {
return ['tests/dummy/public'];
}
return this.options().paths;
},
optimizeSVGs(tree) {
var config = this.options().optimize;
if (!config) {
return tree;
}
return new SVGOptmizer([tree], { svgoConfig: config });
},
treeForApp(tree) {
var existingPaths = this.svgPaths().filter(function (path) {
return fs.existsSync(path);
});
var svgTrees = existingPaths.map(function (path) {
return new Funnel(path, {
include: [new RegExp(/\.svg$/)],
});
});
var svgs = mergeTrees(svgTrees, {
overwrite: true,
});
var optimized = this.optimizeSVGs(svgs);
var manifest = flatiron(optimized, {
outputFile: 'svgs.js',
trimExtensions: true,
});
return mergeTrees([tree, manifest]);
},
};