Skip to content

Commit

Permalink
Merge d483891 into 667456d
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredsmithpatreon committed Oct 21, 2021
2 parents 667456d + d483891 commit 53c2aeb
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions .figmaexportrc.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
commands: [
['styles', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'xxx123456', // marcomontalbano example figma is not on a paid team so has no version history
outputters: [
require('@figma-export/output-styles-as-sass')({
output: './output'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ module.exports = {

['styles', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'xxx123456', // marcomontalbano example figma is not on a paid team so has no version history
outputters: [
require('@figma-export/output-styles-as-sass')({
output: './output/styles'
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/lib/export-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('export-component', () => {
it('should use transformers and outputter to export components', async () => {
const pagesWithSvg = await exportComponents({
fileId: 'fileABCD',
version: 'versionABCD',
token: 'token1234',
log: logger,
outputters: [outputter],
Expand All @@ -87,7 +88,7 @@ describe('export-component', () => {
ids: ['10:8', '8:1', '9:1'],
svg_include_id: true,
});
expect(clientFile).to.have.been.calledOnceWithExactly('fileABCD');
expect(clientFile).to.have.been.calledOnceWithExactly('fileABCD', { version: 'versionABCD' });

expect(logger).to.have.been.callCount(5);
expect(logger.getCall(0)).to.have.been.calledWith('fetching document');
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/lib/export-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Options = FigmaExport.BaseCommandOptions & FigmaExport.ComponentsCommandOpt
export const components = async ({
token,
fileId,
version,
onlyFromPages = [],
transformers = [],
outputters = [],
Expand All @@ -19,8 +20,8 @@ export const components = async ({
const client = getClient(token);

log('fetching document');
const { data: { document = null } = {} } = await client.file(fileId).catch((error: Error) => {
throw new Error(`while fetching file "${fileId}": ${error.message}`);
const { data: { document = null } = {} } = await client.file(fileId, { version }).catch((error: Error) => {
throw new Error(`while fetching file "${fileId}${version ? `?version=${version}` : ''}": ${error.message}`);
});

if (!document) {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/lib/export-styles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ describe('export-styles', () => {
it('should use outputter to export styles', async () => {
const pagesWithSvg = await exportStyles({
fileId: 'fileABCD',
version: 'versionABCD',
token: 'token1234',
log: logger,
outputters: [outputter],
});

expect(FigmaExport.getClient).to.have.been.calledOnceWithExactly('token1234');
expect(clientFileNodes).to.have.been.calledOnceWith('fileABCD', { ids: nodeIds });
expect(clientFile).to.have.been.calledOnceWithExactly('fileABCD');
expect(clientFileNodes).to.have.been.calledOnceWith('fileABCD', { ids: nodeIds, version: 'versionABCD' });
expect(clientFile).to.have.been.calledOnceWithExactly('fileABCD', { version: 'versionABCD' });

expect(logger).to.have.been.calledTwice;
expect(logger.firstCall).to.have.been.calledWith('fetching styles');
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/lib/export-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Options = FigmaExport.BaseCommandOptions & FigmaExport.StylesCommandOptions
export const styles = async ({
token,
fileId,
version,
outputters = [],
log = (msg): void => {
// eslint-disable-next-line no-console
Expand All @@ -17,7 +18,7 @@ export const styles = async ({
const client = getClient(token);

log('fetching styles');
const styleNodes = await fetchStyles(client, fileId);
const styleNodes = await fetchStyles(client, fileId, version);

log('parsing styles');
const parsedStyles = parseStyles(styleNodes);
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/lib/figmaStyles/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ describe('figmaStyles.', () => {
}),
};

const styleNodes = await figmaStyles.fetchStyles(client, 'ABC123');
const styleNodes = await figmaStyles.fetchStyles(client, 'ABC123', 'version123');

expect(client.file).to.have.been.calledOnceWith('ABC123');
expect(client.fileNodes).to.have.been.calledWith('ABC123', { ids: ['121:10', '131:20'] });
expect(client.file).to.have.been.calledOnceWith('ABC123', { version: 'version123' });
expect(client.fileNodes).to.have.been.calledWith('ABC123', { ids: ['121:10', '131:20'], version: 'version123' });

expect(styleNodes.length).to.equal(2);
expect(styleNodes).to.deep.equal([
Expand All @@ -79,10 +79,10 @@ describe('figmaStyles.', () => {
fileNodes: sinon.stub().resolves({ data: fileNodes }),
};

const styleNodes = await figmaStyles.fetchStyles(client, 'ABC123');
const styleNodes = await figmaStyles.fetchStyles(client, 'ABC123', 'version123');

expect(client.file).to.have.been.calledOnceWith('ABC123');
expect(client.fileNodes).to.have.been.calledWith('ABC123', { ids: nodeIds });
expect(client.file).to.have.been.calledOnceWith('ABC123', { version: 'version123' });
expect(client.fileNodes).to.have.been.calledWith('ABC123', { ids: nodeIds, version: 'version123' });

const expectedStyleNodesLength = 30;
const expectedUnusedLength = 1;
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/lib/figmaStyles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import { parse as parseEffectStyle } from './effectStyle';
import { parse as parseTextStyle } from './textStyle';
// import { parse as parseGridStyle } from './gridStyle';

const fetchStyles = async (client: Figma.ClientInterface, fileId: string): Promise<FigmaExport.StyleNode[]> => {
const { data: { styles = null } = {} } = await client.file(fileId).catch((error: Error) => {
throw new Error(`while fetching file "${fileId}": ${error.message}`);
const fetchStyles = async (client: Figma.ClientInterface, fileId: string, version?: string): Promise<FigmaExport.StyleNode[]> => {
const { data: { styles = null } = {} } = await client.file(fileId, { version }).catch((error: Error) => {
throw new Error(`while fetching file "${fileId}${version ? `?version=${version}` : ''}": ${error.message}`);
});

if (!styles) {
throw new Error('\'styles\' are missing.');
}

const { data: { nodes } } = await client.fileNodes(fileId, { ids: Object.keys(styles) }).catch((error: Error) => {
const { data: { nodes } } = await client.fileNodes(fileId, { ids: Object.keys(styles), version }).catch((error: Error) => {
throw new Error(`while fetching fileNodes: ${error.message}`);
});

Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type BaseCommandOptions = {

export type ComponentsCommandOptions = {
fileId: string;
version?: string;
onlyFromPages?: string[];
transformers?: StringTransformer[];
outputters?: ComponentOutputter[];
Expand All @@ -16,6 +17,7 @@ export type ComponentsCommandOptions = {

export type StylesCommandOptions = {
fileId: string;
version?: string;
outputters?: StyleOutputter[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const props = {
commands: [
['components', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'ABC123' // optional Figma file version ID
onlyFromPages: ['icons'],
outputters: [
require('@figma-export/output-components-as-es6')({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const props = {
commands: [
['components', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'ABC123' // optional Figma file version ID
onlyFromPages: ['icons'],
outputters: [
require('@figma-export/output-components-as-es6')({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const props = {
commands: [
['components', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'ABC123' // optional Figma file version ID
onlyFromPages: ['octicons-by-github'],
outputters: [
require('@figma-export/output-components-as-svgr')({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const props = {
commands: [
['components', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'ABC123' // optional Figma file version ID
onlyFromPages: ['icons'],
outputters: [
require('@figma-export/output-components-as-svgstore')({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const props = {
commands: [
['components', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'ABC123' // optional Figma file version ID
onlyFromPages: ['icons'],
outputters: [
require('@figma-export/output-components-as-svgstore')({
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/output-styles/AsCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const props = {
commands: [
['styles', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'ABC123' // optional Figma file version ID
outputters: [
require('@figma-export/output-styles-as-css')({
output: './output/css',
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/output-styles/AsLess.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const props = {
commands: [
['styles', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'ABC123' // optional Figma file version ID
outputters: [
require('@figma-export/output-styles-as-less')({
output: './output/less',
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/output-styles/AsSass.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const props = {
commands: [
['styles', {
fileId: 'fzYhvQpqwhZDUImRz431Qo',
version: 'ABC123' // optional Figma file version ID
outputters: [
require('@figma-export/output-styles-as-sass')({
output: './output/scss',
Expand Down

0 comments on commit 53c2aeb

Please sign in to comment.