-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-assets.js
40 lines (36 loc) · 1.03 KB
/
create-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
import { config } from "./src/lib/config.js";
import https from "https";
import fs from "fs";
const download = (url, dest, successCb, errorCb) => {
const file = fs.createWriteStream(dest);
https
.get(url, (response) => {
response.pipe(file);
file.on("finish", () => {
file.close(successCb);
});
})
.on("error", (err) => {
if (errorCb) errorCb(err.message);
});
};
const downloadAsPromise = (url, localDestination) => {
return new Promise((resolve, reject) => {
download(
url,
localDestination,
() => {
console.log(`Successfully downloaded ${url} as ${localDestination}`);
resolve();
},
reject
);
});
};
const run = async () => {
await downloadAsPromise(config.assets.logo, "./static/logo.png");
await downloadAsPromise(config.assets.footer_logo, "./static/footer_logo.png");
await downloadAsPromise(config.assets.favicon, "./static/favicon.ico");
await downloadAsPromise(config.assets.splash_image, "./static/splash.png");
};
run();