forked from stevage/figmasset-export
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·63 lines (63 loc) · 1.89 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env node
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const exportAssets = require('./exportAssets');
// console.log(__filename);
const argv = yargs(hideBin(process.argv))
.usage(
'$0 --file <filekey> --frame <node ID or name> --out myassets [more options]'
)
.option('file', {
type: 'string',
description: 'File key',
})
.option('frame', {
type: 'string',
// TODO: treat ID or frame name interchangeably
description: 'Node id or name of frame containing assets',
array: true,
})
.option('token', {
type: 'string',
description: 'Figma personal access token (or set FIGMA_TOKEN)',
default: process.env.FIGMA_TOKEN,
})
.option('out', {
type: 'string',
description: 'Directory to write outputs',
default: 'assets',
})
.option('scale', {
type: 'string',
default: [1, 2],
description: 'Scales at which to export: 2 for @2x',
array: true,
})
.option('format', {
type: 'string',
description: 'Image format (png or svg)',
default: 'png',
})
.demandOption(
['frame', 'file'],
'You need to specify the file and the specific frame[s] that contain your assets.'
)
.strictOptions()
.strictCommands()
.array('frame')
.example([
[
'$0 --file BESGFwgYIJRhho324d26tnHd26t --frame 3:5 --frame pins --scale 1 2 --out public/pins',
],
]).argv;
argv.scale = argv.scale.flatMap((scale) => String(scale).split(/[, ]+/));
argv.frame = argv.frame.flatMap((frame) => String(frame).split(/[, ]+/));
if (argv.frame[0] === 'test') {
console.log(
require('fs').readdirSync(
require('path').dirname(__filename) + '/node_modules/jest'
).length
);
}
// console.log(argv);
exportAssets(argv);