-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
103 lines (79 loc) · 2.43 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
'use strict';
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const VersionChecker = require('ember-cli-version-checker');
const HtmlbarsPlugin = require('./lib/htmlbars-plugin');
const DEFAULT_EMOTION_OPTIONS = {
injectMixin: true,
babel: {}
};
module.exports = {
name: require('./package').name,
init() {
this._super.init && this._super.init.apply(this, arguments);
this.checker = new VersionChecker(this);
},
/**
* Return the root of the consuming application, regardless of whether that's
* an Addon's dummy app or a real application
*/
applicationRoot() {
const root = this.project.root;
if (this.project.isEmberCLIAddon()) {
return `${root}/tests/dummy`;
}
return root;
},
appOptions() {
return (
(this.parent && this.parent.options) || (this.app && this.app.options)
);
},
emotionOptions() {
const emotion = this.appOptions().emotion;
return Object.assign({}, DEFAULT_EMOTION_OPTIONS, emotion);
},
included() {
this._super.included.apply(this, arguments);
this.import('node_modules/emotion/dist/emotion.umd.min.js', {
using: [{ transformation: 'amd', as: 'emotion-umd' }]
});
const opts = this.appOptions();
opts.babel = opts.babel || {};
opts.babel.plugins = opts.babel.plugins || [];
opts.babel.plugins.push(['emotion', this.emotionOptions().babel]);
},
treeForAddon() {
const addonTree = this._super.treeForAddon.apply(this, arguments);
if (this.emotionOptions().injectMixin) {
return new MergeTrees([addonTree, `${__dirname}/vendor`]);
}
return new Funnel(addonTree, {
exclude: [`${this.name}/extensions.js`]
});
},
/**
* Ensure that the `styles` directory's JavaScript files are in the App tree
*/
treeForApp(tree) {
const parentStylesDirectory = `${this.applicationRoot()}/app/styles`;
const styleDirectory = new Funnel(parentStylesDirectory, {
destDir: 'styles',
include: ['**/*.js']
});
return new MergeTrees([tree, styleDirectory]);
},
setupPreprocessorRegistry(type, registry) {
// Skip if we're setting up this addon's own registry
if (type !== 'parent') {
return;
}
registry.add('htmlbars-ast-plugin', {
name: 'ember-emotion',
plugin: HtmlbarsPlugin.forEmberVersion(this.checker.forEmber().version),
baseDir() {
return __dirname;
}
});
}
};