-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathget_mock_list.js
36 lines (30 loc) · 965 Bytes
/
get_mock_list.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
var path = require('path');
var glob = require('glob');
var constants = require('../../../tasks/util/constants');
/**
* Return array of mock name corresponding to input glob pattern
*
* @param {array} _ : argv._ from minimist
* @return {array}
*/
module.exports = function getMockList(_) {
if(_.length === 0) {
return fromPattern('*');
} else {
return _
.map(String)
.map(fromPattern)
.reduce(function(a, b) { return a.concat(b); });
}
};
function fromPattern(pattern) {
// defaults to '.json' ext is none is provided
if(path.extname(pattern) === '') pattern += '.json';
var patternFull = path.join(constants.pathToTestImageMocks, pattern);
var matches = glob.sync(patternFull);
// return only the mock name (not a full path, no ext)
var mockNames = matches.map(function(match) {
return path.basename(match).split('.')[0];
});
return mockNames;
}