Giter Site home page Giter Site logo

figmachi's Introduction

Figma-bot

Figma-bot is a Node.js module to programmatically create and update projects and files in Figma, which Figma API does not allow.

Installation

yarn add @proscom/figma-bot
// or
npm install --save @proscom/figma-bot

FigmaBot

import { FigmaBot } from '@proscom/figma-bot';

The main class of the module which uses Puppeteer library to interact with Figma web-site and create and update Figma projects and files.

Properties

  • browser Object: Puppeteer Browser instance, the browser which opens Figma web-site pages;
  • authData Object: Figma authorization data of the account which will be used by the bot to authorize on Figma web-site:
    • email string: account email;
    • password string: account password;
  • delayDuration number: duration of delay between bot interactions with Figma web-site (e.g. click, navigate etc.) in ms;
  • cookiesProvider Object: object providing Figma authorization cookies (see below for details).

Constructor

const bot = new FigmaBot({ authData, delayDuration, cookiesProvider });

Parameters:

  • authData Object: value to initialize authData property:
    • email string (required);
    • password string (required);
  • delayDuration number: value to initialize delayDuration property (optional, default 2000);
  • cookiesProvider Object: value to initialize cookiesProvider property (optional).

Methods

Method Parameters Description Return value
bot.start() Starts the bot. Promise<void>
bot.stop() Stops the bot. Promise<void>
bot.createProject(projectName, teamId) - projectName string (required)
- teamId string (required)
Creates a project with name projectName in team with id teamId. Promise<string> - a promise which resolves with the new project id
bot.createFile(fileName, projectId) - fileName string (required),
- projectId string (required)
Creates a file with name fileName in project with id projectId. Promise<string> - a promise which resolves with the new file id
bot.renameFile(fileId, newName) - fileId string (required)
- newName string (required)
Renames a file with id fileId to newName. Promise<void>
bot.renameProject(projectId, newName) - projectId string (required)
- newName string (required)
Renames a project with id project to newName. Promise<void>
bot.duplicateFileFromExternalProject(sourceProjectId, sourceFileName, destinationProjectName) - sourceProjectId string (required)
- sourceFileNamestring (required)
- destinationProjectNamestring (required)
Creates duplicate of sourceFileName in project sourceProjectId and move copy to destinationProjectName Promise<void>
bot.renameFileInProject(sourceProjectId, sourceFileName, newFileName) - sourceProjectId string (required)
- sourceFileNamestring (required)
- newFileNamestring (required)
Renames a file sourceFileName in project sourceProjectId to newFileName Promise<void>

You can find your team id in the team's page URL between 'team' and your team name, e.g. for team page URL https://www.figma.com/files/team/000000000000000001/MyTeamName team id is 000000000000000001. Same for project and file ids:

CookiesProvider

FigmaBot's cookiesProvider property is an instance of the following interface:

export interface CookiesProvider {
  getCookies: () => Promise<any>;
  setCookies: (cookies: any) => Promise<void>;
}

CookiesProvider allows saving and loading Figma account authorization cookies. If cookiesProvider parameter not passed to FigmaBot's constructor, cookies are not saved and authorization is performed every new session.

FSCookiesProvider

A simple example of CookiesProvider is FSCookiesProvider class which implements CookiesProvider interface and uses fs module to save cookies to json file and load cookies from the file.

import { FSCookiesProvider } from '@proscom/figma-bot';

const cookiesProvider = new FSCookiesProvider(path);

Constructor parameters:

  • path string: path to json file which contains cookies.

Example

An example code that creates a simple Figma bot, uses FSCookiesProvider as cookiesProvider and creates project "My project" and file "My file":

const { FigmaBot, FSCookiesProvider } = require('./lib');

const bot = new FigmaBot({
  authData: {
    email: 'your figma email',
    password: 'your figma password'
  },
  cookiesProvider: new FSCookiesProvider()
});

(async () => {
  try {
    await bot.start();
    const projectId = await bot.createProject('My project', 'your team id');
    const fileId = await bot.createFile('My file', projectId);
    console.log('"My project" id is "' + projectId + '", "My file" id is "' + fileId + '".');
  } catch (e) {
    console.log(e);
  }
  await bot.stop();
})();

figmachi's People

Contributors

mirakl-026 avatar sviryukov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.