Skip to content

Commit

Permalink
WIP: Usage of .figmaexportrc.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Sep 7, 2020
1 parent 32d256e commit 11b5855
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -229,6 +229,25 @@ If needed you can also provide a different configuration file.
}
```

#### TypeScript

If you prefer, you can create a `.figmaexportrc.ts` and use TypeScript instead.
For doing so, you just need to install a few new dependencies in your project,

```sh
npm install --save-dev typescript ts-node @types/node @figma-export/types
```

and slightly change your `package.json`

```diff
{
"scripts": {
+ "figma:export": "ts-node ./node_modules/.bin/figma-export use-config .figmaexportrc.ts"
}
}
```

## :books: More Packages

For the list of all official packages or if you want to create your own transformer or outputter you can continue reading [CLI Documentation](/packages/cli#readme).
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"predebug": "yarn build",
"debug": "./packages/cli/bin/run use-config",
"debug": "./packages/cli/bin/run use-config .figmaexportrc.ts",
"preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('You must use Yarn to install, not NPM')\"",
"clean": "rm -rf node_modules/ output/ */*/node_modules */*/output */*/dist */*/tsconfig.tsbuildinfo",
"postinstall": "lerna bootstrap",
Expand Down
11 changes: 1 addition & 10 deletions packages/core/src/lib/export-components.ts
Expand Up @@ -3,15 +3,6 @@ import { Document } from 'figma-js';

import { getClient, getPages, enrichPagesWithSvg } from './figma';

type Options = {
token: string;
fileId: string;
onlyFromPages?: string[];
transformers?: FigmaExport.StringTransformer[];
outputters?: FigmaExport.ComponentOutputter[];
log?: (msg: string) => void;
}

export const components = async ({
token,
fileId,
Expand All @@ -22,7 +13,7 @@ export const components = async ({
// eslint-disable-next-line no-console
console.log(msg);
},
}: Options): Promise<FigmaExport.PageNode[]> => {
}: FigmaExport.ExportComponentsOptions): Promise<FigmaExport.PageNode[]> => {
const client = getClient(token);

log('fetching document');
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/lib/export-styles.ts
Expand Up @@ -3,13 +3,6 @@ import * as FigmaExport from '@figma-export/types';
import { getClient } from './figma';
import { fetchStyles, parseStyles } from './figmaStyles';

type Options = {
token: string;
fileId: string;
outputters?: FigmaExport.StyleOutputter[];
log?: (msg: string) => void;
}

export const styles = async ({
token,
fileId,
Expand All @@ -18,7 +11,7 @@ export const styles = async ({
// eslint-disable-next-line no-console
console.log(msg);
},
}: Options): Promise<FigmaExport.Style[]> => {
}: FigmaExport.ExportStylesOptions): Promise<FigmaExport.Style[]> => {
const client = getClient(token);

log('fetching styles');
Expand Down
27 changes: 27 additions & 0 deletions packages/types/src/commands.ts
@@ -0,0 +1,27 @@
import { StringTransformer, ComponentOutputter } from './global';
import { StyleOutputter } from './styles';

type ExportComponents = {
fileId: string;
onlyFromPages?: string[];
transformers?: StringTransformer[];
outputters?: ComponentOutputter[];
}

type ExportStyles = {
fileId: string;
outputters?: StyleOutputter[];
}

type ExportOptions = {
token: string;
log?: (msg: string) => void;
}

export type ExportComponentsOptions = ExportOptions & ExportComponents

export type ExportStylesOptions = ExportOptions & ExportStyles

export type CommandUseConfig = {
commands: (['components', ExportComponents] | ['styles', ExportStyles])[]
}
1 change: 1 addition & 0 deletions packages/types/src/index.ts
@@ -1,2 +1,3 @@
export * from './global';
export * from './styles';
export * from './commands';

0 comments on commit 11b5855

Please sign in to comment.