Skip to content

Commit e6270c8

Browse files
authored
[Website] Fix layout and form primitive component names missed by changelog script (#2929)
1 parent c3fe034 commit e6270c8

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

website/lib/changelog/generate-component-changelog-entries.mjs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,33 @@ const getComponentPaths = (baseDir) => {
2626
const componentPath = `${baseDir}/${folder.name}`;
2727
const partialsPath = `${componentPath}/partials`;
2828
if (fs.existsSync(partialsPath)) {
29-
// we have two special cases where intermediate namespacing is used to group components:
30-
// `copy` components and `link` components
29+
// we have some special cases where intermediate namespacing is used to group components:
3130
if (baseDir.endsWith('/copy')) {
3231
components[`copy-${folder.name}`] = componentPath;
32+
} else if (baseDir.endsWith('/form')) {
33+
if (folder.name === 'primitives') {
34+
const primitiveNames = [
35+
'character-count',
36+
'error',
37+
'field',
38+
'fieldset',
39+
'helper-text',
40+
'indicator',
41+
'label',
42+
'legend',
43+
];
44+
primitiveNames.forEach((componentName) => {
45+
components[`form-${componentName}`] = componentPath;
46+
});
47+
} else {
48+
components[`form-${folder.name}`] = componentPath;
49+
}
50+
} else if (baseDir.endsWith('/layouts')) {
51+
if (folder.name === 'app-frame') {
52+
components[`${folder.name}`] = componentPath;
53+
} else {
54+
components[`layout-${folder.name}`] = componentPath;
55+
}
3356
} else if (baseDir.endsWith('/link')) {
3457
components[`link-${folder.name}`] = componentPath;
3558
} else if (baseDir.endsWith('/stepper')) {
@@ -69,15 +92,26 @@ const extractVersion = (changelogContent, version) => {
6992
};
7093

7194
const convertComponentNameFormat = (componentName) => {
72-
let separator = '';
73-
const multiLevelComponentNames = ['copy', 'link', 'stepper'];
74-
if (multiLevelComponentNames.includes(componentName.split('-')[0])) {
75-
separator = '::';
95+
const twoLevelComponentNames = ['copy', 'form', 'layout', 'link', 'stepper'];
96+
const threeLevelComponentNames = [
97+
'stepper-step-indicator',
98+
'stepper-task-indicator',
99+
];
100+
if (twoLevelComponentNames.includes(componentName.split('-')[0])) {
101+
let words = componentName
102+
.split('-')
103+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1));
104+
if (threeLevelComponentNames.includes(componentName)) {
105+
return words.join('::');
106+
} else {
107+
return words[0] + '::' + words.slice(1).join('');
108+
}
109+
} else {
110+
return componentName
111+
.split('-')
112+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
113+
.join('');
76114
}
77-
return componentName
78-
.split('-')
79-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
80-
.join(separator);
81115
};
82116

83117
const extractComponentChangelogEntries = (components, lastVersionContent) => {
@@ -113,7 +147,17 @@ const updateComponentVersionHistory = (componentChangelogEntries, version) => {
113147
if (!versionHistoryContent.includes(`## ${version}`)) {
114148
// for each entry, remove the component name and keep only the description (assuming the "`ComponentName` - Description" format)
115149
const newEntries = componentChangelogEntries[componentName]
116-
.map((entry) => entry.split(' - ')[1])
150+
.map((entry) => {
151+
// If the component is a form primitive, we want to keep the component name in the description
152+
if (
153+
allComponentsPath[componentName] ===
154+
'./docs/components/form/primitives'
155+
) {
156+
return entry;
157+
} else {
158+
return entry.split(' - ')[1];
159+
}
160+
})
117161
.join('\n\n');
118162
const newHeading = `## ${version}\n\n${newEntries}\n\n${versionHistoryContent}`;
119163
fs.writeFileSync(versionHistoryPath, newHeading, 'utf8');

0 commit comments

Comments
 (0)