Skip to content

Commit

Permalink
feat(element): added all events arguments in TS declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed May 10, 2023
1 parent d6a0aca commit abb0688
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions scripts/build-types.js
Expand Up @@ -31,13 +31,24 @@ export default async function buildTypes() {
coreEventsContent = coreEventsContent
.split('// CORE_EVENTS_START')[1]
.split('// CORE_EVENTS_END')[0];
coreEventsElement = replaceInstances(
coreEventsContent.replace(/ ([a-zA-Z_?]*): ([^;]*);/g, (string, name) => {
if (name.includes('_')) {
coreEventsElement = coreEventsContent.replace(
/ ([a-zA-Z_?]*): ([^;]*);/g,
(string, name, args) => {
if (
name.includes('_') ||
name.toLowerCase() === 'classnames' ||
name.toLowerCase() === 'index'
) {
return '';
}
return ` ${name.toLowerCase()}: CustomEvent;`;
}),
args = args
.replace('(', '')
.replace(')', '')
.split('=>')[0]
.replace('SwiperClass', 'Swiper')
.trim();
return ` ${name.toLowerCase()}: CustomEvent<[${args}]>;`;
},
);
coreEventsReact = replaceInstances(
coreEventsContent.replace(/ ([a-zA-Z]*): \(/g, (string, name) => {
Expand All @@ -60,10 +71,17 @@ export default async function buildTypes() {
let eventsContent = await fs.readFile(eventsFile, 'utf-8');
eventsContent = eventsContent.split('Events {')[1].split('}')[0].trim();
if (eventsContent.length) {
modulesEventsElement += replaceInstances(
eventsContent.replace(/ ([a-zA-Z]*): ([^;]*);/g, (string, name) => {
return ` ${name.toLowerCase()}: CustomEvent;`;
}),
modulesEventsElement += eventsContent.replace(
/ ([a-zA-Z]*): ([^;]*);/g,
(string, name, args) => {
args = args
.replace('(', '')
.replace(')', '')
.split('=>')[0]
.replace('SwiperClass', 'Swiper')
.trim();
return ` ${name.toLowerCase()}: CustomEvent<[${args}]>;`;
},
);
modulesEventsReact += replaceInstances(
eventsContent.replace(/ ([a-zA-Z]*): \(/g, (string, name) => {
Expand Down

0 comments on commit abb0688

Please sign in to comment.