@@ -314,6 +314,63 @@ export default function (
314314 path : "bricks/{{pkgName}}/docs/{{>lastTagName}}.md" ,
315315 templateFile : "templates/brick.md.hbs" ,
316316 } ,
317+ async function updateJsxDts ( answers ) {
318+ const jsxDtsFile = path . join (
319+ bricksDir ,
320+ answers . pkgName ,
321+ "src/jsx.d.ts"
322+ ) ;
323+ /** @type {string } */
324+ let jsxDtsContent ;
325+ if ( ! existsSync ( jsxDtsFile ) ) {
326+ // jsxDtsContent = `import type { DetailedHTMLProps, HTMLAttributes } from "react"`;
327+ const jsxDtsTemplateFile = path . join (
328+ __dirname ,
329+ "templates/bricks/src/jsx.d.ts.hbs"
330+ ) ;
331+ jsxDtsContent = await readFile ( jsxDtsTemplateFile , "utf-8" ) ;
332+ } else {
333+ jsxDtsContent = await readFile ( jsxDtsFile , "utf-8" ) ;
334+ }
335+ const tagName = plop . renderString (
336+ "{{getTagName brickType pkgName brickName false false}}" ,
337+ answers
338+ ) ;
339+ const className = plop . renderString (
340+ "{{pascalCase (getTagName brickType pkgName brickName true true)}}" ,
341+ answers
342+ ) ;
343+ const propName = `${ className } Props` ;
344+ const importStatement = `import type { ${ className } , ${ propName } } from "./${ answers . brickName } ";` ;
345+ const definitionProp = ` "${ tagName } ": DetailedHTMLProps<HTMLAttributes<${ className } >, ${ className } > & ${ propName } ;` ;
346+
347+ /** @type {[RegExp, string][] } */
348+ const replacementPatterns = [
349+ [
350+ / ( \r ? \n ) ( \r ? \n ) ? ( d e c l a r e g l o b a l ) / ,
351+ `$1${ importStatement } $1$2$3` ,
352+ ] ,
353+ [
354+ // eslint-disable-next-line no-regex-spaces
355+ / ( \r ? \n ) ( \} \r ? \n \} \r ? \n \} \r ? \n ) $ / ,
356+ `$1${ definitionProp } $1$2` ,
357+ ] ,
358+ ] ;
359+
360+ let newJsxDts = jsxDtsContent ;
361+ for ( const [ pattern , replacement ] of replacementPatterns ) {
362+ newJsxDts = jsxDtsContent . replace ( pattern , replacement ) ;
363+ if ( newJsxDts === jsxDtsContent ) {
364+ throw new Error (
365+ `Failed to add definition in jsx.d.ts for ${ tagName } .`
366+ ) ;
367+ }
368+ jsxDtsContent = newJsxDts ;
369+ }
370+
371+ await writeFile ( jsxDtsFile , jsxDtsContent ) ;
372+ return `Updated jsx.d.ts to include ${ tagName } definition.` ;
373+ } ,
317374 async function modifyCommonBricksJson ( answers ) {
318375 if ( answers . brickType === "common" ) {
319376 const realBrickName = `eo-${ answers . brickName } ` ;
0 commit comments