-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
106 lines (85 loc) · 2.68 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
/* eslint-env node */
'use strict';
const Funnel = require('broccoli-funnel');
const brocMergeTrees = require('broccoli-merge-trees');
const concat = require('broccoli-concat');
const brocSprite = require('broccoli-sprite');
const util = require('util');
module.exports = {
name: 'ember-sprite',
treeFor: treeFor,
postprocessTree: postprocessTree,
_processSprite: _processSprite,
};
function treeFor( /*inTree*/ ) {}
function getAppCSSOutputPath(options) {
let appCssOutputPath = options.outputPaths.app.css.app;
if(appCssOutputPath[0] === '/' ){
appCssOutputPath = appCssOutputPath.substr(1);
}
return appCssOutputPath;
}
function postprocessTree(type, workingTree) {
if (type === 'all' && this.app.options.sprite) {
let self = this;
// retrieves the app CSS output path
const appCssOutputPath = getAppCSSOutputPath(this.app.options);
// for backwards compatibility to previous implementation that
// passed plain object into sprite,
// we push that object into an array we can iterate through to
// process the sprite(s)
if (Object.prototype.toString.call(this.app.options.sprite) ===
'[object Object]') {
let tmp = this.app.options.sprite;
this.app.options.sprite = [];
this.app.options.sprite.push(tmp);
}
// process each of the sprites that was passed in
this.app.options.sprite.forEach(function eachSprite(sprite) {
workingTree = self._processSprite(sprite, workingTree, appCssOutputPath);
});
}
return workingTree;
}
function _processSprite(sprite, workingTree, appCssOutputPath) {
let spriteTree = new Funnel(workingTree, {
srcDir: '/',
destDir: '/',
include: [
...sprite.src
],
});
if (!!sprite.debug) {
console.log('spriteTree', util.inspect(workingTree, false, 6, true));
}
spriteTree = brocSprite(spriteTree, sprite);
workingTree = brocMergeTrees([
workingTree,
spriteTree
]);
//sprites.css is appended to app.css,
//so that two separate styles sheets do not need to get linked from index.html
let spriteCssFile = sprite.stylesheetPath;
let treeConcatCss = concat(workingTree, {
inputFiles: [
appCssOutputPath,
spriteCssFile
],
outputFile: "/" + appCssOutputPath
});
workingTree = brocMergeTrees([
workingTree,
treeConcatCss
], {
overwrite: true,
});
if (sprite.removeSrcFiles) {
workingTree = new Funnel(workingTree, {
exclude: [
spriteCssFile,
...sprite.src
]
});
}
return workingTree;
}