figgo
Version:
A CLI tool make your design tokens stay up to date with your Figma design styleguide
126 lines • 4.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = require("chalk");
const fs = require("fs");
const path_1 = require("path");
// save files
function saveColor(outDir, colors, type) {
if (colors !== undefined) {
switch (type) {
case "scss":
const scssDist = path_1.join(outDir, "_colorToken.scss");
fs.writeFileSync(scssDist, colors.join("\n"), "utf-8");
console.log(successLog(`🎨 Color tokens are updated at ${scssDist}`));
break;
case "js":
const jsDist = path_1.join(outDir, "colorToken.js");
fs.writeFileSync(jsDist, colors.join("\n"), "utf-8");
console.log(successLog(`🎨 Color tokens are updated at ${jsDist}`));
break;
default:
console.log(errorLog(`Format ${type} is not supported for color`));
break;
}
}
else {
console.log(errorLog("No color token is updated"));
}
}
exports.saveColor = saveColor;
function saveSpaces(outDir, spaces, type) {
if (spaces !== undefined) {
switch (type) {
case "scss":
const scssDist = path_1.join(outDir, "_spaceToken.scss");
fs.writeFileSync(scssDist, spaces.join("\n"), "utf-8");
console.log(successLog(`🛰 Spacing tokens are updated at ${scssDist}`));
break;
case "js":
const jsDist = path_1.join(outDir, "spaceToken.js");
fs.writeFileSync(jsDist, spaces.join("\n"), "utf-8");
console.log(successLog(`🛰 Spacing tokens are updated at ${jsDist}`));
break;
default:
console.log(successLog(`Format ${type} is not supported for spacing`));
break;
}
}
else {
console.log(errorLog("No spacing token is updated"));
}
}
exports.saveSpaces = saveSpaces;
function saveTypos(outDir, typos, type) {
if (typos !== undefined) {
switch (type) {
case "scss":
const scssDist = path_1.join(outDir, "_typoToken.scss");
fs.writeFileSync(scssDist, typos.join("\n"), "utf-8");
console.log(successLog(`✍️ Typography tokens are updated at ${scssDist}`));
break;
case "js":
const jsDist = path_1.join(outDir, "typoToken.js");
fs.writeFileSync(jsDist, typos.join("\n"), "utf-8");
console.log(successLog(`✍️ Typography tokens are updated at ${jsDist}`));
break;
default:
console.log(successLog(`Format ${type} is not supported for typography`));
break;
}
}
else {
console.log(errorLog("No typography token is updated"));
}
}
exports.saveTypos = saveTypos;
// covert float number to integer
function floatToInt(float) {
return Math.round(float * 255);
}
exports.floatToInt = floatToInt;
// convert interger to hex
function intToHex(int) {
let hex = Number(int).toString(16);
if (hex.length < 2) {
hex = `0${hex}`;
}
return hex;
}
exports.intToHex = intToHex;
// convert rgb color into a hex string
function rgbToHex(r, g, b) {
const rHex = intToHex(floatToInt(r));
const gHex = intToHex(floatToInt(g));
const bHex = intToHex(floatToInt(b));
return `#${rHex}${gHex}${bHex}`;
}
exports.rgbToHex = rgbToHex;
// convert rgba into a string
function rgbaToString(r, g, b, a) {
const rInt = floatToInt(r);
const gInt = floatToInt(g);
const bInt = floatToInt(b);
return `rgba(${rInt},${gInt},${bInt},${a.toFixed(2)})`;
}
exports.rgbaToString = rgbaToString;
function errorLog(log) {
const label = chalk_1.default.red("Error");
return `${label} ${log}`;
}
exports.errorLog = errorLog;
function successLog(log) {
const label = chalk_1.default.cyan("Success");
return `${label} ${log}`;
}
exports.successLog = successLog;
function warningLog(log) {
const label = chalk_1.default.yellow("Warning");
return `${label} ${log}`;
}
exports.warningLog = warningLog;
function urlFactory(id) {
const url = `https://www.figma.com/file/${id}`;
return url;
}
exports.urlFactory = urlFactory;
//# sourceMappingURL=helper.js.map