-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
329 additions
and
1,012 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}, | ||
); |
Oops, something went wrong.