45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
const https = require('https');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const fonts = [
|
|
{ name: 'Nunito-Regular.ttf', url: 'https://github.com/googlefonts/nunito/raw/main/fonts/ttf/Nunito-Regular.ttf' },
|
|
{ name: 'Nunito-SemiBold.ttf', url: 'https://github.com/googlefonts/nunito/raw/main/fonts/ttf/Nunito-SemiBold.ttf' },
|
|
{ name: 'Nunito-Bold.ttf', url: 'https://github.com/googlefonts/nunito/raw/main/fonts/ttf/Nunito-Bold.ttf' },
|
|
{ name: 'Nunito-ExtraBold.ttf', url: 'https://github.com/googlefonts/nunito/raw/main/fonts/ttf/Nunito-ExtraBold.ttf' },
|
|
];
|
|
|
|
const dir = path.join(__dirname, 'assets', 'fonts');
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
}
|
|
|
|
function download(url, dest) {
|
|
return new Promise((resolve, reject) => {
|
|
const file = fs.createWriteStream(dest);
|
|
https.get(url, (response) => {
|
|
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
download(response.headers.location, dest).then(resolve).catch(reject);
|
|
return;
|
|
}
|
|
response.pipe(file);
|
|
file.on('finish', () => {
|
|
file.close(resolve);
|
|
});
|
|
}).on('error', (err) => {
|
|
fs.unlink(dest, () => reject(err));
|
|
});
|
|
});
|
|
}
|
|
|
|
Promise.all(fonts.map(font => {
|
|
const dest = path.join(dir, font.name);
|
|
console.log(`Downloading ${font.name}...`);
|
|
return download(font.url, dest);
|
|
})).then(() => {
|
|
console.log('All fonts downloaded successfully!');
|
|
}).catch(err => {
|
|
console.error('Error downloading fonts:', err);
|
|
});
|