UNPKG

figgo

Version:

A CLI tool make your design tokens stay up to date with your Figma design styleguide

174 lines 6.37 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const enquirer_1 = require("enquirer"); const meow = require("meow"); const controller_1 = require("./controller"); const helper_1 = require("./helper"); const hint_1 = require("./hint"); const service_1 = require("./service"); const cli = meow(hint_1.hints, { flags: { help: { alias: "h", type: "boolean" }, version: { alias: "v", type: "boolean" }, list: { alias: "l", type: "boolean" }, sync: { alias: "s", type: "boolean" }, remove: { alias: "r", type: "string" }, init: { alias: "i", type: "boolean" } } }); const { input, flags } = cli; const controller = new controller_1.default(); if (flags.list) { console.log("Listing..."); const boards = controller.getBoards(); if (!controller.getStorage().isStorageDirExisted() && !controller.getStorage().isLocalConfigFileExisted()) { console.log(helper_1.errorLog("No boards is stored with Figgo")); } else { if (boards.length < 1) { console.log(helper_1.errorLog("No boards is stored with Figgo")); } else { boards.map((board, i) => console.log(` Board ${i + 1} Name: ${board.boardName} \n Token Directory: ${board.outputDir}\n Token Format: ${board.outputFormat}\n`)); } } } if (flags.sync) { if (!controller.getStorage().isLocalConfigFileExisted() && !controller.getStorage().isStorageDirExisted()) { console.log(helper_1.errorLog("No boards is stored with Figgo")); } else { console.log("Sync..."); if (input.length < 1) { const boards = controller.getBoards(); boards.forEach(board => { const { token, id, outputDir, outputFormat } = board; const colors = service_1.getColors(token, id, outputFormat); const spaces = service_1.getSpaces(token, id, outputFormat); const typos = service_1.getTypographics(token, id, outputFormat); colors .then(res => helper_1.saveColor(outputDir, res, outputFormat)) .catch(e => console.log(e)); spaces .then(res => helper_1.saveSpaces(outputDir, res, outputFormat)) .catch(e => console.log(e)); typos .then(res => helper_1.saveTypos(outputDir, res, outputFormat)) .catch(e => console.log(e)); }); } else { const boards = input.map(bn => controller.getBoard(bn)); boards.forEach(board => { const { token, id, outputDir, outputFormat } = board; const colors = service_1.getColors(token, id, outputFormat); const spaces = service_1.getSpaces(token, id, outputFormat); const typos = service_1.getTypographics(token, id, outputFormat); colors .then(res => helper_1.saveColor(outputDir, res, outputFormat)) .catch(e => console.log(e)); spaces .then(res => helper_1.saveSpaces(outputDir, res, outputFormat)) .catch(e => console.log(e)); typos .then(res => helper_1.saveTypos(outputDir, res, outputFormat)) .catch(e => console.log(e)); }); } } } if (flags.remove) { if (!controller.getStorage().isLocalConfigFileExisted() && !controller.getStorage().isConfigFileExisted()) { console.log(helper_1.errorLog("No boards is stored with Figgo")); } else { console.log(`Removing...`); controller.removeBoard(flags.remove); } } if (flags.init) { console.log("init..."); if (input.length < 1) { InitQustionaire() .then(res => { const { boardName, id, outputDir, outputFormat, token } = res; controller.saveNewBoard(boardName, id, outputDir, outputFormat, token); }) .catch(error => { console.log(helper_1.errorLog("An error occured, please try again")); }); } else { const [boardName, id, outputDir, outputFormat, token] = input; controller.saveNewBoard(boardName, id, outputDir, outputFormat, token); } } function InitQustionaire() { return __awaiter(this, void 0, void 0, function* () { const qustions = [ { message: "Please name your Figma file.", name: "boardName", type: "input" }, { message: "Please provide your Figma file ID.", name: "id", type: "input" }, { message: "Please provide your Figma personal access token.", name: "token", type: "input" }, { message: "Please provide your token directory.", name: "outputDir", type: "input" }, { choices: ["scss", "js", "css"], message: "Please choose your token format.", name: "outputFormat", type: "select" } ]; const response = yield enquirer_1.prompt(qustions); return response; }); } //# sourceMappingURL=cli.js.map