Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
82 lines (68 loc) · 2.22 KB
/
Copy pathindex.js
File metadata and controls
82 lines (68 loc) · 2.22 KB
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
'use strict';
var merge = require('merge');
var makeArray = require('make-array');
var SVGStore = require('broccoli-misvg');
var UnwatchedTree = require('broccoli-unwatched-tree');
var Funnel = require('broccoli-funnel');
var MergeTrees = require('broccoli-merge-trees');
module.exports = {
name: 'ember-cli-misvg',
options: function() {
return this._options = this._options || merge(true, {}, {
files: []
}, this.app.options.misvg || {});
},
treeForPublic: function() {
var options = this.options();
var trees = this._makeSvgTrees(options.files, options.misvgOptions);
return this._maybeMerge(trees, 'output');
},
// Remove sprite files from the dist if they originate in the `/public` dir
postprocessTree: function(type, tree) {
if (type !== 'all') {
return tree;
}
var options = this.options();
var globalExclude = options.excludeSourceFiles;
var excludeGlobs = makeArray(this.options().files).reduce(function(result, fileSpec) {
var paths = [];
// Remove only if the `excludeSourceFiles` option is set
if (globalExclude || fileSpec.excludeSourceFiles) {
paths = makeArray(fileSpec.sourceDirs).filter(function(dir) {
return dir.match(/^public\//);
}).map(function(dir) {
return dir.replace(/^public\//, '') + '/*';
});
}
return result.concat(paths);
}, []);
if (excludeGlobs.length) {
tree = new Funnel(tree, {
exclude: excludeGlobs
});
}
return tree;
},
_makeSvgTrees: function(files, misvgOptions) {
return makeArray(files).map(function(fileSpec) {
return new SVGStore(this._makeSourceTree(fileSpec), {
outputFile: fileSpec.outputFile,
misvgOptions: misvgOptions
});
}, this);
},
_makeSourceTree: function(fileSpec) {
var inputs = makeArray(fileSpec.sourceDirs).map(UnwatchedTree);
return this._maybeMerge(inputs, 'sources: ' + fileSpec.outputFile);
},
_maybeMerge: function(trees, description) {
trees = makeArray(trees);
if (trees.length === 1) {
return trees[0];
} else {
return new MergeTrees(trees, {
description: 'TreeMerger (SVGStore ' + description + ')'
});
}
}
};