Skip to content

Commit a1a51de

Browse files
committed
Impement export devup
1 parent 7860e0d commit a1a51de

File tree

5 files changed

+502
-43
lines changed

5 files changed

+502
-43
lines changed

src/commands/devup/__tests__/import-devup.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ describe('import-devup (standalone file)', () => {
6666
createVariable,
6767
},
6868
getLocalTextStylesAsync: async () => [],
69+
getLocalEffectStylesAsync: async () => [],
6970
createTextStyle,
71+
createEffectStyle: () => ({ name: '', effects: [] }),
7072
loadFontAsync,
7173
} as unknown as typeof figma
7274

@@ -129,12 +131,14 @@ describe('import-devup (standalone file)', () => {
129131
createVariable,
130132
},
131133
getLocalTextStylesAsync: async () => [],
134+
getLocalEffectStylesAsync: async () => [],
132135
createTextStyle: mock(
133136
() =>
134137
({
135138
name: '',
136139
}) as unknown as TextStyle,
137140
),
141+
createEffectStyle: () => ({ name: '', effects: [] }),
138142
loadFontAsync: mock(() => Promise.resolve()),
139143
} as unknown as typeof figma
140144

@@ -194,7 +198,9 @@ describe('import-devup (standalone file)', () => {
194198
),
195199
},
196200
getLocalTextStylesAsync: async () => [],
201+
getLocalEffectStylesAsync: async () => [],
197202
createTextStyle,
203+
createEffectStyle: () => ({ name: '', effects: [] }),
198204
loadFontAsync,
199205
} as unknown as typeof figma
200206

src/commands/devup/__tests__/index.test.ts

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,26 @@ describe('devup commands', () => {
106106
util: { rgba: (v: unknown) => v },
107107
loadAllPagesAsync: async () => {},
108108
getLocalTextStylesAsync: async () => [],
109+
getLocalEffectStylesAsync: async () => [],
109110
root: { findAllWithCriteria: () => [] },
110111
variables: {
111112
getVariableByIdAsync: async () =>
112113
({
113114
name: 'Primary',
115+
resolvedType: 'COLOR',
114116
valuesByMode: { m1: { r: 1, g: 0, b: 0, a: 1 } },
115117
}) as unknown as Variable,
118+
getLocalVariableCollectionsAsync: async () => [
119+
{
120+
modes: [{ modeId: 'm1', name: 'Light' }],
121+
variableIds: ['v1'],
122+
},
123+
],
116124
},
117125
} as unknown as typeof figma
118126

119127
await exportDevup('json')
120128

121-
expect(getColorCollectionSpy).toHaveBeenCalled()
122129
expect(downloadFileMock).toHaveBeenCalledWith(
123130
'devup.json',
124131
expect.stringContaining('"primary":"#ff0000"'),
@@ -152,9 +159,11 @@ describe('devup commands', () => {
152159
{ id: '1', name: 'heading/1' },
153160
{ id: '2', name: 'heading/2' },
154161
] as unknown as TextStyle[],
162+
getLocalEffectStylesAsync: async () => [],
155163
root: { findAllWithCriteria: () => [] },
156164
variables: {
157165
getVariableByIdAsync: async () => null,
166+
getLocalVariableCollectionsAsync: async () => [],
158167
},
159168
} as unknown as typeof figma
160169

@@ -210,6 +219,7 @@ describe('devup commands', () => {
210219
getLocalTextStylesAsync: async () => [
211220
{ id: 'style1', name: 'heading/1' } as unknown as TextStyle,
212221
],
222+
getLocalEffectStylesAsync: async () => [],
213223
root: {
214224
findAllWithCriteria: () => [textNode],
215225
children: [],
@@ -224,6 +234,12 @@ describe('devup commands', () => {
224234
name: 'Primary',
225235
valuesByMode: { m1: { type: 'VARIABLE_ALIAS', id: 'var1' } },
226236
}) as unknown as Variable,
237+
getLocalVariableCollectionsAsync: async () => [
238+
{
239+
modes: [{ modeId: 'm1', name: 'Light' }],
240+
variableIds: ['var1'],
241+
},
242+
],
227243
},
228244
} as unknown as typeof figma
229245

@@ -265,9 +281,13 @@ describe('devup commands', () => {
265281
getLocalTextStylesAsync: async () => [
266282
{ id: 'style1', name: 'heading/1' } as unknown as TextStyle,
267283
],
284+
getLocalEffectStylesAsync: async () => [],
268285
root: { findAllWithCriteria: () => [mixedTextNode] },
269286
mixed: mixedSymbol,
270-
variables: { getVariableByIdAsync: async () => null },
287+
variables: {
288+
getVariableByIdAsync: async () => null,
289+
getLocalVariableCollectionsAsync: async () => [],
290+
},
271291
} as unknown as typeof figma
272292

273293
await exportDevup('json', true)
@@ -329,11 +349,15 @@ describe('devup commands', () => {
329349
{ id: 'style1', name: 'heading/1' } as unknown as TextStyle,
330350
{ id: 'style2', name: 'heading/2' } as unknown as TextStyle,
331351
],
352+
getLocalEffectStylesAsync: async () => [],
332353
root: {
333354
children: [otherPage, currentPage],
334355
},
335356
mixed: Symbol('mixed'),
336-
variables: { getVariableByIdAsync: async () => null },
357+
variables: {
358+
getVariableByIdAsync: async () => null,
359+
getLocalVariableCollectionsAsync: async () => [],
360+
},
337361
} as unknown as typeof figma
338362

339363
await exportDevup('json', true)
@@ -400,11 +424,15 @@ describe('devup commands', () => {
400424
{ id: 'style1', name: 'heading/1' } as unknown as TextStyle,
401425
{ id: 'style2', name: 'body/2' } as unknown as TextStyle,
402426
],
427+
getLocalEffectStylesAsync: async () => [],
403428
root: {
404429
children: [currentPage, otherPage],
405430
},
406431
mixed: Symbol('mixed'),
407-
variables: { getVariableByIdAsync: async () => null },
432+
variables: {
433+
getVariableByIdAsync: async () => null,
434+
getLocalVariableCollectionsAsync: async () => [],
435+
},
408436
} as unknown as typeof figma
409437

410438
await exportDevup('json', true)
@@ -464,11 +492,15 @@ describe('devup commands', () => {
464492
{ id: 'style1', name: 'heading/1' } as unknown as TextStyle,
465493
{ id: 'style2', name: 'body/2' } as unknown as TextStyle,
466494
],
495+
getLocalEffectStylesAsync: async () => [],
467496
root: {
468497
children: [currentPage],
469498
},
470499
mixed: Symbol('mixed'),
471-
variables: { getVariableByIdAsync: async () => null },
500+
variables: {
501+
getVariableByIdAsync: async () => null,
502+
getLocalVariableCollectionsAsync: async () => [],
503+
},
472504
} as unknown as typeof figma
473505

474506
await exportDevup('json', true)
@@ -519,13 +551,17 @@ describe('devup commands', () => {
519551
{ id: 'style1', name: 'heading/1' },
520552
{ id: 'style2', name: 'heading/2' },
521553
] as unknown as TextStyle[],
554+
getLocalEffectStylesAsync: async () => [],
522555
root: { findAllWithCriteria: () => [textNode], children: [] },
523556
getStyleByIdAsync: async (id: string) =>
524557
id === 'style1'
525558
? ({ id: 'style1', name: 'heading/1' } as unknown as TextStyle)
526559
: ({ id: 'style2', name: 'heading/2' } as unknown as TextStyle),
527560
mixed: Symbol('mixed'),
528-
variables: { getVariableByIdAsync: async () => null },
561+
variables: {
562+
getVariableByIdAsync: async () => null,
563+
getLocalVariableCollectionsAsync: async () => [],
564+
},
529565
} as unknown as typeof figma
530566

531567
await exportDevup('json', true)
@@ -566,8 +602,12 @@ describe('devup commands', () => {
566602
{ id: 'style1', name: 'heading/1' },
567603
{ id: 'style3', name: 'heading/3' },
568604
] as unknown as TextStyle[],
605+
getLocalEffectStylesAsync: async () => [],
569606
root: { findAllWithCriteria: () => [], children: [] },
570-
variables: { getVariableByIdAsync: async () => null },
607+
variables: {
608+
getVariableByIdAsync: async () => null,
609+
getLocalVariableCollectionsAsync: async () => [],
610+
},
571611
} as unknown as typeof figma
572612

573613
await exportDevup('json', false)
@@ -608,8 +648,12 @@ describe('devup commands', () => {
608648
{ id: 'style0', name: 'heading/0' },
609649
{ id: 'style1', name: 'heading/2' },
610650
] as unknown as TextStyle[],
651+
getLocalEffectStylesAsync: async () => [],
611652
root: { findAllWithCriteria: () => [], children: [] },
612-
variables: { getVariableByIdAsync: async () => null },
653+
variables: {
654+
getVariableByIdAsync: async () => null,
655+
getLocalVariableCollectionsAsync: async () => [],
656+
},
613657
} as unknown as typeof figma
614658

615659
await exportDevup('json', false)
@@ -638,7 +682,10 @@ describe('devup commands', () => {
638682

639683
;(globalThis as { figma?: unknown }).figma = {
640684
util: { rgba: (v: unknown) => v },
641-
variables: {},
685+
variables: {
686+
getVariableByIdAsync: async () => null,
687+
getLocalVariableCollectionsAsync: async () => [],
688+
},
642689
loadAllPagesAsync: async () => {},
643690
getLocalTextStylesAsync: async () => [
644691
{
@@ -647,6 +694,7 @@ describe('devup commands', () => {
647694
fontName: { family: 'Inter', style: 'Regular' },
648695
} as unknown as TextStyle,
649696
],
697+
getLocalEffectStylesAsync: async () => [],
650698
root: {
651699
findAllWithCriteria: () => [
652700
{
@@ -734,6 +782,7 @@ describe('devup commands', () => {
734782
createVariable,
735783
},
736784
getLocalTextStylesAsync: async () => [],
785+
getLocalEffectStylesAsync: async () => [],
737786
createTextStyle: createTextStyleMock,
738787
loadFontAsync,
739788
} as unknown as typeof figma
@@ -823,6 +872,7 @@ describe('devup commands', () => {
823872
createVariable,
824873
},
825874
getLocalTextStylesAsync: async () => [],
875+
getLocalEffectStylesAsync: async () => [],
826876
createTextStyle: createTextStyleMock,
827877
loadFontAsync,
828878
} as unknown as typeof figma
@@ -881,6 +931,7 @@ describe('devup commands', () => {
881931
}) as unknown as Variable,
882932
},
883933
getLocalTextStylesAsync: async () => [],
934+
getLocalEffectStylesAsync: async () => [],
884935
createTextStyle: createTextStyleMock,
885936
loadFontAsync,
886937
notify: notifyMock,
@@ -949,6 +1000,7 @@ describe('devup commands', () => {
9491000
}) as unknown as Variable,
9501001
},
9511002
getLocalTextStylesAsync: async () => [],
1003+
getLocalEffectStylesAsync: async () => [],
9521004
createTextStyle: () => styleObj,
9531005
loadFontAsync,
9541006
notify: mock(() => {}),

0 commit comments

Comments
 (0)