forked from electron/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolors.js
More file actions
executable file
·48 lines (44 loc) · 1.39 KB
/
Copy pathcolors.js
File metadata and controls
executable file
·48 lines (44 loc) · 1.39 KB
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
const fs = require('fs')
const path = require('path')
const getImageColors = require('get-image-colors')
const pickAGoodColor = require('pick-a-good-color')
const colorConvert = require('color-convert')
const apps = require('../lib/raw-app-list')()
const colors = {}
console.log('Extracting color palettes from app icons...')
// Prevent superficial diffs in the file by adding sorted keys first
apps.forEach(app => {
colors[app.slug] = null
})
Promise.all(
apps
.filter(app => fs.existsSync(app.iconPath))
.map(app => {
return getImageColors(app.iconPath).then(iconColors => {
const palette = iconColors.map(color => color.hex())
const goodColorOnWhite = pickAGoodColor(palette)
const goodColorOnBlack = pickAGoodColor(palette, {background: 'black'})
const faintColorOnWhite = `rgba(${colorConvert.hex.rgb(goodColorOnWhite).join(', ')}, 0.1)`
colors[app.slug] = {
palette: palette,
goodColorOnWhite: goodColorOnWhite,
goodColorOnBlack: goodColorOnBlack,
faintColorOnWhite: faintColorOnWhite
}
return Promise.resolve(true)
})
.catch(error => {
console.log(`problem with ${app.slug} icon: ${app.iconPath}`)
console.error(error)
})
})
)
.then(apps => {
fs.writeFileSync(
path.join(__dirname, '../meta/colors.json'),
JSON.stringify(colors, null, 2)
)
})
.catch(error => {
console.error(error)
})