forked from adopted-ember-addons/ember-data-factory-guy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (59 loc) · 1.67 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
/*jshint node: true */
'use strict';
var fs = require('fs');
var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
module.exports = {
name: 'ember-data-factory-guy',
treeForVendor: function() {
var files = [];
var urijsPath = path.dirname(require.resolve('urijs'));
files.push(new Funnel(urijsPath, {
files: [
'URI.js'
],
destDir: 'urijs'
}));
return mergeTrees(files);
},
config: function (env, config) {
this.parentConfig = config;
return config;
},
includeFactoryGuyFactories: function() {
var config = this.parentConfig;
return config.environment === 'development' && config.factoryGuy;
},
treeForApp: function(appTree) {
var trees = [appTree];
if (this.includeFactoryGuyFactories()) {
try {
if (fs.statSync('tests/factories').isDirectory()) {
var factoriesTree = new Funnel('tests/factories', {
destDir: 'tests/factories'
});
trees.push(factoriesTree);
}
} catch (err) {
// do nothing;
}
}
return mergeTrees(trees);
},
included: function(app) {
this._super.included(app);
this.app = app;
// need to load mockjax in development and test environment since ember tests
// can be run from browser in development mode
if (app.tests) {
app.import(path.join(app.bowerDirectory, 'jquery-mockjax', 'dist', 'jquery.mockjax.js'));
app.import(path.join('vendor', 'urijs', 'URI.js'));
}
},
treeFor: function(name) {
if (this.app.tests) {
return this._super.treeFor.apply(this, arguments);
}
}
};