1- import { createMiniOxygen } from '@shopify/mini-oxygen' ;
1+ import { createMiniOxygen } from '@shopify/mini-oxygen' ;
2+
3+ /* eslint-disable no-console */
24
35/**
46 * This is script is a simple runner for our example app. This script will run
57 * the compiled example on a local worker implementation to emulate a Oxygen worker runtime.
6- *
8+ *
79 * For the actual example implementation, see the src/index.ts file.
810 */
911
10- const printValueAndBanner = ( flagKey , flagValue ) => {
12+ const printValueAndBanner = ( flagKey : string , flagValue : string ) => {
1113 console . log ( `*** The '${ flagKey } ' feature flag evaluates to ${ flagValue } .` ) ;
1214
1315 if ( flagValue ) {
@@ -24,7 +26,7 @@ const printValueAndBanner = (flagKey, flagValue) => {
2426 ` ,
2527 ) ;
2628 }
27- }
29+ } ;
2830
2931const main = async ( ) => {
3032 // NOTE: you will see logging coming from mini-oxygen's default request hook.
@@ -35,44 +37,46 @@ const main = async () => {
3537 {
3638 name : 'main' ,
3739 modules : true ,
38- scriptPath : 'dist/index.js'
40+ scriptPath : 'dist/index.js' ,
3941 } ,
4042 ] ,
4143 } ) ;
4244
4345 miniOxygen . ready . then ( ( ) => {
4446 console . log ( 'Oxygen worker is started...' ) ;
4547 console . log ( 'Press "q" or Ctrl+C to quit...' ) ;
46-
48+
4749 // Dispatch fetch every 5 seconds
4850 const interval = setInterval ( ( ) => {
4951 // NOTE: This is a bogus URL and will not be used in the actual fetch handler.
5052 // please see the src/index.ts file for the actual fetch handler.
51- miniOxygen . dispatchFetch ( 'https://localhost:8000' )
52- . then ( d => d . json ( ) )
53- . then ( ( { flagValue, flagKey} ) => {
53+ miniOxygen
54+ . dispatchFetch ( 'https://localhost:8000' as any )
55+ . then ( ( d ) => d . json ( ) as Promise < any > )
56+ . then ( ( { flagValue, flagKey } ) => {
5457 console . clear ( ) ;
5558 printValueAndBanner ( flagKey , flagValue ) ;
56- console . log ( 'Press "q" or Ctrl+C to quit...' )
57- } ) . catch ( ( err ) => {
59+ console . log ( 'Press "q" or Ctrl+C to quit...' ) ;
60+ } )
61+ . catch ( ( err ) => {
5862 console . log ( 'Error dispatching fetch:' , err . message ) ;
59- console . log ( 'Press "q" or Ctrl+C to quit...' )
63+ console . log ( 'Press "q" or Ctrl+C to quit...' ) ;
6064 } ) ;
6165 } , 1000 ) ;
62-
66+
6367 // Handle keypresses for cleanup
6468 process . stdin . setRawMode ( true ) ;
6569 process . stdin . resume ( ) ;
6670 process . stdin . setEncoding ( 'utf8' ) ;
67-
68- process . stdin . on ( 'data' , async ( key ) => {
71+
72+ process . stdin . on ( 'data' , async ( key : string ) => {
6973 // Handle Ctrl+C
7074 if ( key === '\u0003' ) {
7175 clearInterval ( interval ) ;
7276 await miniOxygen . dispose ( ) ;
7377 process . exit ( ) ;
7478 }
75-
79+
7680 // Handle 'q' key
7781 if ( key === 'q' || key === 'Q' ) {
7882 clearInterval ( interval ) ;
@@ -81,6 +85,6 @@ const main = async () => {
8185 }
8286 } ) ;
8387 } ) ;
84- }
88+ } ;
8589
8690main ( ) . catch ( console . error ) ;
0 commit comments