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

refactor(ts): cleanup output and use as const and type extraction #411

Open
wants to merge 1 commit into
base: chores/update-typescript-and-other-dependencies
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export const DEFAULT_OPTIONS: Omit<RunnerOptions, 'inputDir' | 'outputDir'> = {
OtherAssetType.JSON,
OtherAssetType.TS
],
formatOptions: { json: { indent: 4 } },
formatOptions: {
json: { indent: 4 },
ts: { types: ['stringLiteral', 'enum'] }
},
pathOptions: {},
templates: {},
codepoints: {},
Expand Down
133 changes: 1 addition & 132 deletions src/generators/asset-types/__tests__/__snapshots__/ts.ts.snap
Original file line number Diff line number Diff line change
@@ -1,134 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`\`TS\` asset generator generates constant only 1`] = `
"export const MY_ICONS_SET_CODEPOINTS: Record<string, string> = {
\\"foo\\": \\"4265\\",
\\"bar\\": \\"1231\\",
};
"
`;

exports[`\`TS\` asset generator generates constant with literalId if no enum generated 1`] = `
"export type MyIconsSetId =
| \\"foo\\"
| \\"bar\\";

export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSetId]: string } = {
\\"foo\\": \\"4265\\",
\\"bar\\": \\"1231\\",
};
"
`;

exports[`\`TS\` asset generator generates constant with literalKey if no enum generated 1`] = `
"export type MyIconsSetKey =
| \\"Foo\\"
| \\"Bar\\";

export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSetKey]: string } = {
\\"foo\\": \\"4265\\",
\\"bar\\": \\"1231\\",
};
"
`;

exports[`\`TS\` asset generator generates no key string literal type if option passed like that 1`] = `
"export enum MyIconsSet {
Foo = \\"foo\\",
Bar = \\"bar\\",
}

export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = {
[MyIconsSet.Foo]: \\"4265\\",
[MyIconsSet.Bar]: \\"1231\\",
};
"
`;

exports[`\`TS\` asset generator generates single quotes if format option passed 1`] = `
"export type MyIconsSetId =
| 'foo'
| 'bar';

export type MyIconsSetKey =
| 'Foo'
| 'Bar';

export enum MyIconsSet {
Foo = 'foo',
Bar = 'bar',
}

export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = {
[MyIconsSet.Foo]: '4265',
[MyIconsSet.Bar]: '1231',
};
"
`;

exports[`\`TS\` asset generator prevents enum keys that start with digits 1`] = `
"export type MyIconsSetId =
| \\"1234\\"
| \\"5678\\";

export type MyIconsSetKey =
| \\"i1234\\"
| \\"i5678\\";

export enum MyIconsSet {
i1234 = \\"1234\\",
i5678 = \\"5678\\",
}

export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = {
[MyIconsSet.i1234]: \\"undefined\\",
[MyIconsSet.i5678]: \\"undefined\\",
};
"
`;

exports[`\`TS\` asset generator prevents enum keys that start with digits when digits and chars 1`] = `
"export type MyIconsSetId =
| \\"1234asdf\\"
| \\"5678ab\\"
| \\"foo\\";

export type MyIconsSetKey =
| \\"i1234asdf\\"
| \\"i5678ab\\"
| \\"Foo\\";

export enum MyIconsSet {
i1234asdf = \\"1234asdf\\",
i5678ab = \\"5678ab\\",
Foo = \\"foo\\",
}

export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = {
[MyIconsSet.i1234asdf]: \\"undefined\\",
[MyIconsSet.i5678ab]: \\"undefined\\",
[MyIconsSet.Foo]: \\"4265\\",
};
"
`;

exports[`\`TS\` asset generator renders expected TypeScript module content 1`] = `
"export type MyIconsSetId =
| \\"foo\\"
| \\"bar\\";

export type MyIconsSetKey =
| \\"Foo\\"
| \\"Bar\\";

export enum MyIconsSet {
Foo = \\"foo\\",
Bar = \\"bar\\",
}

export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = {
[MyIconsSet.Foo]: \\"4265\\",
[MyIconsSet.Bar]: \\"1231\\",
};
"
`;
exports[`\`TS\` asset generator renders expected TypeScript module content 1`] = `"export enum MyIconsSet { Foo = \\"foo\\", Bar = \\"bar\\", } export type MyIconsSetId = \`MyIconsSet\`; export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSetId]: string } = { \\"foo\\": \\"4265\\", \\"bar\\": \\"1231\\", }; "`;
Loading