Skip to content
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
2 changes: 2 additions & 0 deletions src/components/component-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function castI18nTag(tag: string | undefined) {

export function buildComponentDefinition(
name: string,
dashCaseName: string,
props: Array<ExpandedProp>,
functions: Array<ExpandedProp>,
defaultValues: Record<string, string>,
Expand All @@ -48,6 +49,7 @@ export function buildComponentDefinition(

return {
name,
dashCaseName,
releaseStatus: 'stable',
description: componentDescription.text,
systemTags: getCommentTags(componentDescription, 'awsuiSystem'),
Expand Down
16 changes: 12 additions & 4 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { bootstrapTypescriptProject } from '../bootstrap/typescript';
import { extractDeclaration, getDescription } from './type-utils';

function componentNameFromPath(componentPath: string) {
const directoryName = pathe.dirname(componentPath);
return pascalCase(pathe.basename(directoryName));
const dashCaseName = pathe.basename(pathe.dirname(componentPath));
return { dashCaseName, name: pascalCase(dashCaseName) };
}

interface DocumenterOptions {
Expand All @@ -36,7 +36,7 @@ export function documentComponents(
.filter(file => isMatch(file.fileName))
.map(sourceFile => {
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
const name = componentNameFromPath(sourceFile.fileName);
const { name, dashCaseName } = componentNameFromPath(sourceFile.fileName);

// istanbul ignore next
if (!moduleSymbol) {
Expand All @@ -57,6 +57,14 @@ export function documentComponents(
extractDeclaration(componentSymbol)
);

return buildComponentDefinition(name, props, functions, defaultValues, componentDescription, checker);
return buildComponentDefinition(
name,
dashCaseName,
props,
functions,
defaultValues,
componentDescription,
checker
);
});
}
1 change: 1 addition & 0 deletions src/components/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
export interface ComponentDefinition {
name: string;
dashCaseName: string;
/** @deprecated */
releaseStatus: string;
/** @deprecated */
Expand Down
11 changes: 11 additions & 0 deletions test/components/complex-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ beforeAll(() => {
[buttonGroup, columnLayout, sideNavigation, table] = result;
});

test('should have camel and dash-cased names', () => {
expect(buttonGroup.name).toEqual('ButtonGroup');
expect(buttonGroup.dashCaseName).toEqual('button-group');
expect(sideNavigation.name).toEqual('SideNavigation');
expect(sideNavigation.dashCaseName).toEqual('side-navigation');
expect(columnLayout.name).toEqual('ColumnLayout');
expect(columnLayout.dashCaseName).toEqual('column-layout');
expect(table.name).toEqual('Table');
expect(table.dashCaseName).toEqual('table');
});

test('should only have expected properties, regions and events', () => {
expect(table.properties.map(prop => prop.name)).toEqual(['ariaLabels', 'columns', 'filteringFn', 'items', 'trackBy']);
expect(table.events.map(prop => prop.name)).toEqual(['onWidthChange']);
Expand Down
Loading