forked from miragejs/ember-cli-mirage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (50 loc) · 1.81 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
'use strict';
var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
module.exports = {
name: 'ember-cli-mirage',
included: function included(app) {
this.app = app;
this.addonConfig = this.app.project.config(app.env)['ember-cli-mirage'];
if (this._shouldIncludeFiles()) {
app.import(app.bowerDirectory + '/FakeXMLHttpRequest/fake_xml_http_request.js');
app.import(app.bowerDirectory + '/route-recognizer/dist/route-recognizer.js');
app.import(app.bowerDirectory + '/pretender/pretender.js');
app.import('vendor/ember-cli-mirage/shim.js', {
type: 'vendor',
exports: { 'pretender': ['default'] }
});
app.import(app.bowerDirectory + '/ember-inflector/ember-inflector.js');
app.import(app.bowerDirectory + '/lodash/lodash.js');
app.import(app.bowerDirectory + '/Faker/build/build/faker.js');
}
},
blueprintsPath: function() {
return path.join(__dirname, 'blueprints');
},
treeFor: function(name) {
if (this._shouldIncludeFiles()) {
return this._super.treeFor.apply(this, arguments);
}
this._requireBuildPackages();
return mergeTrees([]);
},
postprocessTree: function(type, tree) {
if(type === 'js' && !this._shouldIncludeFiles()) {
return this._excludePretenderDir(tree);
}
return tree;
},
_shouldIncludeFiles: function() {
var enabledInProd = this.app.env === 'production' && this.addonConfig.enabled;
return enabledInProd || (this.app.env !== 'production');
},
_excludePretenderDir: function(tree) {
var modulePrefix = this.app.project.config(this.app.env)['modulePrefix'];
return new Funnel(tree, {
exclude: [new RegExp('^' + modulePrefix + '/mirage/')],
description: 'Funnel: exclude mirage'
});
}
};