-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (72 loc) · 2.13 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
var defaults = require('lodash.defaults');
var checker = require('ember-cli-version-checker');
var ToJSFilter = require('broccoli-anything-to-js');
/**
* The preprocessor to register with Ember.
*
* @class
* @param {object} options The options object
*/
function ToJSPreprocessor(options) {
this.name = 'ember-cli-anything-to-js';
this.options = options || {};
}
/**
* Ember CLI add-on hook. This actually calls broccoli-anything-to-js, which does the work.
*
* @function
* @param {string,broccoliTree} tree The options object
* @param {string,broccoliTree} inputPath
* @param {string,broccoliTree} outputPath
*/
ToJSPreprocessor.prototype.toTree = function(tree, inputPath, outputPath) {
defaults(this.options, {
srcDir: inputPath,
destDir: outputPath
});
return ToJSFilter(tree, this.options);
};
module.exports = {
name: "Ember CLI Anything-To-JS Addon",
/**
* Function for checking if we need to manually run setupPreprocessorRegistry.
*
* @function
* @return {boolean} Whether we need to manually run setupPreprocessorRegistry
*/
shouldSetupRegistryInIncluded: function () {
return !checker.isAbove(this, '0.2.0');
},
/**
* Access the configuration for this plugin from the Ember CLI environment.
*
* @function
*/
getConfig: function () {
var brocfileConfig = {};
var toJSOptions = this.project.config(process.env.EMBER_ENV).toJSOptions || {};
return toJSOptions;
},
/**
* Register this as an Ember CLI preprocessor.
*
* @function
* @param {string} type
* @param {registry} registry
*/
setupPreprocessorRegistry: function(type, registry) {
var plugin = new ToJSPreprocessor(this.getConfig());
registry.add('js', plugin);
},
/**
* Ember CLI add-on hook. All this does is call setupPreprocessorRegistry if needed.
*
* @function
* @param {Ember.app} app
*/
included: function (app) {
if (this.shouldSetupRegistryInIncluded()) {
this.setupPreprocessorRegistry('parent', app.registry);
}
}
};