diff --git a/src/export.js b/src/export.js index 34a5380..b86a910 100644 --- a/src/export.js +++ b/src/export.js @@ -5,6 +5,7 @@ import dialog from '@skpm/dialog'; import { writeFileSync } from '@skpm/fs'; import color from './lib/color'; import { toArray } from 'util'; +import { extname } from 'path'; export default function(context) { @@ -18,7 +19,7 @@ export default function(context) { buttons: ['OK', 'Cancel'], message: 'Export colors', checkboxLabel: 'Include color variables from library.', - checkboxChecked: true + checkboxChecked: false }, ({ response, checkboxChecked }) => { if (response === 0) { @@ -54,10 +55,16 @@ export default function(context) { }, (filePath) => { if (identifier === 'export-color-variables-to-clr-file') { + if (extname(filePath) === '') { + filePath += '.clr'; + } let colorList = color.colorListFromArray(colors); colorList.writeToFile(filePath); } if (identifier === 'export-color-variables-to-txt-file') { + if (extname(filePath) === '') { + filePath += '.txt'; + } let keyCount = {}; let text = color.toTextContent(colors, keyCount); writeFileSync(filePath, text); diff --git a/src/import.js b/src/import.js index e73b586..d2df530 100644 --- a/src/import.js +++ b/src/import.js @@ -55,6 +55,8 @@ export default function(context) { colors = sketch2colors(filePath); } else if (fileType === '.txt' || fileType === '.text') { colors = txt2colors(filePath); + } else { + UI.message('Unknown file format.'); } if (colors === undefined) { @@ -115,8 +117,12 @@ export default function(context) { function addColorVariables(addNumber) { colors.forEach((item, index) => { + let name = item.name; + if (addNumber) { + name = item.name.replace(/\/([^\/]*)$/, `/${index + 1}. $1`); + } const swatch = Swatch.from({ - name: (addNumber ? `${index + 1}. ` : '') + item.name, + name, color: item.color }); swatches.push(swatch);