Skip to content

Commit fa6f42e

Browse files
committed
feat(converting): optimize output
1 parent 6b42a67 commit fa6f42e

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

dist/icons.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
export const sampleIconsExpressionless: SVGIcon = {
1+
export const sampleIconsexpressionless: SampleIcon = {
22
name: 'expressionless',
33
data: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g data-name="Expressionless Face"><path d="M256 512A256 256 0 0175.172 74.783a256 256 0 01361.656 362.434A254.352 254.352 0 01256 512z"/><path d="M436.828 74.783a258.146 258.146 0 00-42.542-34.3 256.558 256.558 0 01-53.458 284.739 256.2 256.2 0 01-319.115 34.3A256.068 256.068 0 10436.828 74.783z"/><g><circle cx="88" cy="232" r="24"/><circle cx="424" cy="232" r="24"/><path d="M264 304h-16a8 8 0 010-16h16a8 8 0 010 16z"/></g><path d="M136 176H72a8 8 0 010-16h64a8 8 0 010 16z"/><path d="M376 272H136a8 8 0 010-16h240a8 8 0 010 16z"/><path d="M440 176h-64a8 8 0 010-16h64a8 8 0 010 16z"/></g></svg>'
44
};
5-
export const sampleIconsFull: SVGIcon = {
5+
export const sampleIconsfull: SampleIcon = {
66
name: 'full',
77
data: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 512A256 256 0 0175.172 74.783a256 256 0 01361.656 362.434A254.353 254.353 0 01256 512z"/><path d="M436.828 74.783a257.826 257.826 0 00-47.511-37.426A257.015 257.015 0 01400 110.933a255.989 255.989 0 01-256 256 254.39 254.39 0 01-133.317-37.357 256.108 256.108 0 00426.145 107.641 256.016 256.016 0 000-362.434z"/><circle cx="64" cy="240" r="24"/><circle cx="448" cy="240" r="24"/><path d="M200 192a8 8 0 01-8-8 24 24 0 00-48 0 8 8 0 01-16 0 40 40 0 0180 0 8 8 0 01-8 8zM392 192a8 8 0 01-8-8 24 24 0 00-48 0 8 8 0 01-16 0 40 40 0 0180 0 8 8 0 01-8 8z"/><path d="M377.547 407.967a68.5 68.5 0 01-48.378-20.289l-45.535-45.535 13.193-3.678c36.958-10.3 67.47-34.244 83.714-65.684l5.024-9.725 34.114 34.112a68.388 68.388 0 0120.3 46.595 61.857 61.857 0 01-62.429 64.2z"/><path d="M412 328a124.459 124.459 0 0126.358 2.817 69.01 69.01 0 00-18.679-33.649l-34.114-34.112-5.024 9.725c-16.244 31.44-46.756 55.381-83.714 65.684l-13.193 3.678 31.923 31.923A123.756 123.756 0 01412 328z"/><path d="M382.28 358.28a7.976 7.976 0 01-5.657-2.343l-30.65-30.65a8 8 0 0111.314-11.314l30.651 30.65a8 8 0 01-5.658 13.657z"/><path d="M256 360c-84.364 0-153-61.907-153-138a8 8 0 0116 0c0 67.271 61.458 122 137 122s137-54.729 137-122a8 8 0 0116 0c0 76.093-68.636 138-153 138z"/><circle cx="376" cy="380" r="12"/></svg>'
88
};
9-
export const sampleIconsLaughing: SVGIcon = {
9+
export const sampleIconslaughing: SampleIcon = {
1010
name: 'laughing',
1111
data: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M240 512c-66.7 0-128.262-27.927-173.341-78.636C24.3 385.712 0 321.065 0 256S24.3 126.288 66.659 78.636C111.738 27.927 173.3 0 240 0c72.332 0 139.1 19.218 188.009 54.113C482.956 93.317 512 149.3 512 216c0 64.3-30.883 138.063-82.611 197.31C374.63 476.029 305.6 512 240 512z"/><path d="M463.669 85.861c.207 4.689.331 9.4.331 14.139 0 174.522-141.478 316-316 316a315.361 315.361 0 01-108.233-19.028 254.869 254.869 0 0026.891 36.392C111.738 484.073 173.3 512 240 512c65.6 0 134.63-35.971 189.389-98.69C481.117 354.063 512 280.3 512 216c0-50.363-16.568-94.607-48.331-130.139z"/><circle cx="80" cy="216" r="24"/><circle cx="448" cy="200" r="24"/><path d="M455.99 510.83h-.051a55.682 55.682 0 01-33.529-11.2l-81.24-60.9.03-.04 67.14-89.57.04.03 81.2 60.86a55.947 55.947 0 0111.48 78.06l-.03.04a55.968 55.968 0 01-45.04 22.72z"/><path d="M336.979 456a23.989 23.989 0 01-22.859-31.17l-11.31-8.48a97.087 97.087 0 01-14.63 1.11h-.02a95.462 95.462 0 01-57.49-19.19l-57.25-42.91a24.674 24.674 0 01-9.89-19.7 23.3 23.3 0 014.05-13.23 23.745 23.745 0 017.4-7.06 24.707 24.707 0 01-5.06-14.91 23.3 23.3 0 014.05-13.23 23.945 23.945 0 016.56-6.52l-7.49-5.62a23.99 23.99 0 01-4.1-34.5 23.664 23.664 0 0118.35-8.58h.06a24.506 24.506 0 018.89 1.65A23.777 23.777 0 01219.29 216h.06a24.9 24.9 0 0114.83 4.94l47.88 35.89a31.923 31.923 0 015.8-14.87 31.545 31.545 0 0111.62-9.81 32.665 32.665 0 0114.291-3.3h.04a32.991 32.991 0 0119.65 6.52l12.37 9.28a95.708 95.708 0 0135.21 52.2 96.961 96.961 0 013.12 20.51l6.73 5.05a23.938 23.938 0 0113.29-4.02h.07a24.031 24.031 0 0114.31 4.77l.04.03a24 24 0 014.81 33.59l-67.182 89.62a24.1 24.1 0 01-19.179 9.6z"/><path d="M418.6 323.19l-.04-.03a24.031 24.031 0 00-14.31-4.77h-.07a23.938 23.938 0 00-13.29 4.02l-6.73-5.05a96.087 96.087 0 00-8.889-36.442 164.066 164.066 0 01-153.005 111.053l8.4 6.3a95.462 95.462 0 0057.49 19.19h.02a97.087 97.087 0 0014.63-1.11l11.31 8.48A23.993 23.993 0 00336.979 456h.071a24.1 24.1 0 0019.179-9.6l67.181-89.62a24 24 0 00-4.81-33.59z"/><g><path d="M268.81 284.8a8 8 0 01-11.2 1.6s-71.53-53.75-71.97-54.33c.55-.04 7.76.49 10.6 1.59a23.937 23.937 0 014.69-9.08c.11-.13.22-.27.35-.4l65.93 49.42a8 8 0 011.6 11.2zM238.4 332.78a7.92 7.92 0 01-6.4 3.21h-.01a7.975 7.975 0 01-4.79-1.6l-55.91-41.91v-.01a22.952 22.952 0 012.68-5.24 23.945 23.945 0 016.56-6.52l-7.49-5.62a23.49 23.49 0 01-3.18-2.87 8.045 8.045 0 012.93 1.38l64.01 47.98a8 8 0 011.6 11.2zM219.21 356.8a8 8 0 01-11.2 1.6l-42.62-31.95a22.732 22.732 0 012.19-4.02 23.745 23.745 0 017.4-7.06 24.8 24.8 0 01-2.14-3.33l44.76 33.56a7.989 7.989 0 011.61 11.2zM325.04 278.39a8 8 0 01-11.2 1.6l-31.7-23.76a31.874 31.874 0 015.72-14.27c.22-.31.46-.62.69-.92l34.89 26.15a8 8 0 011.6 11.2z"/></g><path d="M200 192a8 8 0 01-8-8 24 24 0 00-48 0 8 8 0 01-16 0 40 40 0 0180 0 8 8 0 01-8 8zM392 192a8 8 0 01-8-8 24 24 0 00-48 0 8 8 0 01-16 0 40 40 0 0180 0 8 8 0 01-8 8z"/><path d="M366.68 357.78a8 8 0 10-6.41 3.2 7.983 7.983 0 006.41-3.2zM374.67 333.77a8 8 0 0011.2-1.6l8.867-11.825a24.055 24.055 0 00-3.847 2.065l-6.73-5.05a96.38 96.38 0 00-.763-8.559l-10.328 13.779a8.01 8.01 0 001.601 11.19zM302.81 416.35l11.31 8.48a23.922 23.922 0 00-.907 4.271l34.277-45.721a8 8 0 00-12.81-9.6l-31.911 42.575z"/><path d="M492.505 412.376a116.128 116.128 0 01-121.131 49l51.036 38.254a55.682 55.682 0 0033.529 11.2h.051a55.968 55.968 0 0045.04-22.72l.03-.04a55.94 55.94 0 00-8.555-75.694z"/></svg>'
1212
};
13-
export const sampleIconsSmiling
14-
-face
15-
:
16-
SVGIcon = {
13+
export const sampleIconssmilingFace: SampleIcon = {
1714
name: 'smiling-face',
1815
data: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 512c-34.27 0-67.946-8.1-100.092-24.067-30.031-14.919-57.359-35.96-81.223-62.539C27.222 372.532 0 304.958 0 240c0-64.208 26.7-124.543 75.172-169.891C123.5 24.9 187.72 0 256 0s132.5 24.9 180.828 70.109C485.3 115.457 512 175.792 512 240c0 64.958-27.222 132.532-74.685 185.394-23.864 26.579-51.192 47.62-81.223 62.539C323.946 503.9 290.27 512 256 512z"/><path d="M470.68 109.135q1.3 13.258 1.32 26.865c0 150.221-121.779 272-272 272a270.944 270.944 0 01-178.965-67.181 301.144 301.144 0 0053.65 84.575c23.864 26.579 51.192 47.62 81.223 62.539C188.054 503.9 221.73 512 256 512s67.946-8.1 100.092-24.067c30.031-14.919 57.359-35.96 81.223-62.539C484.778 372.532 512 304.958 512 240a227.707 227.707 0 00-41.32-130.865z"/><path d="M192 160a8 8 0 01-8-8 24 24 0 00-48 0 8 8 0 01-16 0 40 40 0 0180 0 8 8 0 01-8 8zM384 160a8 8 0 01-8-8 24 24 0 00-48 0 8 8 0 01-16 0 40 40 0 0180 0 8 8 0 01-8 8z"/><circle cx="440" cy="152" r="24"/><circle cx="72" cy="152" r="24"/><g><path d="M256 320c-40.234 0-78.14-12.249-106.735-34.489C120.075 262.808 104 232.439 104 200a8 8 0 0116 0c0 57.346 61.009 104 136 104s136-46.654 136-104a8 8 0 0116 0c0 32.439-16.075 62.808-45.265 85.511C334.14 307.751 296.234 320 256 320z"/><path d="M432 220c-30.085 0-44.352-22.111-47.692-33.8a8 8 0 1115.384-4.4c.258.857 6.971 22.2 32.308 22.2a8 8 0 010 16zM80 220a8 8 0 010-16c25.337 0 32.05-21.341 32.323-22.25a8 8 0 1115.369 4.448C124.352 197.889 110.085 220 80 220z"/></g><path d="M288 352h-64a8 8 0 010-16h64a8 8 0 010 16z"/></svg>'
1916
};
20-
type sampleIcons = 'expressionless' | 'full' | 'laughing' | 'smiling-face' |
17+
type sampleIcons = 'expressionless' | 'full' | 'laughing' | 'smiling-face'
2118

2219
export interface SampleIcon {
2320
name: string;

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"typescript": "^3.7.2"
3030
},
3131
"dependencies": {
32+
"lodash.camelcase": "^4.3.0",
3233
"svgo": "^1.3.2"
3334
}
3435
}

src/convert.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {svgo} from './svgo';
22
import {getInterfaceDefenition} from './interface-def';
3+
import * as camelCase from 'lodash.camelcase';
34

45
const util = require('util');
56
const path = require('path');
@@ -24,22 +25,28 @@ export const convert = async (convertionOptions: ConvertionOptions) => {
2425
const files = await readdir(directoryPath);
2526
let types = `type ${convertionOptions.typeName} = `;
2627

27-
for (const fileName of files) {
28+
for (let i = 0; i < files.length; i++) {
29+
const fileName = files[i];
2830
const filenameWithoutEnding = fileName.split('.')[0];
2931
const rawSvg = await extractSvgContent(fileName, directoryPath);
3032
const optimizedSvg = await svgo.optimize(rawSvg);
3133

3234
const fileNameUpperCase = filenameWithoutEnding[0].toUpperCase() + filenameWithoutEnding.slice(1);
33-
const variableName = `${convertionOptions.prefix}${fileNameUpperCase}`;
34-
// TODO kk: check if file is last
35-
types += `'${filenameWithoutEnding}' | `;
36-
fileContent += `export const ${variableName}: SVGIcon = {
35+
const variableName = `${convertionOptions.prefix}${camelCase(fileNameUpperCase)}`;
36+
37+
if (i === files.length - 1) {
38+
types += `'${filenameWithoutEnding}'`;
39+
} else {
40+
types += `'${filenameWithoutEnding}' | `;
41+
}
42+
43+
fileContent += `export const ${variableName}: ${convertionOptions.interfaceName} = {
3744
name: '${filenameWithoutEnding}',
3845
data: '${optimizedSvg.data}'
3946
};`;
4047
}
4148
fileContent += types += getInterfaceDefenition(convertionOptions.interfaceName);
42-
if (!fs.existsSync(convertionOptions.outputDirectory)){
49+
if (!fs.existsSync(convertionOptions.outputDirectory)) {
4350
fs.mkdirSync(convertionOptions.outputDirectory);
4451
}
4552
console.log('FileContent', fileContent);

0 commit comments

Comments
 (0)