forked from buildspace/buildspace-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapgen.js
37 lines (30 loc) · 1.1 KB
/
mapgen.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
// This script will fetch all the filenames in a directory and write them to a JSON object
const fs = require('fs');
const path = require('path');
// Set the project folder name here
const folderName = 'AI_Avatar_Generator';
const dirName = path.join(folderName, "/en/");
const outputFile = path.join(folderName, "/map.json");
const subfolders = fs.readdirSync(dirName).filter(file => fs.lstatSync(path.join(dirName, file)).isDirectory());
// Traverse through all the subfolders and fetch the filenames
const fileNames = subfolders.map(folder => {
return fs.readdirSync(path.join(dirName, folder)).map(file => {
// console.log(path.join(dirName, folder, file));
return file
});
});
// Flatten the array of arrays
const flatFiles = fileNames.reduce((acc, curr) => {
return acc.concat(curr);
}
, []);
// Make a JSON object with the filenames, filename as key an empty value
const map = flatFiles.reduce((acc, curr) => {
acc[curr] = '';
return acc;
}
, {});
// Print filenames
console.log(map);
// Write the JSON object to a file with double quotes
fs.writeFileSync(outputFile, JSON.stringify(map, null, 2));