figgo
Version:
A CLI tool make your design tokens stay up to date with your Figma design styleguide
100 lines • 3.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const helper_1 = require("./helper");
const board_1 = require("./models/board");
const storage_1 = require("./storage");
class Controller {
constructor() {
this.storage = new storage_1.default();
this.boards = this.storage.readBoardsFromFile();
}
appendBoard(newBoard, bn) {
if (!this.isBoardExisted(bn)) {
this.boards.push(newBoard);
console.log(this.storage.writeFile(this.boards));
console.log(helper_1.successLog(`Board ${bn} (${helper_1.urlFactory(newBoard.id)}) is added to Figgo`));
return true;
}
else {
console.log(helper_1.warningLog(`Board ${bn} is already existed`));
return false;
}
}
setBoardOutputDir(dir, bn) {
if (this.isBoardExisted(bn)) {
const target = this.getBoard(bn);
target.outputDir = dir;
this.saveExistingBoard(target, bn);
}
else {
console.log(helper_1.errorLog(`board ${bn} isn't existed`));
}
}
setBoardOutputFormat(format, bn) {
if (this.isBoardExisted(bn)) {
const target = this.getBoard(bn);
target.outputFormat = format;
this.saveExistingBoard(target, bn);
}
else {
console.log(helper_1.errorLog(`board ${bn} isn't existed`));
}
}
setBoardToken(token, bn) {
if (this.isBoardExisted(bn)) {
const target = this.getBoard(bn);
target.token = token;
this.saveExistingBoard(target, bn);
}
else {
console.log(helper_1.errorLog(`board ${bn} isn't existed`));
}
}
setBoardId(id, bn) {
if (this.isBoardExisted(bn)) {
const target = this.getBoard(bn);
target.id = id;
this.saveExistingBoard(target, bn);
}
else {
console.log(helper_1.errorLog(`board ${bn} isn't existed`));
}
}
saveNewBoard(bn, id, outputDir, outputFormat, token) {
const newBoard = new board_1.default(bn);
newBoard.id = id;
newBoard.outputDir = outputDir;
newBoard.outputFormat = outputFormat;
newBoard.token = token;
this.appendBoard(newBoard, bn);
}
saveExistingBoard(target, bn) {
const filtered = this.boards.filter(board => board.boardName !== bn);
filtered.push(target);
console.log(this.storage.writeFile(filtered));
}
removeBoard(bn) {
if (this.isBoardExisted(bn)) {
const afterRemove = this.boards.filter(board => board.boardName !== bn);
this.storage.writeFile(afterRemove);
console.log(helper_1.successLog(`board ${bn} is removed`));
}
else {
console.log(helper_1.errorLog(`board ${bn} isn't existed`));
}
}
getStorage() {
return this.storage;
}
getBoards() {
return this.boards;
}
isBoardExisted(bn) {
return this.boards.some(board => board.boardName === bn) ? true : false;
}
getBoard(bn) {
return this.boards.filter(board => board.boardName === bn)[0];
}
}
exports.default = Controller;
//# sourceMappingURL=controller.js.map