@@ -3,7 +3,7 @@ import type { GenerateElementOptions } from '../main';
33import Case from 'case' ;
44import Chalk from 'chalk' ;
55import prompts from 'prompts' ;
6- import { execa } from 'execa' ;
6+ import { $ } from 'execa' ;
77
88import { fileURLToPath } from 'url' ;
99import { dirname , join , relative } from 'path' ;
@@ -142,46 +142,6 @@ async function writeComponentFile(key: FileKey, options: GenerateElementOptions)
142142 }
143143}
144144
145- async function writeElementFiles ( options : GenerateElementOptions ) {
146- if ( ! await shouldWriteToDir ( options ) ) {
147- return ;
148- }
149-
150- if ( ! options . silent ) {
151- console . log ( `\nCreating ${ green ( options . tagName ) } in ${ getComponentPathFromDirectoryOption ( options ) } \n` ) ;
152- }
153-
154- // $ mkdir -p /Users/alj/jazz-elements/elements/pf-jazz-hands
155- await mkdirp ( getComponentAbsPath ( options ) ) ;
156-
157- for ( const key of Object . keys ( FileKey ) . sort ( ) as FileKey [ ] ) {
158- await writeComponentFile ( key , options ) ;
159- }
160-
161- if ( ! options . silent ) {
162- console . log ( `\n${ greenBright ( 'Done!' ) } ` ) ;
163- }
164- }
165-
166- async function analyzeElement ( options : GenerateElementOptions ) : Promise < void > {
167- if ( ! options . silent ) {
168- console . log ( `\nAnalyzing ${ greenBright ( options . tagName ) } ` ) ;
169- }
170-
171- const { stderr, stdout } =
172- await execa ( 'npm' , [ 'run' , 'analyze' , ] , {
173- all : true ,
174- cwd : options . directory ,
175- } ) ;
176-
177- if ( stderr ) {
178- console . log ( stderr ) ;
179- throw new Error ( `Could not analyze ${ options . tagName } ` ) ;
180- } else if ( ! options . silent ) {
181- console . log ( stdout ) ;
182- }
183- }
184-
185145/**
186146 * Generate an Element
187147 */
@@ -191,11 +151,27 @@ export async function generateElement(options: GenerateElementOptions): Promise<
191151 return ;
192152 }
193153
154+ const log = ( ...args : unknown [ ] ) => ! options . silent && console . log ( ...args ) ;
155+
156+ const $$ = $ ( { stderr : 'inherit' } ) ;
157+
158+ const packageJsonPath = join ( options . directory , 'package.json' ) ;
194159 // Quit if trying to scaffold an element in an uninitialized non-monorepo
195- if ( ! await exists ( join ( options . directory , 'package.json' ) ) ) {
160+ if ( ! await exists ( packageJsonPath ) ) {
196161 return console . log ( '‼️ No package.json found.' , '� Scaffold a repository first' ) ;
162+ } else if ( ! await shouldWriteToDir ( options ) ) {
163+ return ;
197164 } else {
198- await writeElementFiles ( options ) ;
199- analyzeElement ; // skip this for now, come back to fix later
165+ log ( `\nCreating ${ green ( options . tagName ) } in ${ getComponentPathFromDirectoryOption ( options ) } \n` ) ;
166+ // $ mkdir -p /Users/alj/jazz-elements/elements/pf-jazz-hands
167+ await mkdirp ( getComponentAbsPath ( options ) ) ;
168+ for ( const key of Object . keys ( FileKey ) . sort ( ) as FileKey [ ] ) {
169+ await writeComponentFile ( key , options ) ;
170+ }
171+ log ( `Linting package exports...` ) ;
172+ await $$ `npx eslint ${ packageJsonPath } --fix` ;
173+ log ( `Analyzing elements...` ) ;
174+ await $$ `npm run analyze` ;
175+ log ( `\n${ greenBright ( 'Done!' ) } ` ) ;
200176 }
201177}
0 commit comments