Skip to content

Commit

Permalink
Fixes from CR
Browse files Browse the repository at this point in the history
  • Loading branch information
aweell committed Oct 8, 2024
1 parent d648f8c commit 9aab7ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 35 deletions.
4 changes: 2 additions & 2 deletions tokens/figma/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dotenv.config({ path: "../../.env" });

import { BRANDS } from "./utils/constants.mjs";

export const brands = {
export const BRAND_KEY = {
[BRANDS.MOVISTAR]: "ObNHOLPtrIytjy9BH7M9jW",
[BRANDS.O2_NEW]: "CjvgrHEIycSQ6exznxnFXT",
[BRANDS.VIVO_NEW]: "EApRpjaTyUOwW5VQU2ZqgP",
Expand All @@ -13,7 +13,7 @@ export const brands = {
[BRANDS.TU]: "19IXMaFqdYeC1IIdTwXBgY",
};

export const MIDDLEWARE_TOKEN =
export const MIDDLEWARE_KEY =
"w7fBxCsEb8WrMVVuxDnCQd";

export const FIGMA_TOKEN =
Expand Down
20 changes: 11 additions & 9 deletions tokens/figma/update-middleware.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ import {

import formatBrandName from "./utils/format-brand-name.mjs";

import { brands } from "./config.mjs";
import { MIDDLEWARE_TOKEN } from "./config.mjs";
import {
BRAND_KEY,
MIDDLEWARE_KEY,
} from "./config.mjs";

const brandNames = Object.keys(brands);
const brandNames = Object.keys(BRAND_KEY);

async function updateModeCollection(
jsonData,
brand
) {
try {
const figmaData = await getFigmaData(
MIDDLEWARE_TOKEN
MIDDLEWARE_KEY
);
const existingVariables =
figmaData.meta.variables;
Expand Down Expand Up @@ -196,7 +198,7 @@ async function updateModeCollection(

// Update the variables and modes in Figma
await postFigmaVariables(
MIDDLEWARE_TOKEN,
MIDDLEWARE_KEY,
newData
);

Expand All @@ -212,7 +214,7 @@ async function updateBrandCollection(jsonData) {
// Step 1: Fetch the existing data from Figma

const figmaData = await getFigmaData(
MIDDLEWARE_TOKEN
MIDDLEWARE_KEY
);
const existingCollections =
figmaData.meta.variableCollections;
Expand Down Expand Up @@ -469,7 +471,7 @@ async function updateBrandCollection(jsonData) {
// Step 9: Send the data to update the Brand collection (POST)

await postFigmaVariables(
MIDDLEWARE_TOKEN,
MIDDLEWARE_KEY,
newData
);

Expand All @@ -489,11 +491,11 @@ async function postCollections(brand) {
try {
const newData = await updateCollections(
collectionNames,
MIDDLEWARE_TOKEN
MIDDLEWARE_KEY
);

await postFigmaVariables(
MIDDLEWARE_TOKEN,
MIDDLEWARE_KEY,
newData
);
} catch (error) {
Expand Down
36 changes: 12 additions & 24 deletions tokens/figma/update-skins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ import {

import { getPaletteVariables } from "./variables.mjs";

import { brands } from "./config.mjs";
import { BRAND_KEY } from "./config.mjs";

const collectionNames = [
COLLECTION_NAMES.PALETTE,
];

async function updatePalette(
jsonData,
brand,
FILE_KEY
) {
async function updatePalette(jsonData, brand) {
const FILE_KEY = BRAND_KEY[brand];
try {
const figmaData = await getFigmaData(
FILE_KEY
Expand Down Expand Up @@ -107,7 +104,9 @@ async function updatePalette(
}
}

async function postCollections(brand, FILE_KEY) {
async function postCollections(brand) {
const FILE_KEY = BRAND_KEY[brand];

try {
const newData = await updateCollections(
collectionNames,
Expand All @@ -123,16 +122,12 @@ async function postCollections(brand, FILE_KEY) {
}
}

async function postPalette(
jsonData,
brand,
FILE_KEY
) {
async function postPalette(jsonData, brand) {
const FILE_KEY = BRAND_KEY[brand];
try {
const newData = await updatePalette(
jsonData,
brand,
FILE_KEY
brand
);

await postFigmaVariables(FILE_KEY, newData);
Expand All @@ -144,16 +139,9 @@ async function postPalette(
}
}

// Process data for a specific brand

async function processBrand(jsonData, brand) {
const FILE_KEY = brands[brand];
await postCollections(brand, FILE_KEY);
await postPalette(jsonData, brand, FILE_KEY);
}

export async function updateSkinFiles(jsonData) {
for (const brand of Object.keys(brands)) {
await processBrand(jsonData, brand);
for (const brand of Object.keys(BRAND_KEY)) {
await postCollections(brand);
await postPalette(jsonData, brand);
}
}

0 comments on commit 9aab7ac

Please sign in to comment.