-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflattenIcons.js
36 lines (33 loc) · 1.06 KB
/
flattenIcons.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 {readdir, copy, lstatSync} = require('fs-extra');
const iconsPath = __dirname + '/assets/icons';
const listFilesRecursive = ({folderPath, filePaths = []}) => {
return readdir(folderPath)
.then(files => {
return files.reduce((cur, file) =>
cur
.then(() => {
const thatPath = `${folderPath}/${file}`;
const isFolder = lstatSync(thatPath).isDirectory();
if (isFolder) {
return listFilesRecursive({folderPath: thatPath, filePaths})
} else {
filePaths.push(thatPath);
return Promise.resolve({filePaths})
}
})
, Promise.resolve())
})
}
listFilesRecursive({folderPath: iconsPath})
.then(({filePaths}) => {
return filePaths.reduce((curr, input) =>
curr.then(() => {
const fileName = input.split('/').pop();
const output = `${iconsPath}/${fileName}`;
if (input !== output) {
return copy(input, output)
} else return Promise.resolve();
})
, Promise.resolve())
})
.catch(console.error);