-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
120 lines (83 loc) · 1.98 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Module dependencies.
*/
var fs = require('fs')
, path = require('path');
/**
* Nodefixtures constructor.
*
*/
function Nodefixtures () {
this.Nodefixtures = {};
var Nodefixtures_tmp = {}
, Nodefixtures_path = "";
};
/**
* Reload all the Nodefixtures
*
* @api public
*/
Nodefixtures.prototype.reload = function () {
var i
, fxs = _clone(this.Nodefixtures);
for ( i in fxs ) {
if ( fxs.hasOwnProperty(i) ) {
this[i]= fxs[i];
}
};
};
/**
* Load all the Nodefixtures on path
*
* @api public
*/
Nodefixtures.prototype.load = function () {
if ( !this.Nodefixtures_path ) throw new Error('Nodefixtures path not found');
var files = fs.readdirSync(this.Nodefixtures_path);
var tmp_Nodefixtures_path = this.Nodefixtures_path;
var tmp_Nodefixtures_tmp = [];
files.forEach(function(file){
var file_name = file.replace('.js', '');
tmp_Nodefixtures_tmp[file_name] = JSON.parse(fs.readFileSync( path.join("/" + tmp_Nodefixtures_path, file), 'utf8'));
});
this.Nodefixtures = tmp_Nodefixtures_tmp;
var i
, fxs = _clone(this.Nodefixtures);
for ( i in fxs ) {
if ( fxs.hasOwnProperty(i) ) {
this[i]= fxs[i];
}
};
};
/**
* Set Nodefixtures path
*
* @param String NodefixturesPath
* @api public
*/
Nodefixtures.prototype.setPath = function (NodefixturesPath) {
var current_dir = path.join( module.parent.filename, '..');
this.Nodefixtures_path = current_dir + "/" + NodefixturesPath;
};
/**
* Deep clone of JSON Object
*
* @param {Object} param
* @return {Object}
* @api private
*/
function _clone (param) {
var result;
if (typeof param === 'undefined')
return undefined;
else if (param instanceof Array)
result = [];
else if (typeof param === 'object')
result = {};
else
return param;
for (var i in param)
result[i] = _clone(param[i]);
return result;
};
module.exports = exports = new Nodefixtures();