mirror of
https://github.com/penpot/penpot-export.git
synced 2025-01-19 21:22:28 -05:00
feat(core): sort assets reproducibly by name
This commit is contained in:
parent
5392f8a4e0
commit
f988d73655
3 changed files with 18 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
import { CSSCustomPropertyDefinition, ColorAssets } from '../../types'
|
||||
|
||||
import { compareByName } from '../helpers'
|
||||
import { PenpotApiFile } from '../types'
|
||||
|
||||
const toHexQuartet = (hexTriplet: string, alpha: number = 1) => {
|
||||
|
@ -24,6 +25,8 @@ const toHexQuartet = (hexTriplet: string, alpha: number = 1) => {
|
|||
const adaptColorsToCssVariables = (penpotFile: PenpotApiFile): ColorAssets => {
|
||||
const fileName = penpotFile.name
|
||||
const colors = Object.values(penpotFile.data.colors ?? {})
|
||||
.slice()
|
||||
.sort(compareByName)
|
||||
|
||||
const cssPropsEntries = colors.map<CSSCustomPropertyDefinition>((color) => {
|
||||
return {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { CSSClassDefinition, FontsSummary, TypographyAssets } from '../../types'
|
||||
|
||||
import { compareByName } from '../helpers'
|
||||
import { PenpotApiTypography, CssTextProperty, PenpotApiFile } from '../types'
|
||||
|
||||
const mapTypographyAssetCssProps = (
|
||||
|
@ -68,6 +69,8 @@ const summarizeTypographies = (
|
|||
const adaptTypographies = (penpotFile: PenpotApiFile): TypographyAssets => {
|
||||
const fileName = penpotFile.name
|
||||
const typographies = Object.values(penpotFile.data.typographies ?? {})
|
||||
.slice()
|
||||
.sort(compareByName)
|
||||
|
||||
return {
|
||||
scope: fileName,
|
||||
|
|
|
@ -1,9 +1,20 @@
|
|||
import { PenpotApiComponent, PenpotApiObject, PenpotApiPage } from './types'
|
||||
import {
|
||||
PenpotApiColor,
|
||||
PenpotApiComponent,
|
||||
PenpotApiObject,
|
||||
PenpotApiPage,
|
||||
PenpotApiTypography,
|
||||
} from './types'
|
||||
|
||||
export function isComponent(object: PenpotApiObject) {
|
||||
return object.componentRoot === true
|
||||
}
|
||||
|
||||
export const compareByName = (
|
||||
assetA: PenpotApiColor | PenpotApiTypography,
|
||||
assetB: PenpotApiColor | PenpotApiTypography,
|
||||
) => (assetA.name > assetB.name ? 1 : -1)
|
||||
|
||||
export function getObjectShapesFromPage(
|
||||
object: PenpotApiObject,
|
||||
page: PenpotApiPage,
|
||||
|
|
Loading…
Add table
Reference in a new issue