From b17183c3d25bd9b76223bd585558dfb2fd0030d5 Mon Sep 17 00:00:00 2001 From: Valentin Moser Date: Tue, 12 Dec 2023 23:02:31 +0100 Subject: [PATCH] fix(svg-generator): add kebab-case transform to type generator (#143) --- .../__snapshots__/create-tree.spec.ts.snap | 14 ++++++++++++-- svg-generator/__tests__/create-tree.spec.ts | 3 ++- svg-generator/create-types.ts | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/svg-generator/__tests__/__snapshots__/create-tree.spec.ts.snap b/svg-generator/__tests__/__snapshots__/create-tree.spec.ts.snap index c11bcd6..bdeff45 100644 --- a/svg-generator/__tests__/__snapshots__/create-tree.spec.ts.snap +++ b/svg-generator/__tests__/__snapshots__/create-tree.spec.ts.snap @@ -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: \`child_copy\`, + 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__", @@ -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'; " `; diff --git a/svg-generator/__tests__/create-tree.spec.ts b/svg-generator/__tests__/create-tree.spec.ts index 468a6f4..d4e183c 100644 --- a/svg-generator/__tests__/create-tree.spec.ts +++ b/svg-generator/__tests__/create-tree.spec.ts @@ -13,6 +13,7 @@ describe('createTree', () => { [`${srcPath}/group`]: { 'child.svg': `child`, 'child2.svg': `child 2`, + 'child_copy.svg': `child_copy` }, [`${srcPath}/group-two`]: { 'child-one.svg': `child`, @@ -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(); }); }); diff --git a/svg-generator/create-types.ts b/svg-generator/create-types.ts index fb143ed..1d8a64e 100644 --- a/svg-generator/create-types.ts +++ b/svg-generator/create-types.ts @@ -5,9 +5,9 @@ import { ScriptTarget, ScriptKind, factory, - NodeFlags, SyntaxKind, } from 'typescript'; +import kebabCase from 'lodash.kebabcase'; const printer = createPrinter({ newLine: NewLineKind.LineFeed, @@ -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)); }) ) ),