-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
69 lines (61 loc) · 1.91 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
'use strict';
const path = require('path');
const GenerateIcons = require('./lib/generate-icons');
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const assert = require('assert');
module.exports = {
name: require('./package').name,
imageTransformerConfig: null,
app: null,
included(app) {
this._super.included.apply(this, arguments);
if (typeof app.import !== 'function' && app.app) {
app = app.app;
}
this.app = app;
var addonOptions =
(this.parent && this.parent.options) ||
(this.app && this.app.options) ||
{};
this.imageTransformerConfig = addonOptions[this.name] || {
images: [],
};
},
treeForPublic(publicTree) {
let trees = this.imageTransformerConfig.images.map((obj) => {
this.checkProperty('inputFilename', obj);
this.checkProperty('outputFileName', obj);
this.checkProperty('convertTo', obj);
this.checkProperty('sizes', obj);
const inputPath = path.join(this.app.project.root, obj.inputFilename);
const pathData = path.parse(inputPath);
const imageNode = new Funnel(pathData.dir, {
include: [pathData.base],
});
let options = {
sizes: obj.sizes,
inputFilename: pathData.base,
outputFileName: obj.outputFileName,
project: this.app.project,
convertTo: obj.convertTo,
};
if ('background' in obj) {
options.background = obj.background;
}
const icons = new GenerateIcons(imageNode, options);
const destDir = 'destination' in obj ? obj.destination : 'assets/icons';
return new Funnel(icons, { destDir });
});
if (publicTree) {
trees.push(publicTree);
}
return new MergeTrees(trees);
},
checkProperty(property, obj) {
assert.ok(
property in obj,
`\n${this.name} error: ${property} missing from image definition\n`,
);
},
};