Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(svg-generator): add kebab-case transform to type generator (#143) #144

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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