-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathload-fixtures.js
36 lines (27 loc) · 886 Bytes
/
load-fixtures.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
const path = require("path");
const fs = require("fs");
const YAML = require("js-yaml");
const glob = require("glob");
const loadYaml = (filepath) => {
return YAML.load(fs.readFileSync(filepath, "utf8"), {
schema: YAML.FAILSAFE_SCHEMA
});
};
const ensureDirectoryExistence = (filePath) => {
const dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) return;
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
};
glob("**/*.yml", {
cwd: "./node_modules/device-detector/"
}, (err, files) => {
for (const file of files) {
const src = path.join("./node_modules/device-detector", file);
const dest = path.join("./src/fixtures", file.replace(RegExp(".yml$", "i"), ".json"));
ensureDirectoryExistence(dest);
const fixture = loadYaml(src);
const json = JSON.stringify(fixture, null, 2);
fs.writeFileSync(dest, json);
}
});