-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (40 loc) · 1.26 KB
/
index.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 path = require('path');
const fse = require('fs-extra');
const less = require('less');
// Source: https://gist.github.com/VinGarcia/ba278b9460500dad1f50
let walkSync = async(dir, filelist)=> {
if( dir[dir.length-1] != '/') dir=dir.concat('/')
let files = await fse.readdir(dir);
filelist = filelist || [];
for (let file of files) {
if ((await fse.stat(dir + file)).isDirectory()) {
filelist = await walkSync(dir + file + '/', filelist);
}
else {
filelist.push(dir+file);
}
}
return filelist;
};
(async()=> {
let files = await walkSync('./indices');
for (let file of files) {
let p = path.parse(file);
if(p.ext != ".less") continue;
let src = `${p.dir}/${p.base}`;
let lessFile = await less.render((await fse.readFile(src)).toString(), {filename: src});
await fse.writeFile(`${p.dir}/${p.name}.css`, lessFile.css, {flag:'w'});
}
})()
.then(async()=> {
let imports = [
'./node_modules/jquery/dist/jquery.min.js'
];
let destination = "./indices/importedScripts";
for(let i of imports) {
await fse.copy(i, `${destination}/${path.parse(i).base}`, {overwrite: true});
}
})
.catch((error)=> {
console.log(error);
});