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 4761160
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
11 changes: 10 additions & 1 deletion svg-generator/__tests__/__snapshots__/create-tree.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ 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';
Expand Down Expand Up @@ -78,6 +87,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 4761160

Please sign in to comment.