@@ -111,7 +111,7 @@ const getComponentAbsPath =
111111 * If no scope is provided, returns the empty string.
112112 */
113113const normalizeScope = ( scope : string ) : string =>
114- scope ? `@${ scope . replace ( / ^ @ ( .* ) \/ $ / , '$1 ' ) } /` : '' ;
114+ scope ? `@${ scope . replace ( / ^ ( @ + ) ( .* ) \/ $ / , '$2 ' ) } /` : '' ;
115115
116116/** Get template interpolation data from options */
117117const getInterpolations =
@@ -121,7 +121,7 @@ const getInterpolations =
121121 const className = Case . pascal ( options . tagName ) ;
122122 const readmeName = Case . title ( options . tagName . replace ( / ^ \w + - ( .* ) / , '$1' ) ) ;
123123 const scope = ! options . scope ? '' : normalizeScope ( options . scope ) ;
124- const packageName = `${ scope } ${ tagName } ` ;
124+ const packageName = `${ scope } ${ tagName } ` . replace ( / ^ @ + / , '@' ) ;
125125 return {
126126 className,
127127 cssName,
@@ -219,17 +219,27 @@ async function updateTsconfig(options: GenerateElementOptions): Promise<void> {
219219 const configPath = join ( process . cwd ( ) , 'tsconfig.settings.json' ) ;
220220 const { packageName, tagName } = getInterpolations ( options ) ;
221221 const config = await readJson < Tsconfig > ( configPath ) ;
222- if ( ! config ?. compilerOptions ?. paths ) {
223- return ;
222+
223+ if ( config ?. compilerOptions ?. paths ) {
224+ config . compilerOptions . paths [ packageName ] = [ join ( `./elements/${ tagName } /${ tagName } .ts` ) ] ;
224225 }
225- config . compilerOptions . paths [ packageName ] = [ join ( `./elements/ ${ tagName } / ${ tagName } .ts` ) ] ;
226- if ( ! config . references . some ( x => x . path === `./elements/${ tagName } ` ) ) {
226+
227+ if ( ! config . references ? .some ( x => x . path === `./elements/${ tagName } ` ) ) {
227228 config . references . push ( { 'path' : `./elements/${ tagName } ` } ) ;
228229 }
230+
229231 await writeFile ( configPath , JSON . stringify ( config , null , 2 ) , 'utf8' ) ;
230232 await execaCommand ( `npx eslint --fix ${ configPath } ` ) ;
231233}
232234
235+ async function updateDocsBundle ( options : GenerateElementOptions ) : Promise < void > {
236+ const pathname = join ( process . cwd ( ) , 'docs' , 'demo' , 'bundle.ts' ) ;
237+ const content = await readFile ( pathname , 'utf8' ) ;
238+
239+ await writeFile ( pathname , `${ content } \nimport '@patternfly/${ options . tagName } ';` , 'utf8' ) ;
240+ await execaCommand ( `npx eslint --fix ${ pathname } ` ) ;
241+ }
242+
233243/**
234244 * Generate an Element
235245 */
@@ -246,5 +256,7 @@ export async function generateElement(options: GenerateElementOptions): Promise<
246256 await writeElementFiles ( options ) ;
247257 await analyzeElement ( options ) ;
248258 await updateTsconfig ( options ) ;
259+ await updateDocsBundle ( options ) ;
260+ await execaCommand ( 'npm install' ) ;
249261 }
250262}
0 commit comments