Skip to content

Commit

Permalink
Export color will add file extension. Fix add number to color name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashung Hung committed Apr 10, 2021
1 parent cf8fc0d commit 5355c1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5355c1b

Please sign in to comment.