-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathspecs.js
More file actions
56 lines (48 loc) · 1.86 KB
/
specs.js
File metadata and controls
56 lines (48 loc) · 1.86 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var fs = require('fs');
var path = require('path');
const lodash = require("lodash");
var SupportedCultures = require('./cultures');
var supportedLanguages = lodash.keys(SupportedCultures);
var specsPath = '../../Specs';
module.exports.readAll = function (type) {
// get list of specs (.json)
var specFiles = getSpecFilePaths(path.join(__dirname, specsPath))
// Ignore specs which type is different from parameter 'type'
.filter(s => s.indexOf(path.sep + type + path.sep) !== -1)
// Ignore non-supported languages
.filter(s => supportedLanguages.find(lang => s.indexOf(path.sep + lang + path.sep) !== -1));
// invalidate require cache
specFiles.forEach(s => delete require.cache[s]);
// parse specs
return specFiles
.map(s => ({
config: getSuiteConfig(s),
specs: require(s)
}))
.reverse();
};
// helpers
function getSpecFilePaths(specsPath) {
if (!fs.existsSync(specsPath)) {
throw new Error(`Specs directory not found at ${path.resolve(specsPath)}`);
}
return fs
.readdirSync(specsPath).map(s => path.join(specsPath, s))
.filter(p => fs.lstatSync(p).isDirectory())
.map(s1 => fs.readdirSync(s1).map(s2 => path.join(s1, s2)))
.reduce((a, b) => a.concat(b), []) // flatten
.filter(p => fs.lstatSync(p).isDirectory())
.map(s1 => fs.readdirSync(s1).map(s2 => path.join(s1, s2)))
.reduce((a, b) => a.concat(b), []) // flatten
.filter(s => s.indexOf('.json') !== -1);
}
function getSuiteConfig(jsonPath) {
var parts = jsonPath.split(path.sep).slice(-3);
return {
type: parts[0],
subType: parts[2].split('.json')[0],
language: parts[1]
};
}