forked from adamlaska/coinbase-wallet-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile-assets.js
48 lines (42 loc) · 1.57 KB
/
compile-assets.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
43
44
45
46
47
48
// Copyright (c) 2018-2022 Coinbase, Inc. <https://www.coinbase.com/>
// Licensed under the Apache License, version 2.0
const fs = require("fs");
const glob = require("glob");
const sass = require("sass");
const { optimize } = require("svgo");
const COPYRIGHT = `// Copyright (c) 2018-2022 Coinbase, Inc. <https://www.coinbase.com/>
// Licensed under the Apache License, version 2.0`;
async function main() {
// compile SCSS
const scssFiles = glob.sync(`${__dirname}/src/**/*.scss`);
for (const filePath of scssFiles) {
console.log(`Compiling ${filePath}...`);
const css = sass
.renderSync({ file: filePath, outputStyle: "compressed" })
.css.toString("utf8");
const ts = `${COPYRIGHT}\n\nexport default \`${css}\``;
fs.writeFileSync(filePath.replace(/\.scss$/, "-css.ts"), ts, {
mode: 0o644
});
}
// compile SVG
const svgFiles = glob.sync(`${__dirname}/src/**/*.svg`);
for (const filePath of svgFiles) {
console.log(`Compiling ${filePath}...`);
const svg = fs.readFileSync(filePath, { encoding: "utf8" });
const { data } = optimize(svg, {
path: filePath,
datauri: "base64",
// datauri inlining won't happen until min size has been reached per
// https://github.com/svg/svgo/blob/b37d90e12a87312bba87a6c52780884e6e595e23/lib/svgo.js#L57-L68
// so we enable multipass for that to happen
multipass: true
});
const ts = `${COPYRIGHT}\n\nexport default \`${data}\``;
fs.writeFileSync(filePath.replace(/\.svg$/, "-svg.ts"), ts, {
mode: 0o644
});
}
console.log("DONE!");
}
main();