forked from miragejs/ember-cli-mirage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (45 loc) · 1.73 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
/* jshint node: true */
'use strict';
var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
var unwatchedTree = require('broccoli-unwatched-tree');
module.exports = {
name: 'ember-cli-mirage',
included: function included(app) {
this.app = app;
this.addonConfig = this.app.project.config(app.env)['ember-cli-mirage'] || {};
this.addonBuildConfig = this.app.options['ember-cli-mirage'] || {};
this.mirageDirectory = this.addonBuildConfig['directory'] || path.join(this.app.project.root, '/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/pretender-shim.js', {
type: 'vendor',
exports: { 'pretender': ['default'] }
});
app.import(app.bowerDirectory + '/Faker/build/build/faker.js');
}
},
blueprintsPath: function() {
return path.join(__dirname, 'blueprints');
},
treeFor: function(name) {
if (!this._shouldIncludeFiles()) {
return;
}
return this._super.treeFor.apply(this, arguments);
},
treeForApp: function(name) {
var originalAppTree = unwatchedTree(path.resolve(__dirname, 'app'));
var mirageFilesTree = new Funnel(this.mirageDirectory, {
destDir: 'mirage'
});
return mergeTrees([originalAppTree, mirageFilesTree]);
},
_shouldIncludeFiles: function() {
var enabledInProd = this.app.env === 'production' && this.addonConfig.enabled;
return enabledInProd || (this.app.env !== 'production');
}
};