1
- import { spawn } from 'node:child_process'
2
1
import path from 'node:path'
3
2
import { warm } from '@epic-web/workshop-cli/warm'
4
3
import {
5
4
getApps ,
6
5
isProblemApp ,
7
6
setPlayground ,
8
7
} from '@epic-web/workshop-utils/apps.server'
8
+ import { execa } from 'execa'
9
9
import fsExtra from 'fs-extra'
10
10
11
11
await warm ( )
@@ -14,41 +14,16 @@ const allApps = await getApps()
14
14
15
15
console . log ( '🔗 Generating React Router types' )
16
16
for ( 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' ,
33
21
} )
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
+ }
52
27
}
53
28
54
29
const problemApps = allApps . filter ( isProblemApp )
0 commit comments