Skip to content

Commit

Permalink
track dist, resolve nonstrict errors
Browse files Browse the repository at this point in the history
  • Loading branch information
evwilkin committed Jun 8, 2024
1 parent 24fc55e commit 0d5a5b3
Show file tree
Hide file tree
Showing 7 changed files with 34,715 additions and 221 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build:docs": "yarn workspace @patternfly/design-tokens docs:build",
"build:fed:packages": "yarn workspace @patternfly/design-tokens build:fed:packages",
"build:scss": "yarn workspace @patternfly/design-tokens build:scss",
"build:plugin": "yarn workspace @patternfly/design-tokens build:plugin",
"start": "yarn build && concurrently --kill-others \"yarn workspace @patternfly/design-tokens docs:develop\"",
"serve:docs": "yarn workspace @patternfly/design-tokens docs:serve",
"clean": "yarn workspace @patternfly/design-tokens clean",
Expand Down
87 changes: 87 additions & 0 deletions packages/module/plugins/export-patternfly-tokens/dist/code.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34,204 changes: 34,204 additions & 0 deletions packages/module/plugins/export-patternfly-tokens/dist/ui.html

Large diffs are not rendered by default.

191 changes: 0 additions & 191 deletions packages/module/plugins/export-patternfly-tokens/export.html

This file was deleted.

28 changes: 20 additions & 8 deletions packages/module/plugins/export-patternfly-tokens/src/code.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
console.clear();

interface FileData {
fileName: string;
body: {
description?: string;
$type?: string;
$value?: any;
};
}

type VariableValueExtended = VariableValue & {
type?: string;
id?: string;
};

/* MAIN function */

figma.ui.onmessage = (e) => {
console.log('code received message', e);
if (e.type === 'IMPORT') {
const { selectedCollection, selectedMode, body } = e;
importJSONFile({ selectedCollection, selectedMode, body });
getExistingCollectionsAndModes();
} else if (e.type === 'EXPORT') {
if (e.type === 'EXPORT') {
exportToJSON();
}
};
Expand Down Expand Up @@ -38,7 +48,7 @@ function exportToJSON() {
function processCollection({ name, modes, variableIds }) {
const files = [];
modes.forEach((mode) => {
let file = { fileName: `${name}.${mode.name}.tokens.json`, body: {} };
let file: FileData = { fileName: `${name}.${mode.name}.tokens.json`, body: {} };

variableIds.forEach((variableId) => {
const { name, resolvedType, valuesByMode, description } = figma.variables.getVariableById(variableId);
Expand All @@ -47,7 +57,7 @@ function processCollection({ name, modes, variableIds }) {
return; // Skip this variable
}

const value = valuesByMode[mode.modeId];
const value: VariableValueExtended = valuesByMode[mode.modeId];

if (value !== undefined && ['COLOR', 'FLOAT', 'STRING'].includes(resolvedType)) {
let obj = file.body;
Expand All @@ -63,6 +73,7 @@ function processCollection({ name, modes, variableIds }) {
if (value.type === 'VARIABLE_ALIAS') {
obj.$type = resolvedType === 'COLOR' ? 'color' : 'number';
obj.$value = `{${figma.variables.getVariableById(value.id).name.replace(/\//g, '.')}}`;
console.log(value);
} else if (resolvedType === 'COLOR') {
obj.$type = 'color';
obj.$value = rgbToHex(value);
Expand All @@ -80,7 +91,8 @@ function processCollection({ name, modes, variableIds }) {
return files;
}

function rgbToHex({ r, g, b, a }) {
function rgbToHex(value) {
const { r, g, b, a } = value;
if (a !== 1) {
return `rgba(${[r, g, b].map((n) => Math.round(n * 255)).join(', ')}, ${a.toFixed(4)})`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const App = () => {
exportTokens();
// Listen for messages sent from the plugin code.ts file
window.onmessage = ({ data: { pluginMessage } }) => {
if (pluginMessage.type === 'EXPORT_RESULT') {
if (pluginMessage?.type === 'EXPORT_RESULT') {
// Reset download files
resetDownloads();
// Display all tokens in textarea
Expand Down
Loading

0 comments on commit 0d5a5b3

Please sign in to comment.