Skip to content

Commit

Permalink
fix(svg-generator): add kebab-case transform to type generator (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokipedia committed Dec 13, 2023
1 parent bcceb6e commit b17183c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
14 changes: 12 additions & 2 deletions svg-generator/__tests__/__snapshots__/create-tree.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ exports[`createTree should create the correct tree 1`] = `
"name": "child2",
"path": "src/app/svg/group/child2.ts",
},
{
"content": "export const childCopyIcon = {
data: \`<svg>child_copy</svg>\`,
name: 'child-copy' as const
};",
"identifierName": "childCopyIcon",
"name": "child_copy",
"path": "src/app/svg/group/child_copy.ts",
},
{
"content": "import { childIcon } from './child';
import { child2Icon } from './child2';
export const groupIcons = [childIcon, child2Icon];
import { childCopyIcon } from './child_copy';
export const groupIcons = [childIcon, child2Icon, childCopyIcon];
",
"identifierName": "index",
"name": "__INDEX__",
Expand Down Expand Up @@ -78,6 +88,6 @@ export const groupTwoIcons = [childOneIcon, childTwoIcon];
`;
exports[`createTree should create the type file 1`] = `
"export declare type SvgIcons = 'foo' | 'bar' | 'foo-bar';
"export declare type SvgIcons = 'foo' | 'bar' | 'foo-bar' | 'foo-baz';
"
`;
3 changes: 2 additions & 1 deletion svg-generator/__tests__/create-tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('createTree', () => {
[`${srcPath}/group`]: {
'child.svg': `<svg>child</svg>`,
'child2.svg': `<svg>child 2</svg>`,
'child_copy.svg': `<svg>child_copy</svg>`
},
[`${srcPath}/group-two`]: {
'child-one.svg': `<svg>child</svg>`,
Expand All @@ -28,6 +29,6 @@ describe('createTree', () => {
});

it('should create the type file', () => {
expect(createTypeFile(['foo', 'bar', 'foo-bar'])).toMatchSnapshot();
expect(createTypeFile(['foo', 'bar', 'foo-bar', 'foo_baz'])).toMatchSnapshot();
});
});
4 changes: 2 additions & 2 deletions svg-generator/create-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
ScriptTarget,
ScriptKind,
factory,
NodeFlags,
SyntaxKind,
} from 'typescript';
import kebabCase from 'lodash.kebabcase';

const printer = createPrinter({
newLine: NewLineKind.LineFeed,
Expand All @@ -23,7 +23,7 @@ export function createTypeFile(names: string[]) {
undefined,
factory.createUnionTypeNode(
names.map((name) => {
return factory.createLiteralTypeNode(factory.createStringLiteral(name, true));
return factory.createLiteralTypeNode(factory.createStringLiteral(kebabCase(name), true));
})
)
),
Expand Down

0 comments on commit b17183c

Please sign in to comment.