/**
 * This util script is used to convert Figma's Token Studio JSON color config to TS file.
 *
 * CLI usage example:
 *  $ yarn figma-to-cunningham dark.json
 */
import fs from "fs";
import path from "path";

const filePath = process.argv[2];
const data = fs.readFileSync(filePath);
const json = JSON.parse(data.toString());
const output: any = {};

Object.keys(json).forEach((color) => {
  console.log("Parsing color:", color);
  Object.keys(json[color]).forEach((colorVariation) => {
    const colorName = color === "Succes" ? "success" : color.toLowerCase();
    output[colorName + "-" + colorVariation] =
      json[color][colorVariation].value;
  });
});
console.log("Output:", output);
const content = `/**
 * /!\\ Please do not edit this file directly. Instead use the FigmaToCunningham.ts converter that generated this file.
 */
export const colors = ${JSON.stringify(output)}
`;

const fileName = path.parse(filePath).name;
const outputPath = `./src/bin/ThemeColors/${fileName}.ts`;
fs.writeFileSync(outputPath, content);
console.log("Successfuly written to", outputPath);
