Skip to content

Commit 02fcced

Browse files
authored
feat: Export dash-cased names (#63)
1 parent 98b1a89 commit 02fcced

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/components/component-definition.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function castI18nTag(tag: string | undefined) {
3636

3737
export function buildComponentDefinition(
3838
name: string,
39+
dashCaseName: string,
3940
props: Array<ExpandedProp>,
4041
functions: Array<ExpandedProp>,
4142
defaultValues: Record<string, string>,
@@ -48,6 +49,7 @@ export function buildComponentDefinition(
4849

4950
return {
5051
name,
52+
dashCaseName,
5153
releaseStatus: 'stable',
5254
description: componentDescription.text,
5355
systemTags: getCommentTags(componentDescription, 'awsuiSystem'),

src/components/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { bootstrapTypescriptProject } from '../bootstrap/typescript';
1111
import { extractDeclaration, getDescription } from './type-utils';
1212

1313
function componentNameFromPath(componentPath: string) {
14-
const directoryName = pathe.dirname(componentPath);
15-
return pascalCase(pathe.basename(directoryName));
14+
const dashCaseName = pathe.basename(pathe.dirname(componentPath));
15+
return { dashCaseName, name: pascalCase(dashCaseName) };
1616
}
1717

1818
export interface DocumenterOptions {
@@ -57,7 +57,7 @@ export function documentComponents(
5757
.filter(file => isMatch(file.fileName))
5858
.map(sourceFile => {
5959
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
60-
const name = componentNameFromPath(sourceFile.fileName);
60+
const { name, dashCaseName } = componentNameFromPath(sourceFile.fileName);
6161

6262
// istanbul ignore next
6363
if (!moduleSymbol) {
@@ -78,6 +78,14 @@ export function documentComponents(
7878
extractDeclaration(componentSymbol)
7979
);
8080

81-
return buildComponentDefinition(name, props, functions, defaultValues, componentDescription, checker);
81+
return buildComponentDefinition(
82+
name,
83+
dashCaseName,
84+
props,
85+
functions,
86+
defaultValues,
87+
componentDescription,
88+
checker
89+
);
8290
});
8391
}

src/components/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
export interface ComponentDefinition {
44
name: string;
5+
dashCaseName: string;
56
/** @deprecated */
67
releaseStatus: string;
78
/** @deprecated */

test/components/complex-types.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ beforeAll(() => {
1515
[buttonGroup, columnLayout, sideNavigation, table] = result;
1616
});
1717

18+
test('should have camel and dash-cased names', () => {
19+
expect(buttonGroup.name).toEqual('ButtonGroup');
20+
expect(buttonGroup.dashCaseName).toEqual('button-group');
21+
expect(sideNavigation.name).toEqual('SideNavigation');
22+
expect(sideNavigation.dashCaseName).toEqual('side-navigation');
23+
expect(columnLayout.name).toEqual('ColumnLayout');
24+
expect(columnLayout.dashCaseName).toEqual('column-layout');
25+
expect(table.name).toEqual('Table');
26+
expect(table.dashCaseName).toEqual('table');
27+
});
28+
1829
test('should only have expected properties, regions and events', () => {
1930
expect(table.properties.map(prop => prop.name)).toEqual(['ariaLabels', 'columns', 'filteringFn', 'items', 'trackBy']);
2031
expect(table.events.map(prop => prop.name)).toEqual(['onWidthChange']);

0 commit comments

Comments
 (0)