File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { compileSearchIndex } from "react-lib-tools/scripts/compile-search-index.ts" ;
2+ import { createConnection } from "net" ;
3+
4+ // TODO
5+ async function waitUntilConnected ( {
6+ host = "localhost" ,
7+ port = 3000 ,
8+ retryAttempts = 10 ,
9+ retryDelay = 1_000
10+ } : {
11+ host ?: string ;
12+ port ?: number ;
13+ retryAttempts ?: number ;
14+ retryDelay ?: number ;
15+ } = { } ) {
16+ console . log ( `Checking ${ host } :${ port } ...` ) ;
17+ return new Promise < void > ( ( resolve , reject ) => {
18+ const socket = createConnection ( { host, port } ) ;
19+ socket . addListener ( "connect" , ( ) => {
20+ console . log ( "Connected" ) ;
21+
22+ socket . destroy ( ) ;
23+
24+ resolve ( ) ;
25+ } ) ;
26+ socket . addListener ( "error" , ( ) => {
27+ socket . destroy ( ) ;
28+
29+ if ( retryAttempts > 1 ) {
30+ console . log ( `Retrying after ${ retryDelay } ms...` ) ;
31+
32+ setTimeout ( ( ) => {
33+ waitUntilConnected ( {
34+ host,
35+ port,
36+ retryAttempts : retryAttempts - 1 ,
37+ retryDelay
38+ } ) . then ( resolve , reject ) ;
39+ } , retryDelay ) ;
40+ } else {
41+ console . error ( "Host not available" ) ;
42+
43+ process . exit ( 1 ) ;
44+ }
45+ } ) ;
46+ } ) ;
47+ }
48+
49+ await waitUntilConnected ( ) ;
50+ // TODO
251
352await compileSearchIndex ( {
453 chromeExecutablePath : process . env . CHROME_PATH ,
You can’t perform that action at this time.
0 commit comments