Skip to content

Commit c04396d

Browse files
committed
Add the possibility to the webcomponents-react wrapper script to only create a single component
1 parent 4f3a68a commit c04396d

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

packages/main/scripts/create-web-components-wrapper.js

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ console.warn(
55
'Currently there are two tag-names missing or faulty: "ui5-notification-overflow-action" and "ui5-timeline-item"\n These have to be adjusted manually!\n'
66
);
77

8+
// To only create a single component, add the component (module) name here:
9+
CREATE_SINGLE_COMPONENT = false;
10+
811
const mainWebComponentsSpec = require('@ui5/webcomponents/dist/api.json');
912
const fioriWebComponentsSpec = require('@ui5/webcomponents-fiori/dist/api.json');
1013
const dedent = require('dedent');
@@ -732,59 +735,61 @@ resolvedWebComponents.forEach((componentSpec) => {
732735
};
733736

734737
const [mainDescription, description = ''] = formatDescription();
738+
if (CREATE_SINGLE_COMPONENT === componentSpec.module || !CREATE_SINGLE_COMPONENT) {
739+
const webComponentWrapper = createWebComponentWrapper(
740+
componentSpec.module,
741+
componentSpec.tagname,
742+
mainDescription,
743+
propTypes,
744+
uniqueAdditionalImports,
745+
defaultProps,
746+
(componentSpec.properties || [])
747+
.filter(filterNonPublicAttributes)
748+
.filter(({ type }) => type !== 'boolean' && type !== 'Boolean')
749+
.map(({ name }) => name),
750+
(componentSpec.properties || [])
751+
.filter(filterNonPublicAttributes)
752+
.filter(({ type }) => type === 'boolean' || type === 'Boolean')
753+
.map(({ name }) => name),
754+
(componentSpec.slots || []).filter(filterNonPublicAttributes).map(({ name }) => name),
755+
(componentSpec.events || []).filter(filterNonPublicAttributes).map(({ name }) => name)
756+
);
735757

736-
const webComponentWrapper = createWebComponentWrapper(
737-
componentSpec.module,
738-
componentSpec.tagname,
739-
mainDescription,
740-
propTypes,
741-
uniqueAdditionalImports,
742-
defaultProps,
743-
(componentSpec.properties || [])
744-
.filter(filterNonPublicAttributes)
745-
.filter(({ type }) => type !== 'boolean' && type !== 'Boolean')
746-
.map(({ name }) => name),
747-
(componentSpec.properties || [])
748-
.filter(filterNonPublicAttributes)
749-
.filter(({ type }) => type === 'boolean' || type === 'Boolean')
750-
.map(({ name }) => name),
751-
(componentSpec.slots || []).filter(filterNonPublicAttributes).map(({ name }) => name),
752-
(componentSpec.events || []).filter(filterNonPublicAttributes).map(({ name }) => name)
753-
);
754-
755-
// check if folder exists and create it if necessary
756-
const webComponentFolderPath = path.join(WEB_COMPONENTS_ROOT_DIR, componentSpec.module);
757-
if (!fs.existsSync(webComponentFolderPath)) {
758-
fs.mkdirSync(webComponentFolderPath);
759-
}
758+
// check if folder exists and create it if necessary
759+
const webComponentFolderPath = path.join(WEB_COMPONENTS_ROOT_DIR, componentSpec.module);
760+
if (!fs.existsSync(webComponentFolderPath)) {
761+
fs.mkdirSync(webComponentFolderPath);
762+
}
760763

761-
fs.writeFileSync(path.join(webComponentFolderPath, 'index.tsx'), webComponentWrapper);
764+
fs.writeFileSync(path.join(webComponentFolderPath, 'index.tsx'), webComponentWrapper);
762765

763-
// create lib export
764-
const libContent = prettier.format(
765-
`
766+
// create lib export
767+
const libContent = prettier.format(
768+
`
766769
import { ${componentSpec.module} } from '../webComponents/${componentSpec.module}';
767770
import type { ${componentSpec.module}PropTypes } from '../webComponents/${componentSpec.module}';
768771
769772
export { ${componentSpec.module} };
770773
export type { ${componentSpec.module}PropTypes };`,
771-
prettierConfig
772-
);
773-
fs.writeFileSync(path.join(LIB_DIR, `${componentSpec.module}.ts`), libContent);
774+
prettierConfig
775+
);
776+
fs.writeFileSync(path.join(LIB_DIR, `${componentSpec.module}.ts`), libContent);
774777

775-
// create test
776-
if (!fs.existsSync(path.join(webComponentFolderPath, `${componentSpec.module}.test.tsx`))) {
777-
const webComponentTest = createWebComponentTest(componentSpec.module);
778-
fs.writeFileSync(path.join(webComponentFolderPath, `${componentSpec.module}.test.tsx`), webComponentTest);
779-
}
778+
// create test
779+
if (!fs.existsSync(path.join(webComponentFolderPath, `${componentSpec.module}.test.tsx`))) {
780+
const webComponentTest = createWebComponentTest(componentSpec.module);
781+
fs.writeFileSync(path.join(webComponentFolderPath, `${componentSpec.module}.test.tsx`), webComponentTest);
782+
}
780783

781-
// create demo
782-
if (
783-
!fs.existsSync(path.join(webComponentFolderPath, `${componentSpec.module}.stories.tsx`)) &&
784-
!fs.existsSync(path.join(webComponentFolderPath, `${componentSpec.module}.stories.mdx`)) &&
785-
!COMPONENTS_WITHOUT_DEMOS.has(componentSpec.module)
786-
) {
787-
const webComponentDemo = createWebComponentDemo(componentSpec, allComponentProperties, description);
788-
fs.writeFileSync(path.join(webComponentFolderPath, `${componentSpec.module}.stories.mdx`), webComponentDemo);
784+
// create demo
785+
if (
786+
CREATE_SINGLE_COMPONENT === componentSpec.module ||
787+
(!fs.existsSync(path.join(webComponentFolderPath, `${componentSpec.module}.stories.tsx`)) &&
788+
!fs.existsSync(path.join(webComponentFolderPath, `${componentSpec.module}.stories.mdx`)) &&
789+
!COMPONENTS_WITHOUT_DEMOS.has(componentSpec.module))
790+
) {
791+
const webComponentDemo = createWebComponentDemo(componentSpec, allComponentProperties, description);
792+
fs.writeFileSync(path.join(webComponentFolderPath, `${componentSpec.module}.stories.mdx`), webComponentDemo);
793+
}
789794
}
790795
});

0 commit comments

Comments
 (0)