From a0a79bf91ad081c6806c4706627fc1d460997c46 Mon Sep 17 00:00:00 2001 From: Mike Ozornin Date: Wed, 30 Jun 2021 12:23:48 +0300 Subject: [PATCH] Added file format and scale options --- cli.js | 9 +++++---- src/defaults.js | 6 ++++-- src/prompts.js | 14 +++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cli.js b/cli.js index 7b912b7..df67ded 100755 --- a/cli.js +++ b/cli.js @@ -188,7 +188,7 @@ function getImages (icons) { return new Promise((resolve) => { spinner.start('Fetching icon urls') const iconIds = icons.map(icon => icon.id).join(',') - figmaClient.get(`/images/${config.fileId}?ids=${iconIds}&format=svg`) + figmaClient.get(`/images/${config.fileId}?ids=${iconIds}&format=${config.format}&scale=${config.scale}`) .then((res) => { spinner.succeed() const images = res.data.images @@ -221,7 +221,8 @@ function downloadImage (url, name) { } } } - const imagePath = path.resolve(directory, `${nameClean}.svg`) + let suffix = config.scale == 1 ? '' : `@${config.scale}x` + const imagePath = path.resolve(directory, `${nameClean}${suffix}.${config.format}`) const writer = fs.createWriteStream(imagePath) @@ -240,9 +241,9 @@ function downloadImage (url, name) { return new Promise((resolve, reject) => { writer.on('finish', () => { - // console.log(`Saved ${name}.svg`, fs.statSync(imagePath).size) + // console.log(`Saved ${name}.${config.format}`, fs.statSync(imagePath).size) resolve({ - name: `${name}.svg`, + name: `${name}.${config.format}`, size: fs.statSync(imagePath).size }) }) diff --git a/src/defaults.js b/src/defaults.js index 39c9891..bb7470a 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -3,7 +3,9 @@ const defaults = { page: 'Identity', frame: 'Icons', iconsPath: 'assets/svg/icons', - removeFromName: 'Icon=' + removeFromName: 'Icon=', + format: "svg", + scale: 1 } -module.exports = defaults +module.exports = defaults \ No newline at end of file diff --git a/src/prompts.js b/src/prompts.js index c67828b..2f417c1 100644 --- a/src/prompts.js +++ b/src/prompts.js @@ -16,7 +16,7 @@ const prompts = [ { type: 'text', name: 'page', - message: 'Name of the page with icons?', + message: 'Name of the page with icons', initial: defaults.page }, { @@ -30,6 +30,18 @@ const prompts = [ name: 'iconsPath', message: 'Directory to download the icons to', initial: defaults.iconsPath + }, + { + type: 'text', + name: 'format', + message: 'Icons format for export', + initial: defaults.iconsPath + }, + { + type: 'text', + name: 'scale', + message: 'Icons scale (default 1)', + initial: defaults.iconsPath } ]