Created
December 8, 2020 09:31
-
-
Save crisu83/825c645949f454a02c16027d4ea45287 to your computer and use it in GitHub Desktop.
Script for generating favicons from an image file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// eslint-disable-next-line node/no-unpublished-import | |
import favicons from 'favicons'; | |
import fs from 'fs'; | |
const [, , source] = process.argv; | |
if (!source) { | |
throw new Error('You need to specify a `source`.'); | |
} | |
const config = { | |
appName: 'My app', | |
background: '#fff', | |
icons: { | |
appleStartup: false, | |
coast: false, | |
firefox: false, | |
windows: false, | |
yandex: false, | |
}, | |
themeColor: '#bada55', // Get it? :D | |
}; | |
const skipRegexp = new RegExp( | |
[ | |
'favicon.ico', | |
'favicon-(?!.*32x32).*.png', | |
'android-chrome-(?!.*192x192).*.png', | |
'apple-touch-icon.png', | |
'apple-touch-icon-(?!.*180x180).*.png', | |
].join('|') | |
); | |
favicons(source, config, (error, response) => { | |
if (error) { | |
console.log(error.message); | |
return; | |
} | |
response.images.forEach(image => { | |
if (!skipRegexp.test(image.name)) { | |
fs.writeFileSync( | |
`${process.cwd()}/public/favicons/${image.name}`, | |
image.contents | |
); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment