Skip to content

Commit

Permalink
Merge eecb87d into 99e8788
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Dec 21, 2021
2 parents 99e8788 + eecb87d commit f7614a6
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 1,012 deletions.
4 changes: 1 addition & 3 deletions packages/cli/bin/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

require('@oclif/core').run()
.then(require('@oclif/core/flush'))
.catch(require('@oclif/core/handle'));
require('../dist/run');
32 changes: 5 additions & 27 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"name": "@figma-export/cli",
"description": "Command line for @figma-export",
"version": "4.0.0-alpha.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Marco Montalbano",
"bin": {
"figma-export": "./bin/run"
Expand All @@ -12,23 +10,16 @@
"dependencies": {
"@figma-export/core": "^4.0.0-alpha.0",
"@figma-export/types": "^4.0.0-alpha.0",
"@oclif/core": "~1.0.10",
"@oclif/plugin-help": "~3.2.17",
"ora": "~5.4.1"
},
"devDependencies": {
"@oclif/dev-cli": "~1.26.9",
"@oclif/test": "~2.0.3",
"globby": "~11.0.4"
"@types/sade": "~1.7.4",
"ora": "~5.4.1",
"sade": "~1.7.4"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"files": [
"/bin",
"/dist",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
"/dist"
],
"homepage": "https://github.com/marcomontalbano/figma-export",
"keywords": [
Expand All @@ -39,25 +30,12 @@
"typography",
"components",
"cli",
"figma cli",
"oclif"
"figma cli"
],
"license": "MIT",
"oclif": {
"commands": "./dist/commands",
"bin": "figma-export",
"plugins": [
"@oclif/plugin-help"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/marcomontalbano/figma-exporter.git",
"directory": "packages/cli"
},
"scripts": {
"postpack": "rm -f oclif.manifest.json",
"prepack": "oclif-dev manifest && oclif-dev readme",
"version": "oclif-dev readme && git add README.md"
}
}
33 changes: 0 additions & 33 deletions packages/cli/src/commands/components.test.ts

This file was deleted.

134 changes: 46 additions & 88 deletions packages/cli/src/commands/components.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,55 @@
import { Command, Flags as commandFlags } from '@oclif/core';
import { Ora } from 'ora';
import { Sade } from 'sade';

import * as figmaExport from '@figma-export/core';
import * as FigmaExport from '@figma-export/types';

import { requirePackages } from '../utils';

import ora = require('ora');

const spinner = ora({});

export class ComponentsCommand extends Command {
static description = `export components from a Figma file
`;
import { asArray, requirePackages } from '../utils';

export const addComponents = (prog: Sade, spinner: Ora) => prog
.command('components <fileId>')
.describe('Export components from a Figma file.')
.option('-O, --outputter', 'Outputter module or path')
.option('-T, --transformer', 'Transformer module or path')
.option('-c, --concurrency', 'Concurrency when fetching', 30)
.option('-o, --output', 'Output directory', 'output')
.option('-p, --page', 'Figma page names (all pages when not specified)')
.option('--fileVersion', `A specific version ID to get. Omitting this will get the current version of the file.
https://help.figma.com/hc/en-us/articles/360038006754-View-a-file-s-version-history`)
.example('components fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-components-as-svg')
.action(
(fileId, {
fileVersion,
concurrency,
output,
...opts
}) => {
const outputter = asArray<string>(opts.outputter);
const transformer = asArray<string>(opts.transformer);
const page = asArray<string>(opts.page);

static args = [
{
name: 'fileId',
required: true,
},
];
spinner.info(`Exporting ${fileId} with [${transformer.join(', ')}] as [${outputter.join(', ')}]`);

static flags = {
fileVersion: commandFlags.string({
required: false,
description: `
A specific version ID to get. Omitting this will get the current version of the file.
https://help.figma.com/hc/en-us/articles/360038006754-View-a-file-s-version-history`,
multiple: false,
}),
page: commandFlags.string({
char: 'p',
description: 'Figma page names (defaults to \'all pages\')',
multiple: true,
}),
concurrency: commandFlags.integer({
char: 'c',
description: 'Concurrency when fetching',
default: 30,
multiple: false,
}),
output: commandFlags.string({
char: 'o',
description: 'Output directory',
default: 'output',
multiple: false,
}),
outputter: commandFlags.string({
char: 'O',
description: 'Outputter module or path',
multiple: true,
}),
transformer: commandFlags.string({
char: 'T',
description: 'Transformer module or path',
multiple: true,
}),
};
spinner.start();

async run(): Promise<void> {
const {
args: {
figmaExport.components({
fileId,
},
flags: {
fileVersion,
page,
output,
version: fileVersion,
concurrency,
outputter = [],
transformer = [],
},
} = await this.parse(ComponentsCommand);

spinner.info(`Exporting ${fileId} with [${transformer.join(', ')}] as [${outputter.join(', ')}]`);

spinner.start();

figmaExport.components({
fileId,
version: fileVersion,
concurrency,
token: process.env.FIGMA_TOKEN || '',
onlyFromPages: page,
transformers: requirePackages<FigmaExport.StringTransformer>(transformer),
outputters: requirePackages<FigmaExport.ComponentOutputter>(outputter, { output }),
log: (message: string) => { spinner.text = message; },
}).then(() => {
spinner.succeed('done');
}).catch((error: Error) => {
spinner.fail();

// eslint-disable-next-line no-console
console.error(error);
});
}
}
token: process.env.FIGMA_TOKEN || '',
onlyFromPages: page,
transformers: requirePackages<FigmaExport.StringTransformer>(transformer),
outputters: requirePackages<FigmaExport.ComponentOutputter>(outputter, { output }),

// eslint-disable-next-line no-param-reassign
log: (message: string) => { spinner.text = message; },
}).then(() => {
spinner.succeed('done');
}).catch((error: Error) => {
spinner.fail();

// eslint-disable-next-line no-console
console.error(error);
});
},
);
111 changes: 41 additions & 70 deletions packages/cli/src/commands/styles.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,46 @@
import { Command, Flags as commandFlags } from '@oclif/core';
import { Ora } from 'ora';
import { Sade } from 'sade';

import * as figmaExport from '@figma-export/core';
import * as FigmaExport from '@figma-export/types';

import { requirePackages } from '../utils';

import ora = require('ora');

const spinner = ora({});

export class StylesCommand extends Command {
static description = `export styles from a Figma file
`;

static args = [
{
name: 'fileId',
required: true,
},
];

static flags = {
fileVersion: commandFlags.string({
required: false,
description: `
A specific version ID to get. Omitting this will get the current version of the file.
https://help.figma.com/hc/en-us/articles/360038006754-View-a-file-s-version-history`,
multiple: false,
}),
output: commandFlags.string({
char: 'o',
description: 'Output directory',
default: 'output',
multiple: false,
}),
outputter: commandFlags.string({
char: 'O',
description: 'Outputter module or path',
multiple: true,
}),
};

async run(): Promise<void> {
const {
args: {
import { asArray, requirePackages } from '../utils';

export const addStyles = (prog: Sade, spinner: Ora) => prog
.command('styles <fileId>')
.describe('Export styles from a Figma file.')
.option('-O, --outputter', 'Outputter module or path')
.option('-o, --output', 'Output directory', 'output')
.option('--fileVersion', `A specific version ID to get. Omitting this will get the current version of the file.
https://help.figma.com/hc/en-us/articles/360038006754-View-a-file-s-version-history`)
.example('styles fzYhvQpqwhZDUImRz431Qo -O @figma-export/output-styles-as-css')
.action(
(fileId, {
fileVersion,
output,
...opts
}) => {
const outputter = asArray<string>(opts.outputter);

spinner.info(`Exporting ${fileId} as [${outputter.join(', ')}]`);

spinner.start();

figmaExport.styles({
fileId,
},
flags: {
output,
outputter = [],
fileVersion,
},
} = await this.parse(StylesCommand);

spinner.info(`Exporting ${fileId} as [${outputter.join(', ')}]`);

spinner.start();

figmaExport.styles({
fileId,
version: fileVersion,
token: process.env.FIGMA_TOKEN || '',
outputters: requirePackages<FigmaExport.StyleOutputter>(outputter, { output }),
log: (message: string) => { spinner.text = message; },
}).then(() => {
spinner.succeed('done');
}).catch((error: Error) => {
spinner.fail();

// eslint-disable-next-line no-console
console.log(error);
});
}
}
version: fileVersion,
token: process.env.FIGMA_TOKEN || '',
outputters: requirePackages<FigmaExport.StyleOutputter>(outputter, { output }),

// eslint-disable-next-line no-param-reassign
log: (message: string) => { spinner.text = message; },
}).then(() => {
spinner.succeed('done');
}).catch((error: Error) => {
spinner.fail();

// eslint-disable-next-line no-console
console.log(error);
});
},
);
Loading

0 comments on commit f7614a6

Please sign in to comment.