1- import { spawn } from 'node:child_process'
21import path from 'node:path'
32import { warm } from '@epic-web/workshop-cli/warm'
43import {
54 getApps ,
65 isProblemApp ,
76 setPlayground ,
87} from '@epic-web/workshop-utils/apps.server'
8+ import { execa } from 'execa'
99import fsExtra from 'fs-extra'
1010
1111await warm ( )
@@ -14,41 +14,16 @@ const allApps = await getApps()
1414
1515console . log ( '🔗 Generating React Router types' )
1616for ( const app of allApps ) {
17- // run npx react-router typegen in app
18- await runWithOutputOnFailure ( 'npx' , [ 'react-router' , 'typegen' ] , {
19- cwd : app . fullPath ,
20- } )
21- }
22-
23- function runWithOutputOnFailure ( command , args , options ) {
24- // { type: 'stdout', data: Buffer }
25- const outputBuffer = [ ]
26- return new Promise ( ( resolve , reject ) => {
27- const child = spawn ( command , args , {
28- ...options ,
29- stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
30- } )
31- child . stdout . on ( 'data' , ( data ) => {
32- outputBuffer . push ( { type : 'stdout' , data } )
17+ try {
18+ await execa ( 'react-router' , [ 'typegen' ] , {
19+ cwd : app . fullPath ,
20+ stdio : 'pipe' ,
3321 } )
34- child . stderr . on ( 'data' , ( data ) => {
35- outputBuffer . push ( { type : 'stderr' , data } )
36- } )
37- child . on ( 'close' , ( code ) => {
38- if ( code !== 0 ) {
39- for ( const { type, data } of outputBuffer ) {
40- if ( type === 'stderr' ) {
41- process . stderr . write ( data )
42- } else {
43- process . stdout . write ( data )
44- }
45- }
46- reject ( code )
47- } else {
48- resolve ( 'ok' )
49- }
50- } )
51- } )
22+ } catch ( error ) {
23+ if ( error . stdout ) process . stdout . write ( error . stdout )
24+ if ( error . stderr ) process . stderr . write ( error . stderr )
25+ throw error
26+ }
5227}
5328
5429const problemApps = allApps . filter ( isProblemApp )
0 commit comments