-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-dir.js
More file actions
32 lines (25 loc) · 935 Bytes
/
build-dir.js
File metadata and controls
32 lines (25 loc) · 935 Bytes
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
const fs = require('fs');
const path = require('path');
const dirTree = (folder, originalFolder = folder) => {
const stats = fs.lstatSync(folder);
const name = path.basename(folder);
if (name.substr(0, 1) === '.') {
return null;
}
return {
path: folder.replace(originalFolder, ''),
name: path.basename(folder),
type: stats.isDirectory() ? 'directory' : 'file',
children: stats.isDirectory() ? fs.readdirSync(folder)
.map((child) => dirTree(path.join(folder, child), originalFolder))
.filter((file) => file !== null)
: [],
};
};
module.exports = dirTree;
if (module.parent === null) {
if (!fs.existsSync(path.join(__dirname, 'assets/'))) {
fs.mkdirSync(path.join(__dirname, 'assets/'));
}
fs.writeFileSync(path.join(__dirname, 'assets/files.json'), JSON.stringify(dirTree(path.join(__dirname, 'files/'))));
}