forked from DanKottke/midas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-theme.js
42 lines (37 loc) · 1017 Bytes
/
import-theme.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
42
const fse = require('fs-extra');
/* Initialize arguments
0 = node
1 = import-theme.js
2 = [SOURCE]
*/
const SOURCE = process.argv[2] || '_theme';
// True to include, False to exclude
const filterFunc = (src, dest) => {
if(fileExclusions.includes(src)) return false;
if(directoryExclusions.map((exclusion) => {
return src.match(exclusion);
}).reduce((a, b) => {
return a || b;
}, 0)) return false;
return true;
};
var fileExclusions = [];
var directoryExclusions = [];
// Look for and read from exclude.txt
fse.readFile('exclude.txt').then((contents) => {
var exclusions = contents.toString().split('\n');
exclusions.map((exclusion) => {
if(exclusion.endsWith('*'))
directoryExclusions.push(exclusion);
else
fileExclusions.push(exclusion);
});
}).catch((error) => {
console.warn(error);
});
// Copy source directory
fse.copy(SOURCE, '.', { filter: filterFunc }).then(() => {
console.log('Theme import succeeded.');
}).catch(err => {
console.error(err);
});