From cb3b76263d86450b1e0fdf8425203acff69fc4a3 Mon Sep 17 00:00:00 2001 From: Marco Christian Krenn Date: Tue, 17 Dec 2024 10:01:59 +0100 Subject: [PATCH 1/3] fix prettier --- packages/nodes-figma/.dockerignore | 4 + packages/nodes-figma/.eslintignore | 11 + packages/nodes-figma/.eslintrc.cjs | 6 + packages/nodes-figma/.prettierignore | 15 + packages/nodes-figma/.prettierrc.json | 1 + packages/nodes-figma/src/index.ts | 2 +- packages/nodes-figma/src/nodes/codeSyntax.ts | 134 +++---- packages/nodes-figma/src/nodes/index.ts | 28 +- packages/nodes-figma/src/nodes/publish.ts | 106 ++--- packages/nodes-figma/src/nodes/scopeAll.ts | 88 ++-- packages/nodes-figma/src/nodes/scopeByType.ts | 150 +++---- packages/nodes-figma/src/nodes/scopeColor.ts | 188 ++++----- packages/nodes-figma/src/nodes/scopeNumber.ts | 376 +++++++++--------- packages/nodes-figma/src/nodes/scopeString.ts | 134 +++---- packages/nodes-figma/src/schemas/utils.ts | 6 +- packages/nodes-figma/src/types/scopes.ts | 88 ++-- packages/nodes-figma/src/utils/tokenMerge.ts | 70 ++-- packages/nodes-figma/tests/codeSyntax.test.ts | 172 ++++---- packages/nodes-figma/tests/publish.test.ts | 154 +++---- packages/nodes-figma/tests/scopeAll.test.ts | 160 ++++---- .../nodes-figma/tests/scopeByType.test.ts | 234 +++++------ packages/nodes-figma/tests/scopeColor.test.ts | 306 +++++++------- .../nodes-figma/tests/scopeNumber.test.ts | 356 ++++++++--------- .../nodes-figma/tests/scopeString.test.ts | 292 +++++++------- packages/nodes-figma/tsconfig.docs.json | 12 +- packages/nodes-figma/tsconfig.json | 70 ++-- packages/nodes-figma/tsconfig.prod.json | 52 +-- packages/nodes-figma/typedoc.json | 18 +- packages/nodes-figma/vitest.config.ts | 10 +- 29 files changed, 1640 insertions(+), 1603 deletions(-) create mode 100644 packages/nodes-figma/.dockerignore create mode 100644 packages/nodes-figma/.eslintignore create mode 100644 packages/nodes-figma/.eslintrc.cjs create mode 100644 packages/nodes-figma/.prettierignore create mode 100644 packages/nodes-figma/.prettierrc.json diff --git a/packages/nodes-figma/.dockerignore b/packages/nodes-figma/.dockerignore new file mode 100644 index 000000000..e57036f4f --- /dev/null +++ b/packages/nodes-figma/.dockerignore @@ -0,0 +1,4 @@ +dist +docs +jest-coverage +node_modules \ No newline at end of file diff --git a/packages/nodes-figma/.eslintignore b/packages/nodes-figma/.eslintignore new file mode 100644 index 000000000..4e25d4741 --- /dev/null +++ b/packages/nodes-figma/.eslintignore @@ -0,0 +1,11 @@ +dist/** +build/** +coverage/** +storybook-static/** +.docusaurus +docs +site +cypress +cli +.rollup +*.md \ No newline at end of file diff --git a/packages/nodes-figma/.eslintrc.cjs b/packages/nodes-figma/.eslintrc.cjs new file mode 100644 index 000000000..790e3bb7e --- /dev/null +++ b/packages/nodes-figma/.eslintrc.cjs @@ -0,0 +1,6 @@ +/* eslint-disable no-undef */ +/** @type {import("eslint").Linter.Config} */ +module.exports = { + root:true, + extends: [require.resolve('@tokens-studio/eslint-config-custom')] +}; \ No newline at end of file diff --git a/packages/nodes-figma/.prettierignore b/packages/nodes-figma/.prettierignore new file mode 100644 index 000000000..759e0ea18 --- /dev/null +++ b/packages/nodes-figma/.prettierignore @@ -0,0 +1,15 @@ +package.json +package-lock.json +dist +coverage +docs +jest-coverage +site +cli +.turbo +.rollup.cache +.rollup +build +storybook-static +.docusaurus +cypress \ No newline at end of file diff --git a/packages/nodes-figma/.prettierrc.json b/packages/nodes-figma/.prettierrc.json new file mode 100644 index 000000000..cc89e1de7 --- /dev/null +++ b/packages/nodes-figma/.prettierrc.json @@ -0,0 +1 @@ +"@tokens-studio/prettier-config-custom" diff --git a/packages/nodes-figma/src/index.ts b/packages/nodes-figma/src/index.ts index d142f8501..936237cd5 100644 --- a/packages/nodes-figma/src/index.ts +++ b/packages/nodes-figma/src/index.ts @@ -1 +1 @@ -export * from "./nodes/index.js"; +export * from './nodes/index.js'; diff --git a/packages/nodes-figma/src/nodes/codeSyntax.ts b/packages/nodes-figma/src/nodes/codeSyntax.ts index d3e9e0b32..497bcf483 100644 --- a/packages/nodes-figma/src/nodes/codeSyntax.ts +++ b/packages/nodes-figma/src/nodes/codeSyntax.ts @@ -1,82 +1,82 @@ import { - INodeDefinition, - Node, - StringSchema, - ToInput, - ToOutput, -} from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { TokenSchema } from "@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js"; -import { mergeTokenExtensions } from "../utils/tokenMerge.js"; + INodeDefinition, + Node, + StringSchema, + ToInput, + ToOutput +} from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { TokenSchema } from '@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js'; +import { mergeTokenExtensions } from '../utils/tokenMerge.js'; export default class NodeDefinition extends Node { - static title = "Code Syntax"; - static type = "studio.tokens.figma.codeSyntax"; - static description = "Defines code syntax for different platforms in Figma"; + static title = 'Code Syntax'; + static type = 'studio.tokens.figma.codeSyntax'; + static description = 'Defines code syntax for different platforms in Figma'; - declare inputs: ToInput<{ - token: SingleToken; - web: string; - android: string; - ios: string; - }>; - declare outputs: ToOutput<{ - token: SingleToken; - }>; + declare inputs: ToInput<{ + token: SingleToken; + web: string; + android: string; + ios: string; + }>; + declare outputs: ToOutput<{ + token: SingleToken; + }>; - constructor(props: INodeDefinition) { - super(props); + constructor(props: INodeDefinition) { + super(props); - this.addInput("token", { - type: { - ...TokenSchema, - description: "The design token to add code syntax to", - }, - }); + this.addInput('token', { + type: { + ...TokenSchema, + description: 'The design token to add code syntax to' + } + }); - this.addInput("web", { - type: { - ...StringSchema, - default: "", - description: "Web platform code syntax", - }, - }); + this.addInput('web', { + type: { + ...StringSchema, + default: '', + description: 'Web platform code syntax' + } + }); - this.addInput("android", { - type: { - ...StringSchema, - default: "", - description: "Android platform code syntax", - }, - }); + this.addInput('android', { + type: { + ...StringSchema, + default: '', + description: 'Android platform code syntax' + } + }); - this.addInput("ios", { - type: { - ...StringSchema, - default: "", - description: "iOS platform code syntax", - }, - }); + this.addInput('ios', { + type: { + ...StringSchema, + default: '', + description: 'iOS platform code syntax' + } + }); - this.addOutput("token", { - type: TokenSchema, - }); - } + this.addOutput('token', { + type: TokenSchema + }); + } - execute(): void | Promise { - const inputs = this.getAllInputs(); + execute(): void | Promise { + const inputs = this.getAllInputs(); - const codeSyntax = { - ...(inputs.web && { Web: inputs.web }), - ...(inputs.android && { Android: inputs.android }), - ...(inputs.ios && { iOS: inputs.ios }), - }; + const codeSyntax = { + ...(inputs.web && { Web: inputs.web }), + ...(inputs.android && { Android: inputs.android }), + ...(inputs.ios && { iOS: inputs.ios }) + }; - const modifiedToken = mergeTokenExtensions(inputs.token, { - hiddenFromPublishing: false, - codeSyntax, - }); + const modifiedToken = mergeTokenExtensions(inputs.token, { + hiddenFromPublishing: false, + codeSyntax + }); - this.outputs.token.set(modifiedToken); - } + this.outputs.token.set(modifiedToken); + } } diff --git a/packages/nodes-figma/src/nodes/index.ts b/packages/nodes-figma/src/nodes/index.ts index 2105c3960..c312621cd 100644 --- a/packages/nodes-figma/src/nodes/index.ts +++ b/packages/nodes-figma/src/nodes/index.ts @@ -1,17 +1,17 @@ -import codeSyntax from "./codeSyntax.js"; -import publish from "./publish.js"; -import scopeAll from "./scopeAll.js"; -import scopeByType from "./scopeByType.js"; -import scopeColor from "./scopeColor.js"; -import scopeNumber from "./scopeNumber.js"; -import scopeString from "./scopeString.js"; +import codeSyntax from './codeSyntax.js'; +import publish from './publish.js'; +import scopeAll from './scopeAll.js'; +import scopeByType from './scopeByType.js'; +import scopeColor from './scopeColor.js'; +import scopeNumber from './scopeNumber.js'; +import scopeString from './scopeString.js'; export const nodes = [ - codeSyntax, - publish, - scopeAll, - scopeByType, - scopeColor, - scopeNumber, - scopeString, + codeSyntax, + publish, + scopeAll, + scopeByType, + scopeColor, + scopeNumber, + scopeString ]; diff --git a/packages/nodes-figma/src/nodes/publish.ts b/packages/nodes-figma/src/nodes/publish.ts index 306536346..e98f621a3 100644 --- a/packages/nodes-figma/src/nodes/publish.ts +++ b/packages/nodes-figma/src/nodes/publish.ts @@ -1,57 +1,57 @@ import { - BooleanSchema, - INodeDefinition, - Node, - ToInput, - ToOutput, -} from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { TokenSchema } from "@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js"; -import { mergeTokenExtensions } from "../utils/tokenMerge.js"; + BooleanSchema, + INodeDefinition, + Node, + ToInput, + ToOutput +} from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { TokenSchema } from '@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js'; +import { mergeTokenExtensions } from '../utils/tokenMerge.js'; export default class NodeDefinition extends Node { - static title = "Publish Variable"; - static type = "studio.tokens.figma.publish"; - static description = "Controls whether a variable is published to Users"; - - declare inputs: ToInput<{ - token: SingleToken; - publish: boolean; - }>; - declare outputs: ToOutput<{ - token: SingleToken; - }>; - - constructor(props: INodeDefinition) { - super(props); - - this.addInput("token", { - type: { - ...TokenSchema, - description: "The design token to control publishing for", - }, - }); - - this.addInput("publish", { - type: { - ...BooleanSchema, - default: true, - description: "Whether to publish this token to Figma", - }, - }); - - this.addOutput("token", { - type: TokenSchema, - }); - } - - execute(): void | Promise { - const { token, publish } = this.getAllInputs(); - - const modifiedToken = mergeTokenExtensions(token, { - hiddenFromPublishing: !publish, - }); - - this.outputs.token.set(modifiedToken); - } + static title = 'Publish Variable'; + static type = 'studio.tokens.figma.publish'; + static description = 'Controls whether a variable is published to Users'; + + declare inputs: ToInput<{ + token: SingleToken; + publish: boolean; + }>; + declare outputs: ToOutput<{ + token: SingleToken; + }>; + + constructor(props: INodeDefinition) { + super(props); + + this.addInput('token', { + type: { + ...TokenSchema, + description: 'The design token to control publishing for' + } + }); + + this.addInput('publish', { + type: { + ...BooleanSchema, + default: true, + description: 'Whether to publish this token to Figma' + } + }); + + this.addOutput('token', { + type: TokenSchema + }); + } + + execute(): void | Promise { + const { token, publish } = this.getAllInputs(); + + const modifiedToken = mergeTokenExtensions(token, { + hiddenFromPublishing: !publish + }); + + this.outputs.token.set(modifiedToken); + } } diff --git a/packages/nodes-figma/src/nodes/scopeAll.ts b/packages/nodes-figma/src/nodes/scopeAll.ts index cfe25dcbe..3c29de182 100644 --- a/packages/nodes-figma/src/nodes/scopeAll.ts +++ b/packages/nodes-figma/src/nodes/scopeAll.ts @@ -1,48 +1,48 @@ import { - INodeDefinition, - Node, - ToInput, - ToOutput, -} from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { TokenSchema } from "@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js"; -import { mergeTokenExtensions } from "../utils/tokenMerge.js"; + INodeDefinition, + Node, + ToInput, + ToOutput +} from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { TokenSchema } from '@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js'; +import { mergeTokenExtensions } from '../utils/tokenMerge.js'; export default class NodeDefinition extends Node { - static title = "Scope All"; - static type = "studio.tokens.figma.scopeAll"; - static description = "Adds ALL_SCOPES scope to a Figma token"; - - declare inputs: ToInput<{ - token: SingleToken; - }>; - declare outputs: ToOutput<{ - token: SingleToken; - }>; - - constructor(props: INodeDefinition) { - super(props); - - this.addInput("token", { - type: { - ...TokenSchema, - description: "The design token to add ALL_SCOPES to", - }, - }); - - this.addOutput("token", { - type: TokenSchema, - }); - } - - execute(): void | Promise { - const inputs = this.getAllInputs(); - const newScopes = ["ALL_SCOPES"]; - - const modifiedToken = mergeTokenExtensions(inputs.token, { - scopes: newScopes, - }); - - this.outputs.token.set(modifiedToken); - } + static title = 'Scope All'; + static type = 'studio.tokens.figma.scopeAll'; + static description = 'Adds ALL_SCOPES scope to a Figma token'; + + declare inputs: ToInput<{ + token: SingleToken; + }>; + declare outputs: ToOutput<{ + token: SingleToken; + }>; + + constructor(props: INodeDefinition) { + super(props); + + this.addInput('token', { + type: { + ...TokenSchema, + description: 'The design token to add ALL_SCOPES to' + } + }); + + this.addOutput('token', { + type: TokenSchema + }); + } + + execute(): void | Promise { + const inputs = this.getAllInputs(); + const newScopes = ['ALL_SCOPES']; + + const modifiedToken = mergeTokenExtensions(inputs.token, { + scopes: newScopes + }); + + this.outputs.token.set(modifiedToken); + } } diff --git a/packages/nodes-figma/src/nodes/scopeByType.ts b/packages/nodes-figma/src/nodes/scopeByType.ts index 13bb2114d..028b5ac56 100644 --- a/packages/nodes-figma/src/nodes/scopeByType.ts +++ b/packages/nodes-figma/src/nodes/scopeByType.ts @@ -1,87 +1,87 @@ -import { FigmaScope } from "../types/scopes.js"; +import { FigmaScope } from '../types/scopes.js'; import { - INodeDefinition, - Node, - ToInput, - ToOutput, -} from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { TokenSchema } from "@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js"; -import { mergeTokenExtensions } from "../utils/tokenMerge.js"; + INodeDefinition, + Node, + ToInput, + ToOutput +} from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { TokenSchema } from '@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js'; +import { mergeTokenExtensions } from '../utils/tokenMerge.js'; export default class NodeDefinition extends Node { - static title = "Scope By Type"; - static type = "studio.tokens.figma.scopeByType"; - static description = "Automatically sets Figma scopes based on token type"; + static title = 'Scope By Type'; + static type = 'studio.tokens.figma.scopeByType'; + static description = 'Automatically sets Figma scopes based on token type'; - declare inputs: ToInput<{ - token: SingleToken; - }>; - declare outputs: ToOutput<{ - token: SingleToken; - }>; + declare inputs: ToInput<{ + token: SingleToken; + }>; + declare outputs: ToOutput<{ + token: SingleToken; + }>; - constructor(props: INodeDefinition) { - super(props); + constructor(props: INodeDefinition) { + super(props); - this.addInput("token", { - type: { - ...TokenSchema, - description: "The design token to automatically scope", - }, - }); + this.addInput('token', { + type: { + ...TokenSchema, + description: 'The design token to automatically scope' + } + }); - this.addOutput("token", { - type: TokenSchema, - }); - } + this.addOutput('token', { + type: TokenSchema + }); + } - private getScopesByType(token: SingleToken): FigmaScope[] { - switch (token.type) { - case "color": - return ["ALL_FILLS", "STROKE_COLOR", "EFFECT_COLOR"]; - case "dimension": - return [ - "GAP", - "WIDTH_HEIGHT", - "CORNER_RADIUS", - "STROKE_FLOAT", - "EFFECT_FLOAT", - "PARAGRAPH_INDENT", - ]; - case "spacing": - return ["GAP", "WIDTH_HEIGHT"]; - case "borderRadius": - return ["CORNER_RADIUS"]; - case "fontFamilies": - return ["FONT_FAMILY"]; - case "fontWeights": - return ["FONT_WEIGHT"]; - case "fontSizes": - return ["FONT_SIZE"]; - case "lineHeights": - return ["LINE_HEIGHT"]; - case "letterSpacing": - return ["LETTER_SPACING"]; - case "paragraphSpacing": - return ["PARAGRAPH_SPACING"]; - case "opacity": - return ["OPACITY"]; - case "sizing": - return ["WIDTH_HEIGHT"]; - default: - return []; - } - } + private getScopesByType(token: SingleToken): FigmaScope[] { + switch (token.type) { + case 'color': + return ['ALL_FILLS', 'STROKE_COLOR', 'EFFECT_COLOR']; + case 'dimension': + return [ + 'GAP', + 'WIDTH_HEIGHT', + 'CORNER_RADIUS', + 'STROKE_FLOAT', + 'EFFECT_FLOAT', + 'PARAGRAPH_INDENT' + ]; + case 'spacing': + return ['GAP', 'WIDTH_HEIGHT']; + case 'borderRadius': + return ['CORNER_RADIUS']; + case 'fontFamilies': + return ['FONT_FAMILY']; + case 'fontWeights': + return ['FONT_WEIGHT']; + case 'fontSizes': + return ['FONT_SIZE']; + case 'lineHeights': + return ['LINE_HEIGHT']; + case 'letterSpacing': + return ['LETTER_SPACING']; + case 'paragraphSpacing': + return ['PARAGRAPH_SPACING']; + case 'opacity': + return ['OPACITY']; + case 'sizing': + return ['WIDTH_HEIGHT']; + default: + return []; + } + } - execute(): void | Promise { - const { token } = this.getAllInputs(); - const newScopes = this.getScopesByType(token); + execute(): void | Promise { + const { token } = this.getAllInputs(); + const newScopes = this.getScopesByType(token); - const modifiedToken = mergeTokenExtensions(token, { - scopes: newScopes, - }); + const modifiedToken = mergeTokenExtensions(token, { + scopes: newScopes + }); - this.outputs.token.set(modifiedToken); - } + this.outputs.token.set(modifiedToken); + } } diff --git a/packages/nodes-figma/src/nodes/scopeColor.ts b/packages/nodes-figma/src/nodes/scopeColor.ts index 3a2a55331..74e32d2bd 100644 --- a/packages/nodes-figma/src/nodes/scopeColor.ts +++ b/packages/nodes-figma/src/nodes/scopeColor.ts @@ -1,112 +1,112 @@ import { - BooleanSchema, - INodeDefinition, - Node, - ToInput, - ToOutput, -} from "@tokens-studio/graph-engine"; -import { FigmaScope } from "../types/scopes.js"; -import { SingleToken } from "@tokens-studio/types"; -import { TokenSchema } from "@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js"; -import { mergeTokenExtensions } from "../utils/tokenMerge.js"; + BooleanSchema, + INodeDefinition, + Node, + ToInput, + ToOutput +} from '@tokens-studio/graph-engine'; +import { FigmaScope } from '../types/scopes.js'; +import { SingleToken } from '@tokens-studio/types'; +import { TokenSchema } from '@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js'; +import { mergeTokenExtensions } from '../utils/tokenMerge.js'; export default class NodeDefinition extends Node { - static title = "Scope Color"; - static type = "studio.tokens.figma.scopeColor"; - static description = "Defines color variable scopes for Figma"; + static title = 'Scope Color'; + static type = 'studio.tokens.figma.scopeColor'; + static description = 'Defines color variable scopes for Figma'; - declare inputs: ToInput<{ - token: SingleToken; - allFills: boolean; - effects: boolean; - frameFill: boolean; - shapeFill: boolean; - stroke: boolean; - textFill: boolean; - }>; - declare outputs: ToOutput<{ - token: SingleToken; - }>; + declare inputs: ToInput<{ + token: SingleToken; + allFills: boolean; + effects: boolean; + frameFill: boolean; + shapeFill: boolean; + stroke: boolean; + textFill: boolean; + }>; + declare outputs: ToOutput<{ + token: SingleToken; + }>; - constructor(props: INodeDefinition) { - super(props); + constructor(props: INodeDefinition) { + super(props); - this.addInput("token", { - type: { - ...TokenSchema, - description: "The design token to add scopes to", - }, - }); + this.addInput('token', { + type: { + ...TokenSchema, + description: 'The design token to add scopes to' + } + }); - this.addInput("allFills", { - type: { - ...BooleanSchema, - default: false, - description: "Include all fills scope", - }, - }); + this.addInput('allFills', { + type: { + ...BooleanSchema, + default: false, + description: 'Include all fills scope' + } + }); - this.addInput("effects", { - type: { - ...BooleanSchema, - default: false, - description: "Include effects scope", - }, - }); + this.addInput('effects', { + type: { + ...BooleanSchema, + default: false, + description: 'Include effects scope' + } + }); - this.addInput("frameFill", { - type: { - ...BooleanSchema, - default: false, - description: "Include frame fill scope", - }, - }); + this.addInput('frameFill', { + type: { + ...BooleanSchema, + default: false, + description: 'Include frame fill scope' + } + }); - this.addInput("shapeFill", { - type: { - ...BooleanSchema, - default: false, - description: "Include shape fill scope", - }, - }); + this.addInput('shapeFill', { + type: { + ...BooleanSchema, + default: false, + description: 'Include shape fill scope' + } + }); - this.addInput("stroke", { - type: { - ...BooleanSchema, - default: false, - description: "Include stroke scope", - }, - }); + this.addInput('stroke', { + type: { + ...BooleanSchema, + default: false, + description: 'Include stroke scope' + } + }); - this.addInput("textFill", { - type: { - ...BooleanSchema, - default: false, - description: "Include text fill scope", - }, - }); + this.addInput('textFill', { + type: { + ...BooleanSchema, + default: false, + description: 'Include text fill scope' + } + }); - this.addOutput("token", { - type: TokenSchema, - }); - } + this.addOutput('token', { + type: TokenSchema + }); + } - execute(): void | Promise { - const inputs = this.getAllInputs(); - const newScopes: FigmaScope[] = []; + execute(): void | Promise { + const inputs = this.getAllInputs(); + const newScopes: FigmaScope[] = []; - // Map inputs to corresponding scopes - if (inputs.allFills) newScopes.push("ALL_FILLS"); - if (inputs.effects) newScopes.push("EFFECT_COLOR"); - if (inputs.frameFill) newScopes.push("FRAME_FILL"); - if (inputs.shapeFill) newScopes.push("SHAPE_FILL"); - if (inputs.stroke) newScopes.push("STROKE_COLOR"); - if (inputs.textFill) newScopes.push("TEXT_FILL"); + // Map inputs to corresponding scopes + if (inputs.allFills) newScopes.push('ALL_FILLS'); + if (inputs.effects) newScopes.push('EFFECT_COLOR'); + if (inputs.frameFill) newScopes.push('FRAME_FILL'); + if (inputs.shapeFill) newScopes.push('SHAPE_FILL'); + if (inputs.stroke) newScopes.push('STROKE_COLOR'); + if (inputs.textFill) newScopes.push('TEXT_FILL'); - const modifiedToken = mergeTokenExtensions(inputs.token, { - scopes: newScopes, - }); + const modifiedToken = mergeTokenExtensions(inputs.token, { + scopes: newScopes + }); - this.outputs.token.set(modifiedToken); - } + this.outputs.token.set(modifiedToken); + } } diff --git a/packages/nodes-figma/src/nodes/scopeNumber.ts b/packages/nodes-figma/src/nodes/scopeNumber.ts index 0134dc953..5da09ce71 100644 --- a/packages/nodes-figma/src/nodes/scopeNumber.ts +++ b/packages/nodes-figma/src/nodes/scopeNumber.ts @@ -1,192 +1,192 @@ import { - BooleanSchema, - INodeDefinition, - Node, - ToInput, - ToOutput, -} from "@tokens-studio/graph-engine"; -import { FigmaScope } from "../types/scopes.js"; -import { SingleToken } from "@tokens-studio/types"; -import { TokenSchema } from "@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js"; -import { mergeTokenExtensions } from "../utils/tokenMerge.js"; + BooleanSchema, + INodeDefinition, + Node, + ToInput, + ToOutput +} from '@tokens-studio/graph-engine'; +import { FigmaScope } from '../types/scopes.js'; +import { SingleToken } from '@tokens-studio/types'; +import { TokenSchema } from '@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js'; +import { mergeTokenExtensions } from '../utils/tokenMerge.js'; export default class NodeDefinition extends Node { - static title = "Scope Number"; - static type = "studio.tokens.figma.scopeNumber"; - static description = "Defines number/float variable scopes for Figma"; - - declare inputs: ToInput<{ - token: SingleToken; - gapBetween: boolean; - padding: boolean; - cornerRadius: boolean; - fontProperties: boolean; - fontWeight: boolean; - fontSize: boolean; - lineHeight: boolean; - letterSpacing: boolean; - paragraphSpacing: boolean; - paragraphIndent: boolean; - layerOpacity: boolean; - effects: boolean; - stroke: boolean; - textContent: boolean; - widthAndHeight: boolean; - }>; - declare outputs: ToOutput<{ - token: SingleToken; - }>; - - constructor(props: INodeDefinition) { - super(props); - - this.addInput("token", { - type: { - ...TokenSchema, - description: "The design token to add scopes to", - }, - }); - - this.addInput("gapBetween", { - type: { - ...BooleanSchema, - default: false, - description: "Include gap between scope", - }, - }); - - this.addInput("padding", { - type: { - ...BooleanSchema, - default: false, - description: "Include padding scope", - }, - }); - - this.addInput("cornerRadius", { - type: { - ...BooleanSchema, - default: false, - description: "Include corner radius scope", - }, - }); - - this.addInput("fontWeight", { - type: { - ...BooleanSchema, - default: false, - description: "Include font weight scope", - }, - }); - - this.addInput("fontSize", { - type: { - ...BooleanSchema, - default: false, - description: "Include font size scope", - }, - }); - - this.addInput("lineHeight", { - type: { - ...BooleanSchema, - default: false, - description: "Include line height scope", - }, - }); - - this.addInput("letterSpacing", { - type: { - ...BooleanSchema, - default: false, - description: "Include letter spacing scope", - }, - }); - - this.addInput("paragraphSpacing", { - type: { - ...BooleanSchema, - default: false, - description: "Include paragraph spacing scope", - }, - }); - - this.addInput("paragraphIndent", { - type: { - ...BooleanSchema, - default: false, - description: "Include paragraph indent scope", - }, - }); - - this.addInput("layerOpacity", { - type: { - ...BooleanSchema, - default: false, - description: "Include layer opacity scope", - }, - }); - - this.addInput("effects", { - type: { - ...BooleanSchema, - default: false, - description: "Include effects scope", - }, - }); - - this.addInput("stroke", { - type: { - ...BooleanSchema, - default: false, - description: "Include stroke scope", - }, - }); - - this.addInput("textContent", { - type: { - ...BooleanSchema, - default: false, - description: "Include text content scope", - }, - }); - - this.addInput("widthAndHeight", { - type: { - ...BooleanSchema, - default: false, - description: "Include width and height scope", - }, - }); - - this.addOutput("token", { - type: TokenSchema, - }); - } - - execute(): void | Promise { - const inputs = this.getAllInputs(); - const newScopes: FigmaScope[] = []; - - // Map inputs to corresponding scopes - if (inputs.gapBetween) newScopes.push("GAP"); - if (inputs.cornerRadius) newScopes.push("CORNER_RADIUS"); - if (inputs.widthAndHeight) newScopes.push("WIDTH_HEIGHT"); - if (inputs.layerOpacity) newScopes.push("OPACITY"); - if (inputs.effects) newScopes.push("EFFECT_FLOAT"); - if (inputs.stroke) newScopes.push("STROKE_FLOAT"); - if (inputs.textContent) newScopes.push("TEXT_CONTENT"); - if (inputs.fontWeight) newScopes.push("FONT_WEIGHT"); - if (inputs.fontSize) newScopes.push("FONT_SIZE"); - if (inputs.lineHeight) newScopes.push("LINE_HEIGHT"); - if (inputs.letterSpacing) newScopes.push("LETTER_SPACING"); - if (inputs.paragraphSpacing) newScopes.push("PARAGRAPH_SPACING"); - if (inputs.paragraphIndent) newScopes.push("PARAGRAPH_INDENT"); - - const modifiedToken = mergeTokenExtensions(inputs.token, { - scopes: newScopes, - }); - - this.outputs.token.set(modifiedToken); - } + static title = 'Scope Number'; + static type = 'studio.tokens.figma.scopeNumber'; + static description = 'Defines number/float variable scopes for Figma'; + + declare inputs: ToInput<{ + token: SingleToken; + gapBetween: boolean; + padding: boolean; + cornerRadius: boolean; + fontProperties: boolean; + fontWeight: boolean; + fontSize: boolean; + lineHeight: boolean; + letterSpacing: boolean; + paragraphSpacing: boolean; + paragraphIndent: boolean; + layerOpacity: boolean; + effects: boolean; + stroke: boolean; + textContent: boolean; + widthAndHeight: boolean; + }>; + declare outputs: ToOutput<{ + token: SingleToken; + }>; + + constructor(props: INodeDefinition) { + super(props); + + this.addInput('token', { + type: { + ...TokenSchema, + description: 'The design token to add scopes to' + } + }); + + this.addInput('gapBetween', { + type: { + ...BooleanSchema, + default: false, + description: 'Include gap between scope' + } + }); + + this.addInput('padding', { + type: { + ...BooleanSchema, + default: false, + description: 'Include padding scope' + } + }); + + this.addInput('cornerRadius', { + type: { + ...BooleanSchema, + default: false, + description: 'Include corner radius scope' + } + }); + + this.addInput('fontWeight', { + type: { + ...BooleanSchema, + default: false, + description: 'Include font weight scope' + } + }); + + this.addInput('fontSize', { + type: { + ...BooleanSchema, + default: false, + description: 'Include font size scope' + } + }); + + this.addInput('lineHeight', { + type: { + ...BooleanSchema, + default: false, + description: 'Include line height scope' + } + }); + + this.addInput('letterSpacing', { + type: { + ...BooleanSchema, + default: false, + description: 'Include letter spacing scope' + } + }); + + this.addInput('paragraphSpacing', { + type: { + ...BooleanSchema, + default: false, + description: 'Include paragraph spacing scope' + } + }); + + this.addInput('paragraphIndent', { + type: { + ...BooleanSchema, + default: false, + description: 'Include paragraph indent scope' + } + }); + + this.addInput('layerOpacity', { + type: { + ...BooleanSchema, + default: false, + description: 'Include layer opacity scope' + } + }); + + this.addInput('effects', { + type: { + ...BooleanSchema, + default: false, + description: 'Include effects scope' + } + }); + + this.addInput('stroke', { + type: { + ...BooleanSchema, + default: false, + description: 'Include stroke scope' + } + }); + + this.addInput('textContent', { + type: { + ...BooleanSchema, + default: false, + description: 'Include text content scope' + } + }); + + this.addInput('widthAndHeight', { + type: { + ...BooleanSchema, + default: false, + description: 'Include width and height scope' + } + }); + + this.addOutput('token', { + type: TokenSchema + }); + } + + execute(): void | Promise { + const inputs = this.getAllInputs(); + const newScopes: FigmaScope[] = []; + + // Map inputs to corresponding scopes + if (inputs.gapBetween) newScopes.push('GAP'); + if (inputs.cornerRadius) newScopes.push('CORNER_RADIUS'); + if (inputs.widthAndHeight) newScopes.push('WIDTH_HEIGHT'); + if (inputs.layerOpacity) newScopes.push('OPACITY'); + if (inputs.effects) newScopes.push('EFFECT_FLOAT'); + if (inputs.stroke) newScopes.push('STROKE_FLOAT'); + if (inputs.textContent) newScopes.push('TEXT_CONTENT'); + if (inputs.fontWeight) newScopes.push('FONT_WEIGHT'); + if (inputs.fontSize) newScopes.push('FONT_SIZE'); + if (inputs.lineHeight) newScopes.push('LINE_HEIGHT'); + if (inputs.letterSpacing) newScopes.push('LETTER_SPACING'); + if (inputs.paragraphSpacing) newScopes.push('PARAGRAPH_SPACING'); + if (inputs.paragraphIndent) newScopes.push('PARAGRAPH_INDENT'); + + const modifiedToken = mergeTokenExtensions(inputs.token, { + scopes: newScopes + }); + + this.outputs.token.set(modifiedToken); + } } diff --git a/packages/nodes-figma/src/nodes/scopeString.ts b/packages/nodes-figma/src/nodes/scopeString.ts index 95686bdd5..8e3c687db 100644 --- a/packages/nodes-figma/src/nodes/scopeString.ts +++ b/packages/nodes-figma/src/nodes/scopeString.ts @@ -1,82 +1,82 @@ import { - BooleanSchema, - INodeDefinition, - Node, - ToInput, - ToOutput, -} from "@tokens-studio/graph-engine"; -import { FigmaScope } from "../types/scopes.js"; -import { SingleToken } from "@tokens-studio/types"; -import { TokenSchema } from "@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js"; -import { mergeTokenExtensions } from "../utils/tokenMerge.js"; + BooleanSchema, + INodeDefinition, + Node, + ToInput, + ToOutput +} from '@tokens-studio/graph-engine'; +import { FigmaScope } from '../types/scopes.js'; +import { SingleToken } from '@tokens-studio/types'; +import { TokenSchema } from '@tokens-studio/graph-engine-nodes-design-tokens/schemas/index.js'; +import { mergeTokenExtensions } from '../utils/tokenMerge.js'; export default class NodeDefinition extends Node { - static title = "Scope String"; - static type = "studio.tokens.figma.scopeString"; - static description = "Defines string variable scopes for Figma"; + static title = 'Scope String'; + static type = 'studio.tokens.figma.scopeString'; + static description = 'Defines string variable scopes for Figma'; - declare inputs: ToInput<{ - token: SingleToken; - fontFamily: boolean; - fontStyle: boolean; - textContent: boolean; - }>; - declare outputs: ToOutput<{ - token: SingleToken; - }>; + declare inputs: ToInput<{ + token: SingleToken; + fontFamily: boolean; + fontStyle: boolean; + textContent: boolean; + }>; + declare outputs: ToOutput<{ + token: SingleToken; + }>; - constructor(props: INodeDefinition) { - super(props); + constructor(props: INodeDefinition) { + super(props); - this.addInput("token", { - type: { - ...TokenSchema, - description: "The design token to add scopes to", - }, - }); + this.addInput('token', { + type: { + ...TokenSchema, + description: 'The design token to add scopes to' + } + }); - this.addInput("fontFamily", { - type: { - ...BooleanSchema, - default: false, - description: "Include font family scope", - }, - }); + this.addInput('fontFamily', { + type: { + ...BooleanSchema, + default: false, + description: 'Include font family scope' + } + }); - this.addInput("fontStyle", { - type: { - ...BooleanSchema, - default: false, - description: "Include font weight or style scope", - }, - }); + this.addInput('fontStyle', { + type: { + ...BooleanSchema, + default: false, + description: 'Include font weight or style scope' + } + }); - this.addInput("textContent", { - type: { - ...BooleanSchema, - default: false, - description: "Include text content scope", - }, - }); + this.addInput('textContent', { + type: { + ...BooleanSchema, + default: false, + description: 'Include text content scope' + } + }); - this.addOutput("token", { - type: TokenSchema, - }); - } + this.addOutput('token', { + type: TokenSchema + }); + } - execute(): void | Promise { - const inputs = this.getAllInputs(); - const newScopes: FigmaScope[] = []; + execute(): void | Promise { + const inputs = this.getAllInputs(); + const newScopes: FigmaScope[] = []; - // Map inputs to corresponding scopes - if (inputs.fontFamily) newScopes.push("FONT_FAMILY"); - if (inputs.fontStyle) newScopes.push("FONT_STYLE"); - if (inputs.textContent) newScopes.push("TEXT_CONTENT"); + // Map inputs to corresponding scopes + if (inputs.fontFamily) newScopes.push('FONT_FAMILY'); + if (inputs.fontStyle) newScopes.push('FONT_STYLE'); + if (inputs.textContent) newScopes.push('TEXT_CONTENT'); - const modifiedToken = mergeTokenExtensions(inputs.token, { - scopes: newScopes, - }); + const modifiedToken = mergeTokenExtensions(inputs.token, { + scopes: newScopes + }); - this.outputs.token.set(modifiedToken); - } + this.outputs.token.set(modifiedToken); + } } diff --git a/packages/nodes-figma/src/schemas/utils.ts b/packages/nodes-figma/src/schemas/utils.ts index 380ffcf40..65d8b6696 100644 --- a/packages/nodes-figma/src/schemas/utils.ts +++ b/packages/nodes-figma/src/schemas/utils.ts @@ -1,4 +1,4 @@ -export const arrayOf = (type) => ({ - type: "array", - items: type, +export const arrayOf = type => ({ + type: 'array', + items: type }); diff --git a/packages/nodes-figma/src/types/scopes.ts b/packages/nodes-figma/src/types/scopes.ts index f9bc4db5f..440967ddf 100644 --- a/packages/nodes-figma/src/types/scopes.ts +++ b/packages/nodes-figma/src/types/scopes.ts @@ -1,54 +1,54 @@ export type FigmaScope = - | "ALL_SCOPES" - | "TEXT_CONTENT" - | "CORNER_RADIUS" - | "WIDTH_HEIGHT" - | "GAP" - | "ALL_FILLS" - | "FRAME_FILL" - | "SHAPE_FILL" - | "TEXT_FILL" - | "STROKE_COLOR" - | "EFFECT_COLOR" - | "STROKE_FLOAT" - | "EFFECT_FLOAT" - | "OPACITY" - | "FONT_FAMILY" - | "FONT_STYLE" - | "FONT_WEIGHT" - | "FONT_SIZE" - | "LINE_HEIGHT" - | "LETTER_SPACING" - | "PARAGRAPH_SPACING" - | "PARAGRAPH_INDENT"; + | 'ALL_SCOPES' + | 'TEXT_CONTENT' + | 'CORNER_RADIUS' + | 'WIDTH_HEIGHT' + | 'GAP' + | 'ALL_FILLS' + | 'FRAME_FILL' + | 'SHAPE_FILL' + | 'TEXT_FILL' + | 'STROKE_COLOR' + | 'EFFECT_COLOR' + | 'STROKE_FLOAT' + | 'EFFECT_FLOAT' + | 'OPACITY' + | 'FONT_FAMILY' + | 'FONT_STYLE' + | 'FONT_WEIGHT' + | 'FONT_SIZE' + | 'LINE_HEIGHT' + | 'LETTER_SPACING' + | 'PARAGRAPH_SPACING' + | 'PARAGRAPH_INDENT'; export const FLOAT_SCOPES: FigmaScope[] = [ - "TEXT_CONTENT", - "CORNER_RADIUS", - "WIDTH_HEIGHT", - "GAP", - "OPACITY", - "STROKE_FLOAT", - "EFFECT_FLOAT", - "FONT_WEIGHT", - "FONT_SIZE", - "LINE_HEIGHT", - "LETTER_SPACING", - "PARAGRAPH_SPACING", - "PARAGRAPH_INDENT", + 'TEXT_CONTENT', + 'CORNER_RADIUS', + 'WIDTH_HEIGHT', + 'GAP', + 'OPACITY', + 'STROKE_FLOAT', + 'EFFECT_FLOAT', + 'FONT_WEIGHT', + 'FONT_SIZE', + 'LINE_HEIGHT', + 'LETTER_SPACING', + 'PARAGRAPH_SPACING', + 'PARAGRAPH_INDENT' ]; export const COLOR_SCOPES: FigmaScope[] = [ - "ALL_FILLS", - "FRAME_FILL", - "SHAPE_FILL", - "TEXT_FILL", - "STROKE_COLOR", - "EFFECT_COLOR", + 'ALL_FILLS', + 'FRAME_FILL', + 'SHAPE_FILL', + 'TEXT_FILL', + 'STROKE_COLOR', + 'EFFECT_COLOR' ]; export const STRING_SCOPES: FigmaScope[] = [ - "TEXT_CONTENT", - "FONT_FAMILY", - "FONT_STYLE", + 'TEXT_CONTENT', + 'FONT_FAMILY', + 'FONT_STYLE' ]; diff --git a/packages/nodes-figma/src/utils/tokenMerge.ts b/packages/nodes-figma/src/utils/tokenMerge.ts index c292b3351..12cdfd479 100644 --- a/packages/nodes-figma/src/utils/tokenMerge.ts +++ b/packages/nodes-figma/src/utils/tokenMerge.ts @@ -1,47 +1,47 @@ -import { SingleToken } from "@tokens-studio/types"; +import { SingleToken } from '@tokens-studio/types'; type DeepPartial = { - [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; + [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; }; interface FigmaExtension { - hiddenFromPublishing?: boolean; - codeSyntax?: Record; - scopes?: string[]; - [key: string]: unknown; + hiddenFromPublishing?: boolean; + codeSyntax?: Record; + scopes?: string[]; + [key: string]: unknown; } export function mergeTokenExtensions( - token: SingleToken, - figmaExtension: DeepPartial, + token: SingleToken, + figmaExtension: DeepPartial ): SingleToken { - const existingExtensions = token.$extensions || {}; - const existingFigmaExt = existingExtensions["com.figma"] || {}; + const existingExtensions = token.$extensions || {}; + const existingFigmaExt = existingExtensions['com.figma'] || {}; - const mergedFigmaExt = { - ...existingFigmaExt, - ...figmaExtension, - ...(figmaExtension.codeSyntax && { - codeSyntax: { - ...existingFigmaExt.codeSyntax, - ...figmaExtension.codeSyntax, - }, - }), - ...(figmaExtension.scopes && { - scopes: [ - ...new Set([ - ...(existingFigmaExt.scopes || []), - ...(figmaExtension.scopes || []), - ]), - ], - }), - }; + const mergedFigmaExt = { + ...existingFigmaExt, + ...figmaExtension, + ...(figmaExtension.codeSyntax && { + codeSyntax: { + ...existingFigmaExt.codeSyntax, + ...figmaExtension.codeSyntax + } + }), + ...(figmaExtension.scopes && { + scopes: [ + ...new Set([ + ...(existingFigmaExt.scopes || []), + ...(figmaExtension.scopes || []) + ]) + ] + }) + }; - return { - ...token, - $extensions: { - ...existingExtensions, - "com.figma": mergedFigmaExt, - }, - } as unknown as SingleToken; + return { + ...token, + $extensions: { + ...existingExtensions, + 'com.figma': mergedFigmaExt + } + } as unknown as SingleToken; } diff --git a/packages/nodes-figma/tests/codeSyntax.test.ts b/packages/nodes-figma/tests/codeSyntax.test.ts index afed26a41..dadb7f31d 100644 --- a/packages/nodes-figma/tests/codeSyntax.test.ts +++ b/packages/nodes-figma/tests/codeSyntax.test.ts @@ -1,102 +1,102 @@ -import { Graph } from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { describe, expect, test } from "vitest"; -import Node from "../src/nodes/codeSyntax.js"; +import { Graph } from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { describe, expect, test } from 'vitest'; +import Node from '../src/nodes/codeSyntax.js'; -describe("nodes/codeSyntax", () => { - test("adds code syntax to token without existing extensions", async () => { - const graph = new Graph(); - const node = new Node({ graph }); +describe('nodes/codeSyntax', () => { + test('adds code syntax to token without existing extensions', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; - node.inputs.token.setValue(mockToken); - node.inputs.web.setValue("var(--test)"); - node.inputs.android.setValue("@test"); - node.inputs.ios.setValue("test"); + node.inputs.token.setValue(mockToken); + node.inputs.web.setValue('var(--test)'); + node.inputs.android.setValue('@test'); + node.inputs.ios.setValue('test'); - await node.execute(); + await node.execute(); - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - hiddenFromPublishing: false, - codeSyntax: { - Web: "var(--test)", - Android: "@test", - iOS: "test", - }, - }, - }, - }); - }); + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + hiddenFromPublishing: false, + codeSyntax: { + Web: 'var(--test)', + Android: '@test', + iOS: 'test' + } + } + } + }); + }); - test("preserves existing extensions and merges code syntax", async () => { - const graph = new Graph(); - const node = new Node({ graph }); + test('preserves existing extensions and merges code syntax', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - $extensions: { - "com.figma": { - codeSyntax: { - Web: "existing", - Android: "existing", - iOS: "existing", - }, - otherProp: true, - }, - }, - } as unknown as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color', + $extensions: { + 'com.figma': { + codeSyntax: { + Web: 'existing', + Android: 'existing', + iOS: 'existing' + }, + otherProp: true + } + } + } as unknown as SingleToken; - node.inputs.token.setValue(mockToken); - node.inputs.web.setValue("new"); - node.inputs.android.setValue("new"); + node.inputs.token.setValue(mockToken); + node.inputs.web.setValue('new'); + node.inputs.android.setValue('new'); - await node.execute(); + await node.execute(); - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - hiddenFromPublishing: false, - codeSyntax: { - Web: "new", - Android: "new", - iOS: "existing", - }, - otherProp: true, - }, - }, - }); - }); + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + hiddenFromPublishing: false, + codeSyntax: { + Web: 'new', + Android: 'new', + iOS: 'existing' + }, + otherProp: true + } + } + }); + }); - test("handles empty string inputs", async () => { - const graph = new Graph(); - const node = new Node({ graph }); + test('handles empty string inputs', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; - node.inputs.token.setValue(mockToken); - node.inputs.web.setValue(""); - node.inputs.android.setValue(""); - node.inputs.ios.setValue(""); + node.inputs.token.setValue(mockToken); + node.inputs.web.setValue(''); + node.inputs.android.setValue(''); + node.inputs.ios.setValue(''); - await node.execute(); + await node.execute(); - expect( - node.outputs.token.value?.$extensions?.["com.figma"]?.codeSyntax, - ).toEqual({}); - }); + expect( + node.outputs.token.value?.$extensions?.['com.figma']?.codeSyntax + ).toEqual({}); + }); }); diff --git a/packages/nodes-figma/tests/publish.test.ts b/packages/nodes-figma/tests/publish.test.ts index d6a91e3e0..47a9489d6 100644 --- a/packages/nodes-figma/tests/publish.test.ts +++ b/packages/nodes-figma/tests/publish.test.ts @@ -1,93 +1,93 @@ -import { Graph } from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { describe, expect, test } from "vitest"; -import Node from "../src/nodes/publish.js"; +import { Graph } from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { describe, expect, test } from 'vitest'; +import Node from '../src/nodes/publish.js'; -describe("nodes/publish", () => { - test("sets token to be published", async () => { - const graph = new Graph(); - const node = new Node({ graph }); +describe('nodes/publish', () => { + test('sets token to be published', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; - node.inputs.token.setValue(mockToken); - node.inputs.publish.setValue(true); + node.inputs.token.setValue(mockToken); + node.inputs.publish.setValue(true); - await node.execute(); + await node.execute(); - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - hiddenFromPublishing: false, - }, - }, - }); - }); + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + hiddenFromPublishing: false + } + } + }); + }); - test("sets token to be hidden", async () => { - const graph = new Graph(); - const node = new Node({ graph }); + test('sets token to be hidden', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; - node.inputs.token.setValue(mockToken); - node.inputs.publish.setValue(false); + node.inputs.token.setValue(mockToken); + node.inputs.publish.setValue(false); - await node.execute(); + await node.execute(); - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - hiddenFromPublishing: true, - }, - }, - }); - }); + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + hiddenFromPublishing: true + } + } + }); + }); - test("preserves existing extensions", async () => { - const graph = new Graph(); - const node = new Node({ graph }); + test('preserves existing extensions', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - $extensions: { - "com.figma": { - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - } as unknown as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color', + $extensions: { + 'com.figma': { + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + } as unknown as SingleToken; - node.inputs.token.setValue(mockToken); - node.inputs.publish.setValue(true); + node.inputs.token.setValue(mockToken); + node.inputs.publish.setValue(true); - await node.execute(); + await node.execute(); - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - otherProp: true, - hiddenFromPublishing: false, - }, - "other.extension": { - someProp: "value", - }, - }, - }); - }); + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + otherProp: true, + hiddenFromPublishing: false + }, + 'other.extension': { + someProp: 'value' + } + } + }); + }); }); diff --git a/packages/nodes-figma/tests/scopeAll.test.ts b/packages/nodes-figma/tests/scopeAll.test.ts index b89c54e37..473a2d2ff 100644 --- a/packages/nodes-figma/tests/scopeAll.test.ts +++ b/packages/nodes-figma/tests/scopeAll.test.ts @@ -1,93 +1,93 @@ -import { Graph } from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { describe, expect, test } from "vitest"; -import Node from "../src/nodes/scopeAll.js"; +import { Graph } from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { describe, expect, test } from 'vitest'; +import Node from '../src/nodes/scopeAll.js'; -describe("nodes/scopeAll", () => { - test("adds ALL_SCOPES to token without existing scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); +describe('nodes/scopeAll', () => { + test('adds ALL_SCOPES to token without existing scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; - node.inputs.token.setValue(mockToken); - await node.execute(); + node.inputs.token.setValue(mockToken); + await node.execute(); - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["ALL_SCOPES"], - }, - }, - }); - }); + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['ALL_SCOPES'] + } + } + }); + }); - test("preserves existing ALL_SCOPES", async () => { - const graph = new Graph(); - const node = new Node({ graph }); + test('preserves existing ALL_SCOPES', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - $extensions: { - "com.figma": { - scopes: ["ALL_SCOPES"], - }, - }, - } as unknown as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color', + $extensions: { + 'com.figma': { + scopes: ['ALL_SCOPES'] + } + } + } as unknown as SingleToken; - node.inputs.token.setValue(mockToken); - await node.execute(); + node.inputs.token.setValue(mockToken); + await node.execute(); - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["ALL_SCOPES"], - }, - }, - }); - }); + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['ALL_SCOPES'] + } + } + }); + }); - test("preserves existing scopes and extensions", async () => { - const graph = new Graph(); - const node = new Node({ graph }); + test('preserves existing scopes and extensions', async () => { + const graph = new Graph(); + const node = new Node({ graph }); - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - $extensions: { - "com.figma": { - scopes: ["TEXT_FILL", "STROKE"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - } as unknown as SingleToken; + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color', + $extensions: { + 'com.figma': { + scopes: ['TEXT_FILL', 'STROKE'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + } as unknown as SingleToken; - node.inputs.token.setValue(mockToken); - await node.execute(); + node.inputs.token.setValue(mockToken); + await node.execute(); - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["TEXT_FILL", "STROKE", "ALL_SCOPES"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - }); - }); + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['TEXT_FILL', 'STROKE', 'ALL_SCOPES'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + }); + }); }); diff --git a/packages/nodes-figma/tests/scopeByType.test.ts b/packages/nodes-figma/tests/scopeByType.test.ts index f9c57821c..86be9bcee 100644 --- a/packages/nodes-figma/tests/scopeByType.test.ts +++ b/packages/nodes-figma/tests/scopeByType.test.ts @@ -1,118 +1,118 @@ -import { Graph } from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { describe, expect, test } from "vitest"; -import Node from "../src/nodes/scopeByType.js"; - -describe("nodes/scopeByType", () => { - test("adds color scopes to color token", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["ALL_FILLS", "STROKE_COLOR", "EFFECT_COLOR"], - }, - }, - }); - }); - - test("adds dimension scopes to dimension token", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "16px", - type: "dimension", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: [ - "GAP", - "WIDTH_HEIGHT", - "CORNER_RADIUS", - "STROKE_FLOAT", - "EFFECT_FLOAT", - "PARAGRAPH_INDENT", - ], - }, - }, - }); - }); - - test("adds font-related scopes to typography tokens", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "Inter", - type: "fontFamilies", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["FONT_FAMILY"], - }, - }, - }); - }); - - test("preserves existing extensions and merges scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - $extensions: { - "com.figma": { - scopes: ["TEXT_FILL"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - } as unknown as SingleToken; - - node.inputs.token.setValue(mockToken); - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["TEXT_FILL", "ALL_FILLS", "STROKE_COLOR", "EFFECT_COLOR"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - }); - }); +import { Graph } from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { describe, expect, test } from 'vitest'; +import Node from '../src/nodes/scopeByType.js'; + +describe('nodes/scopeByType', () => { + test('adds color scopes to color token', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['ALL_FILLS', 'STROKE_COLOR', 'EFFECT_COLOR'] + } + } + }); + }); + + test('adds dimension scopes to dimension token', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '16px', + type: 'dimension' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: [ + 'GAP', + 'WIDTH_HEIGHT', + 'CORNER_RADIUS', + 'STROKE_FLOAT', + 'EFFECT_FLOAT', + 'PARAGRAPH_INDENT' + ] + } + } + }); + }); + + test('adds font-related scopes to typography tokens', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: 'Inter', + type: 'fontFamilies' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['FONT_FAMILY'] + } + } + }); + }); + + test('preserves existing extensions and merges scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color', + $extensions: { + 'com.figma': { + scopes: ['TEXT_FILL'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + } as unknown as SingleToken; + + node.inputs.token.setValue(mockToken); + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['TEXT_FILL', 'ALL_FILLS', 'STROKE_COLOR', 'EFFECT_COLOR'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + }); + }); }); diff --git a/packages/nodes-figma/tests/scopeColor.test.ts b/packages/nodes-figma/tests/scopeColor.test.ts index dcfdb23e3..b6a400628 100644 --- a/packages/nodes-figma/tests/scopeColor.test.ts +++ b/packages/nodes-figma/tests/scopeColor.test.ts @@ -1,154 +1,154 @@ -import { Graph } from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { describe, expect, test } from "vitest"; -import Node from "../src/nodes/scopeColor.js"; - -describe("nodes/scopeColor", () => { - test("adds single scope to token", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.textFill.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["TEXT_FILL"], - }, - }, - }); - }); - - test("adds multiple scopes to token", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.textFill.setValue(true); - node.inputs.stroke.setValue(true); - node.inputs.effects.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["EFFECT_COLOR", "STROKE_COLOR", "TEXT_FILL"], - }, - }, - }); - }); - - test("preserves existing scopes and extensions", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - $extensions: { - "com.figma": { - scopes: ["FRAME_FILL"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - } as unknown as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.textFill.setValue(true); - node.inputs.shapeFill.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["FRAME_FILL", "SHAPE_FILL", "TEXT_FILL"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - }); - }); - - test("avoids duplicate scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - $extensions: { - "com.figma": { - scopes: ["TEXT_FILL", "STROKE_COLOR"], - }, - }, - } as unknown as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.textFill.setValue(true); - node.inputs.stroke.setValue(true); - node.inputs.allFills.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["TEXT_FILL", "STROKE_COLOR", "ALL_FILLS"], - }, - }, - }); - }); - - test("handles all inputs being false", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "#ff0000", - type: "color", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - // All boolean inputs default to false - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: [], - }, - }, - }); - }); +import { Graph } from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { describe, expect, test } from 'vitest'; +import Node from '../src/nodes/scopeColor.js'; + +describe('nodes/scopeColor', () => { + test('adds single scope to token', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.textFill.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['TEXT_FILL'] + } + } + }); + }); + + test('adds multiple scopes to token', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.textFill.setValue(true); + node.inputs.stroke.setValue(true); + node.inputs.effects.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['EFFECT_COLOR', 'STROKE_COLOR', 'TEXT_FILL'] + } + } + }); + }); + + test('preserves existing scopes and extensions', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color', + $extensions: { + 'com.figma': { + scopes: ['FRAME_FILL'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + } as unknown as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.textFill.setValue(true); + node.inputs.shapeFill.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['FRAME_FILL', 'SHAPE_FILL', 'TEXT_FILL'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + }); + }); + + test('avoids duplicate scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color', + $extensions: { + 'com.figma': { + scopes: ['TEXT_FILL', 'STROKE_COLOR'] + } + } + } as unknown as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.textFill.setValue(true); + node.inputs.stroke.setValue(true); + node.inputs.allFills.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['TEXT_FILL', 'STROKE_COLOR', 'ALL_FILLS'] + } + } + }); + }); + + test('handles all inputs being false', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '#ff0000', + type: 'color' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + // All boolean inputs default to false + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: [] + } + } + }); + }); }); diff --git a/packages/nodes-figma/tests/scopeNumber.test.ts b/packages/nodes-figma/tests/scopeNumber.test.ts index 1c9e6ca93..6c80efcad 100644 --- a/packages/nodes-figma/tests/scopeNumber.test.ts +++ b/packages/nodes-figma/tests/scopeNumber.test.ts @@ -1,179 +1,179 @@ -import { Graph } from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { describe, expect, test } from "vitest"; -import Node from "../src/nodes/scopeNumber.js"; - -describe("nodes/scopeNumber", () => { - test("adds single scope to token", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "16", - type: "number", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.fontSize.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["FONT_SIZE"], - }, - }, - }); - }); - - test("adds multiple font-related scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "16", - type: "number", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.fontSize.setValue(true); - node.inputs.fontWeight.setValue(true); - node.inputs.lineHeight.setValue(true); - node.inputs.letterSpacing.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["FONT_WEIGHT", "FONT_SIZE", "LINE_HEIGHT", "LETTER_SPACING"], - }, - }, - }); - }); - - test("adds multiple layout-related scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "8", - type: "number", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.gapBetween.setValue(true); - node.inputs.padding.setValue(true); - node.inputs.cornerRadius.setValue(true); - node.inputs.widthAndHeight.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["GAP", "CORNER_RADIUS", "WIDTH_HEIGHT"], - }, - }, - }); - }); - - test("preserves existing scopes and extensions", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "16", - type: "number", - $extensions: { - "com.figma": { - scopes: ["OPACITY"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - } as unknown as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.fontSize.setValue(true); - node.inputs.lineHeight.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["OPACITY", "FONT_SIZE", "LINE_HEIGHT"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - }); - }); - - test("handles all effect and stroke scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "0.5", - type: "number", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.effects.setValue(true); - node.inputs.stroke.setValue(true); - node.inputs.layerOpacity.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["OPACITY", "EFFECT_FLOAT", "STROKE_FLOAT"], - }, - }, - }); - }); - - test("handles all paragraph-related scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "24", - type: "number", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.paragraphSpacing.setValue(true); - node.inputs.paragraphIndent.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["PARAGRAPH_SPACING", "PARAGRAPH_INDENT"], - }, - }, - }); - }); +import { Graph } from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { describe, expect, test } from 'vitest'; +import Node from '../src/nodes/scopeNumber.js'; + +describe('nodes/scopeNumber', () => { + test('adds single scope to token', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '16', + type: 'number' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.fontSize.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['FONT_SIZE'] + } + } + }); + }); + + test('adds multiple font-related scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '16', + type: 'number' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.fontSize.setValue(true); + node.inputs.fontWeight.setValue(true); + node.inputs.lineHeight.setValue(true); + node.inputs.letterSpacing.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['FONT_WEIGHT', 'FONT_SIZE', 'LINE_HEIGHT', 'LETTER_SPACING'] + } + } + }); + }); + + test('adds multiple layout-related scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '8', + type: 'number' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.gapBetween.setValue(true); + node.inputs.padding.setValue(true); + node.inputs.cornerRadius.setValue(true); + node.inputs.widthAndHeight.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['GAP', 'CORNER_RADIUS', 'WIDTH_HEIGHT'] + } + } + }); + }); + + test('preserves existing scopes and extensions', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '16', + type: 'number', + $extensions: { + 'com.figma': { + scopes: ['OPACITY'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + } as unknown as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.fontSize.setValue(true); + node.inputs.lineHeight.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['OPACITY', 'FONT_SIZE', 'LINE_HEIGHT'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + }); + }); + + test('handles all effect and stroke scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '0.5', + type: 'number' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.effects.setValue(true); + node.inputs.stroke.setValue(true); + node.inputs.layerOpacity.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['OPACITY', 'EFFECT_FLOAT', 'STROKE_FLOAT'] + } + } + }); + }); + + test('handles all paragraph-related scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: '24', + type: 'number' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.paragraphSpacing.setValue(true); + node.inputs.paragraphIndent.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['PARAGRAPH_SPACING', 'PARAGRAPH_INDENT'] + } + } + }); + }); }); diff --git a/packages/nodes-figma/tests/scopeString.test.ts b/packages/nodes-figma/tests/scopeString.test.ts index 412d9d085..c5c28f01c 100644 --- a/packages/nodes-figma/tests/scopeString.test.ts +++ b/packages/nodes-figma/tests/scopeString.test.ts @@ -1,147 +1,147 @@ -import { Graph } from "@tokens-studio/graph-engine"; -import { SingleToken } from "@tokens-studio/types"; -import { describe, expect, test } from "vitest"; -import Node from "../src/nodes/scopeString.js"; - -describe("nodes/scopeString", () => { - test("adds single font family scope", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "Inter", - type: "other", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.fontFamily.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["FONT_FAMILY"], - }, - }, - }); - }); - - test("adds multiple scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "Bold", - type: "other", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.fontStyle.setValue(true); - node.inputs.textContent.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["FONT_STYLE", "TEXT_CONTENT"], - }, - }, - }); - }); - - test("preserves existing scopes and extensions", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "Inter", - type: "other", - $extensions: { - "com.figma": { - scopes: ["TEXT_CONTENT"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - } as unknown as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.fontFamily.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["TEXT_CONTENT", "FONT_FAMILY"], - otherProp: true, - }, - "other.extension": { - someProp: "value", - }, - }, - }); - }); - - test("adds all string-related scopes", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "Inter", - type: "other", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - node.inputs.fontFamily.setValue(true); - node.inputs.fontStyle.setValue(true); - node.inputs.textContent.setValue(true); - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: ["FONT_FAMILY", "FONT_STYLE", "TEXT_CONTENT"], - }, - }, - }); - }); - - test("handles no scopes selected", async () => { - const graph = new Graph(); - const node = new Node({ graph }); - - const mockToken = { - name: "test", - value: "Inter", - type: "other", - } as SingleToken; - - node.inputs.token.setValue(mockToken); - // All boolean inputs default to false - - await node.execute(); - - expect(node.outputs.token.value).toEqual({ - ...mockToken, - $extensions: { - "com.figma": { - scopes: [], - }, - }, - }); - }); +import { Graph } from '@tokens-studio/graph-engine'; +import { SingleToken } from '@tokens-studio/types'; +import { describe, expect, test } from 'vitest'; +import Node from '../src/nodes/scopeString.js'; + +describe('nodes/scopeString', () => { + test('adds single font family scope', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: 'Inter', + type: 'other' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.fontFamily.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['FONT_FAMILY'] + } + } + }); + }); + + test('adds multiple scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: 'Bold', + type: 'other' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.fontStyle.setValue(true); + node.inputs.textContent.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['FONT_STYLE', 'TEXT_CONTENT'] + } + } + }); + }); + + test('preserves existing scopes and extensions', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: 'Inter', + type: 'other', + $extensions: { + 'com.figma': { + scopes: ['TEXT_CONTENT'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + } as unknown as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.fontFamily.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['TEXT_CONTENT', 'FONT_FAMILY'], + otherProp: true + }, + 'other.extension': { + someProp: 'value' + } + } + }); + }); + + test('adds all string-related scopes', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: 'Inter', + type: 'other' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + node.inputs.fontFamily.setValue(true); + node.inputs.fontStyle.setValue(true); + node.inputs.textContent.setValue(true); + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: ['FONT_FAMILY', 'FONT_STYLE', 'TEXT_CONTENT'] + } + } + }); + }); + + test('handles no scopes selected', async () => { + const graph = new Graph(); + const node = new Node({ graph }); + + const mockToken = { + name: 'test', + value: 'Inter', + type: 'other' + } as SingleToken; + + node.inputs.token.setValue(mockToken); + // All boolean inputs default to false + + await node.execute(); + + expect(node.outputs.token.value).toEqual({ + ...mockToken, + $extensions: { + 'com.figma': { + scopes: [] + } + } + }); + }); }); diff --git a/packages/nodes-figma/tsconfig.docs.json b/packages/nodes-figma/tsconfig.docs.json index 9c91cf965..296f7832a 100644 --- a/packages/nodes-figma/tsconfig.docs.json +++ b/packages/nodes-figma/tsconfig.docs.json @@ -1,8 +1,8 @@ { - "extends": "./tsconfig.json", - "compilerOptions": { - "skipLibCheck": true - }, - "include": ["src/**/*"], - "exclude": ["node_modules", "**/*.test.ts", "cypress/**"] + "extends": "./tsconfig.json", + "compilerOptions": { + "skipLibCheck": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "**/*.test.ts", "cypress/**"] } diff --git a/packages/nodes-figma/tsconfig.json b/packages/nodes-figma/tsconfig.json index 1b9296312..4d384307e 100644 --- a/packages/nodes-figma/tsconfig.json +++ b/packages/nodes-figma/tsconfig.json @@ -1,37 +1,37 @@ { - "$schema": "https://json.schemastore.org/tsconfig", - "include": ["src", "package.json"], - "exclude": ["cypress.config.ts", "cypress", "node_modules"], - "compilerOptions": { - "composite": false, - "declaration": true, - "declarationMap": true, - "esModuleInterop": true, - "moduleResolution": "NodeNext", - "forceConsistentCasingInFileNames": true, - "inlineSources": false, - "isolatedModules": true, - "noUnusedLocals": false, - "noUnusedParameters": false, - "preserveWatchOutput": true, - "preserveSymlinks": true, - "skipLibCheck": true, - "strict": true, - "jsx": "react", - "module": "NodeNext", - "target": "esnext", - "baseUrl": ".", - "paths": { - "@/*": ["src/*"] - }, - "noImplicitAny": false, - "rootDir": ".", - "experimentalDecorators": true, - "lib": ["esnext", "dom", "dom.iterable"], - "allowJs": true, - "sourceMap": true, - "resolveJsonModule": true, - "allowSyntheticDefaultImports": true, - "outDir": "dist" - } + "$schema": "https://json.schemastore.org/tsconfig", + "include": ["src", "package.json"], + "exclude": ["cypress.config.ts", "cypress", "node_modules"], + "compilerOptions": { + "composite": false, + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "moduleResolution": "NodeNext", + "forceConsistentCasingInFileNames": true, + "inlineSources": false, + "isolatedModules": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "preserveWatchOutput": true, + "preserveSymlinks": true, + "skipLibCheck": true, + "strict": true, + "jsx": "react", + "module": "NodeNext", + "target": "esnext", + "baseUrl": ".", + "paths": { + "@/*": ["src/*"] + }, + "noImplicitAny": false, + "rootDir": ".", + "experimentalDecorators": true, + "lib": ["esnext", "dom", "dom.iterable"], + "allowJs": true, + "sourceMap": true, + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, + "outDir": "dist" + } } diff --git a/packages/nodes-figma/tsconfig.prod.json b/packages/nodes-figma/tsconfig.prod.json index 267c4328e..fa79947ad 100644 --- a/packages/nodes-figma/tsconfig.prod.json +++ b/packages/nodes-figma/tsconfig.prod.json @@ -1,28 +1,28 @@ { - "extends": "./tsconfig.json", - "include": ["src"], - "compilerOptions": { - "incremental": true, - "rootDir": "src", - "module": "NodeNext", - "skipLibCheck": true, - "moduleResolution": "NodeNext", - "plugins": [ - { - "transform": "typescript-transform-paths" - }, - // Transform paths in output .d.ts files (Include this line if you output declarations files) - { - "transform": "typescript-transform-paths", - "afterDeclarations": true - } - ] - }, - "exclude": [ - "cypress.config.ts", - "cypress", - "node_modules", - "**/*.stories.tsx", - "**/*.cy.tsx" - ] + "extends": "./tsconfig.json", + "include": ["src"], + "compilerOptions": { + "incremental": true, + "rootDir": "src", + "module": "NodeNext", + "skipLibCheck": true, + "moduleResolution": "NodeNext", + "plugins": [ + { + "transform": "typescript-transform-paths" + }, + // Transform paths in output .d.ts files (Include this line if you output declarations files) + { + "transform": "typescript-transform-paths", + "afterDeclarations": true + } + ] + }, + "exclude": [ + "cypress.config.ts", + "cypress", + "node_modules", + "**/*.stories.tsx", + "**/*.cy.tsx" + ] } diff --git a/packages/nodes-figma/typedoc.json b/packages/nodes-figma/typedoc.json index 0fbe69517..de92babb7 100644 --- a/packages/nodes-figma/typedoc.json +++ b/packages/nodes-figma/typedoc.json @@ -1,11 +1,11 @@ { - "$schema": "https://typedoc.org/schema.json", - "tsconfig": "./tsconfig.docs.json", - "entryPoints": ["./src/index.ts", "./src/nodes/**/*.ts"], - "externalPattern": [ - "**/node_modules/**", - "src/nodes/*+(index|.spec|.e2e).ts" - ], - "excludeExternals": true, - "cleanOutputDir": true + "$schema": "https://typedoc.org/schema.json", + "tsconfig": "./tsconfig.docs.json", + "entryPoints": ["./src/index.ts", "./src/nodes/**/*.ts"], + "externalPattern": [ + "**/node_modules/**", + "src/nodes/*+(index|.spec|.e2e).ts" + ], + "excludeExternals": true, + "cleanOutputDir": true } diff --git a/packages/nodes-figma/vitest.config.ts b/packages/nodes-figma/vitest.config.ts index cf231a3b5..b7d791a74 100644 --- a/packages/nodes-figma/vitest.config.ts +++ b/packages/nodes-figma/vitest.config.ts @@ -1,8 +1,8 @@ -import { defineConfig } from "vitest/config"; +import { defineConfig } from 'vitest/config'; export default defineConfig({ - test: { - include: ["tests/**/*.test.[jt]s?(x)"], - globals: true, - }, + test: { + include: ['tests/**/*.test.[jt]s?(x)'], + globals: true + } }); From edda316289fd3973b8e4c63f7f4f4e3d47955621 Mon Sep 17 00:00:00 2001 From: Marco Christian Krenn Date: Tue, 17 Dec 2024 10:08:34 +0100 Subject: [PATCH 2/3] version bump, format --- packages/graph-editor/src/data/version.ts | 2 +- packages/ui/src/api/middleware.ts/auth.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/graph-editor/src/data/version.ts b/packages/graph-editor/src/data/version.ts index 0dea284ee..23911495f 100644 --- a/packages/graph-editor/src/data/version.ts +++ b/packages/graph-editor/src/data/version.ts @@ -1 +1 @@ -export const version = '4.3.4'; +export const version = '4.3.6'; diff --git a/packages/ui/src/api/middleware.ts/auth.ts b/packages/ui/src/api/middleware.ts/auth.ts index 9b09fa97f..c3e6252cf 100644 --- a/packages/ui/src/api/middleware.ts/auth.ts +++ b/packages/ui/src/api/middleware.ts/auth.ts @@ -15,7 +15,6 @@ export const authMiddleware = async ( } req.session = session; req.user = session.user!.id!; - //Ensure that the id can never be falsy if (!req.user) { From fe1ae294e982c10b98c0d7589cd4e5321218e954 Mon Sep 17 00:00:00 2001 From: Marco Christian Krenn Date: Tue, 17 Dec 2024 10:09:02 +0100 Subject: [PATCH 3/3] changeset --- .changeset/orange-panthers-occur.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/orange-panthers-occur.md diff --git a/.changeset/orange-panthers-occur.md b/.changeset/orange-panthers-occur.md new file mode 100644 index 000000000..ef1ab1505 --- /dev/null +++ b/.changeset/orange-panthers-occur.md @@ -0,0 +1,7 @@ +--- +"@tokens-studio/graph-editor": patch +"@tokens-studio/graph-engine-nodes-figma": patch +"@tokens-studio/graph-engine-ui": patch +--- + +fix prettier