forked from husker-dev/web-ios-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compileScript.js
39 lines (31 loc) · 964 Bytes
/
compileScript.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
const fs = require('fs');
const path = require('path');
const sass = require('sass');
const uglifyjs = require("uglify-js");
const outPath = "./out/";
function walkTree(dir) {
return fs.readdirSync(dir, { withFileTypes: true })
.flatMap(file => file.isDirectory() ? walkTree(path.join(dir, file.name)) : path.join(dir, file.name))
}
function compileSass(path){
return sass.compile(path).css.toString();
}
let fullJS = "";
let fullCSS = "";
let minJS = "";
walkTree("./src").forEach(e => {
const data = fs.readFileSync(e, 'utf8') + "\n";
if(e.endsWith(".js")){
fullJS += data;
minJS += uglifyjs.minify(data).code;
}
if(e.endsWith(".css"))
fullCSS += data;
if(e.endsWith(".scss"))
fullCSS += compileSass(e);
});
if (!fs.existsSync(outPath))
fs.mkdirSync(outPath);
fs.writeFileSync(`${outPath}/web-ios-app.js`, fullJS);
fs.writeFileSync(`${outPath}/web-ios-app.css`, fullCSS);
fs.writeFileSync(`${outPath}/web-ios-app.min.js`, minJS);