forked from etienne-martin/device-detector-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
41 lines (30 loc) · 1.05 KB
/
install.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
const path = require("path");
const fs = require("fs");
const YAML = require("js-yaml");
const recursive = require("recursive-readdir");
const loadYaml = (slug) => {
return YAML.load(fs.readFileSync(slug, "utf8"), {
schema: YAML.FAILSAFE_SCHEMA
});
};
const ignoreFilter = (file, stats) => {
if (stats.isDirectory()) return false;
return !(stats.isFile() && path.extname(file) === ".yml");
};
const ensureDirectoryExistence = (filePath) => {
const dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
};
// Ignore files named "foo.cs" and descendants of directories named test
recursive("./node_modules/device-detector", [ignoreFilter], (err, files) => {
for (const file of files) {
let destination = file.replace(RegExp(".yml$", "i"), ".json");
destination = destination.replace("node_modules/device-detector", "fixtures");
ensureDirectoryExistence(destination);
fs.writeFileSync(destination, JSON.stringify(loadYaml(file)));
}
});