-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e11856
commit 12a55d0
Showing
12 changed files
with
504 additions
and
345 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
module.exports = { | ||
extends: ['./node_modules/@mappable-world/mappable-cli/.eslintrc.js'] | ||
extends: ['./node_modules/@mappable-world/mappable-cli/.eslintrc.js'], | ||
rules: { | ||
'no-console': 'error' | ||
} | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** Don't edit manually only color names. Generated by script: ./tools/icons/generate-colors.ts */ | ||
export const iconColors = { | ||
darkgray: {day: '#ada9a6ff', night: '#6f737aff'}, | ||
pink: {day: '#ff8f96ff', night: '#b96066ff'}, | ||
seawave: {day: '#62c0c6ff', night: '#468286ff'}, | ||
orchid: {day: '#e096d0ff', night: '#916187ff'}, | ||
steelblue: {day: '#498ea5ff', night: '#57a8c2ff'}, | ||
bluebell: {day: '#9d9dc4ff', night: '#6767a3ff'}, | ||
ceil: {day: '#88aecfff', night: '#537695ff'}, | ||
green: {day: '#5ebd8cff', night: '#468c68ff'}, | ||
darksalmon: {day: '#f09a75ff', night: '#ab6f55ff'} | ||
} as const; | ||
export const glyphColors = {day: '#ffffffff', night: '#303741ff'} as const; | ||
export type IconColor = keyof typeof iconColors; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {Color, Api as FigmaApi, Node} from 'figma-api'; | ||
|
||
/** The name of the canvas in the file from which the colors will be loaded */ | ||
const CANVAS_NAME = 'colors'; | ||
const PALETTE_NAME = 'rubrics'; | ||
|
||
const PRIMARY_DAY = 'maps_pin_primary_day'; | ||
const PRIMARY_NIGHT = 'maps_pin_primary_night'; | ||
const GLYPH_DAY = 'maps_pin_secondary_day'; | ||
const GLYPH_NIGHT = 'maps_pin_secondary_night'; | ||
|
||
type RubricColors = { | ||
rubricName: string; | ||
primaryDay: string; | ||
primaryNight: string; | ||
}; | ||
|
||
export type MarkerColors = { | ||
day: string; | ||
night: string; | ||
}; | ||
|
||
export type FetchedColors = { | ||
colors: MarkerColors[]; | ||
glyphDay: string; | ||
glyphNight: string; | ||
}; | ||
|
||
export const fetchFigmaColors = async (): Promise<FetchedColors> => { | ||
const personalAccessToken: string | undefined = process.env.FIGMA_API_TOKEN; | ||
const fileId: string | undefined = process.env.FIGMA_FILE_ID; | ||
|
||
if (!personalAccessToken) { | ||
throw new Error('No Figma access token found in environment variable FIGMA_API_TOKEN'); | ||
} | ||
if (!fileId) { | ||
throw new Error('No Figma file id found in environment variable FIGMA_FILE_ID'); | ||
} | ||
|
||
const api = new FigmaApi({personalAccessToken}); | ||
const file = await api.getFile(fileId); | ||
const canvas = file.document.children.find((child) => child.name === CANVAS_NAME) as Node<'CANVAS'>; | ||
const rubricsPalette = canvas.children.find((child) => child.name === PALETTE_NAME) as Node<'GROUP'>; | ||
const rubrics = rubricsPalette.children.filter(({name}) => !name.includes('fallback')) as Node<'GROUP'>[]; | ||
let glyphDay: string = ''; | ||
let glyphNight: string = ''; | ||
const rubricColors = rubrics.reduce((rubricColors, {name, children}) => { | ||
const colors = children as Node<'RECTANGLE'>[]; | ||
|
||
const primaryDay = colors.find((color) => color.name === PRIMARY_DAY)?.fills[0].color; | ||
const primaryNight = colors.find((color) => color.name === PRIMARY_NIGHT)?.fills[0].color; | ||
|
||
if (glyphDay.length === 0) { | ||
const glyphDayColor = colors.find((color) => color.name === GLYPH_DAY)?.fills[0].color; | ||
glyphDay = glyphDayColor ? rgbaToHex(glyphDayColor) : glyphDay; | ||
} | ||
if (glyphNight.length === 0) { | ||
const glyphNightColor = colors.find((color) => color.name === GLYPH_NIGHT)?.fills[0].color; | ||
glyphNight = glyphNightColor ? rgbaToHex(glyphNightColor) : glyphNight; | ||
} | ||
|
||
if (primaryDay === undefined || primaryNight === undefined) { | ||
return rubricColors; | ||
} | ||
|
||
return rubricColors.concat({ | ||
rubricName: name, | ||
primaryDay: rgbaToHex(primaryDay), | ||
primaryNight: rgbaToHex(primaryNight) | ||
}); | ||
}, [] as RubricColors[]); | ||
|
||
const dayNightColorsMap = rubricColors.reduce((colorsMap, {primaryDay, primaryNight}) => { | ||
colorsMap.set(primaryDay, primaryNight); | ||
return colorsMap; | ||
}, new Map<string, string>()); | ||
|
||
const colors = Array.from(dayNightColorsMap.entries()).map(([day, night]) => ({day, night})); | ||
return {colors, glyphDay, glyphNight}; | ||
}; | ||
|
||
const rgbaToHex = (rgba: Color): string => { | ||
const r255 = Math.floor(rgba.r * 255); | ||
const g255 = Math.floor(rgba.g * 255); | ||
const b255 = Math.floor(rgba.b * 255); | ||
const a255 = Math.floor(rgba.a * 255); | ||
return '#' + componentToHex(r255) + componentToHex(g255) + componentToHex(b255) + componentToHex(a255); | ||
}; | ||
|
||
const componentToHex = (c: number): string => c.toString(16).padStart(2, '0'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
import {prettierFormat} from '../utils/prettier-format'; | ||
import {FetchedColors} from './fetch-colors'; | ||
import {SRC_ICONS_PATH} from './paths'; | ||
|
||
/** Human-readable names for colors. They are selected manually */ | ||
const colorNames = ['darkgray', 'pink', 'seawave', 'orchid', 'steelblue', 'bluebell', 'ceil', 'green', 'darksalmon']; | ||
|
||
export const generateColorsFile = async (fetchedColors: FetchedColors) => { | ||
const colorsObjectValues = fetchedColors.colors.map(({day, night}, i) => { | ||
return `${colorNames[i]}:{day:'${day}',night:'${night}'},`; | ||
}); | ||
const content = ` | ||
/** Don't edit manually only color names. Generated by script: ./tools/icons/generate-colors.ts */ | ||
export const iconColors = { | ||
${colorsObjectValues.join('\n')} | ||
} as const; | ||
export const glyphColors = {day:'${fetchedColors.glyphDay}',night:'${fetchedColors.glyphNight}'} as const; | ||
export type IconColor = keyof typeof iconColors`; | ||
|
||
const formattedContent = await prettierFormat(content, 'typescript'); | ||
await fs.writeFile(path.join(SRC_ICONS_PATH, 'icon-colors.ts'), formattedContent); | ||
}; |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {createSpinner} from 'nanospinner'; | ||
import {fetchFigmaColors} from '../icons/fetch-colors'; | ||
import {generateColorsFile} from '../icons/generate-colors'; | ||
|
||
async function main() { | ||
const spinner = createSpinner(); | ||
try { | ||
spinner.start({text: 'Start sync colors'}); | ||
|
||
spinner.update({text: 'Getting information about colors from Figma'}); | ||
const fetchedColors = await fetchFigmaColors(); | ||
|
||
spinner.update({text: 'Updating the file with colors'}); | ||
await generateColorsFile(fetchedColors); | ||
|
||
spinner.success({text: 'Colors are successfully synchronized'}); | ||
} catch (error) { | ||
spinner.error({text: error.message || error.toString()}); | ||
} | ||
} | ||
|
||
main().catch(() => { | ||
process.exit(1); | ||
}); |