This repository was archived by the owner on Sep 15, 2022. It is now read-only.
forked from minutebase/ember-inline-svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (54 loc) · 1.47 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
'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: function(app) {
if (app.app) {
app = app.app;
}
this.app = app;
},
options: function() {
return merge(true, {}, {
paths: ['public'],
optimize: { /* svgo defaults */ }
}, (this.app && this.app.options && this.app.options.svg) || {});
},
svgPaths: function() {
if (this.isDevelopingAddon()) {
return ['tests/dummy/public'];
}
return this.options().paths;
},
optimizeSVGs: function(tree) {
var config = this.options().optimize;
if (!config) {
return tree;
}
return new SVGOptmizer([tree], {svgoConfig: config});
},
treeForApp: function(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]);
}
};