11import pc from 'picocolors' ;
2- import ora from 'ora' ;
32import { program } from 'commander' ;
43import type { FederatedGraph , Subgraph , WhoAmIResponse } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb' ;
54import { config } from '../../core/config.js' ;
@@ -24,6 +23,7 @@ import {
2423 resetScreen ,
2524 runRouterContainer ,
2625 updateScreenWithUserInfo ,
26+ demoSpinner ,
2727} from './util.js' ;
2828
2929function printHello ( ) {
@@ -54,7 +54,7 @@ async function handleGetFederatedGraphResponse(
5454 } ) ;
5555 }
5656
57- const spinner = ora ( ) . start ( ) ;
57+ const spinner = demoSpinner ( ) . start ( ) ;
5858 const getFederatedGraphResponse = await fetchFederatedGraphByName ( client , {
5959 name : config . demoGraphName ,
6060 namespace : config . demoNamespace ,
@@ -99,7 +99,7 @@ async function cleanupFederatedGraph(
9999 cleanupFederatedGraph ( client , { graphData, userInfo } ) ;
100100 }
101101
102- const spinner = ora ( ) . start ( `Removing federated graph ${ pc . bold ( graphData . graph . name ) } …` ) ;
102+ const spinner = demoSpinner ( `Removing federated graph ${ pc . bold ( graphData . graph . name ) } …` ) . start ( ) ;
103103 const deleteResponse = await cleanUpFederatedGraph ( client , graphData ) ;
104104
105105 if ( deleteResponse . error ) {
@@ -139,7 +139,7 @@ async function handleCreateFederatedGraphResponse(
139139 const routingUrl = new URL ( 'graphql' , 'http://localhost' ) ;
140140 routingUrl . port = String ( config . demoRouterPort ) ;
141141
142- const federatedGraphSpinner = ora ( ) . start ( ) ;
142+ const federatedGraphSpinner = demoSpinner ( ) . start ( ) ;
143143 const createGraphResponse = await createFederatedGraph ( client , {
144144 name : config . demoGraphName ,
145145 namespace : config . demoNamespace ,
@@ -192,11 +192,14 @@ async function handleStep2(
192192 const graph = graphData ?. graph ;
193193 const subgraphs = graphData ?. subgraphs ?? [ ] ;
194194 if ( graph ) {
195- const cleanupFn = async ( ) =>
195+ let deleted = false ;
196+ const cleanupFn = async ( ) => {
196197 await cleanupFederatedGraph ( opts . client , {
197198 graphData : { graph, subgraphs } ,
198199 userInfo,
199200 } ) ;
201+ deleted = true ;
202+ } ;
200203 await waitForKeyPress (
201204 {
202205 Enter : ( ) => undefined ,
@@ -205,6 +208,10 @@ async function handleStep2(
205208 } ,
206209 'Hit [ENTER] to continue or [d] to delete the federated graph and its subgraphs to start over. CTRL+C to quit.' ,
207210 ) ;
211+ if ( deleted ) {
212+ console . log ( pc . yellow ( '\nPlease restart the demo command to continue.\n' ) ) ;
213+ process . exit ( 0 ) ;
214+ }
208215 return { routingUrl : graph . routingURL } ;
209216 }
210217
@@ -272,7 +279,7 @@ async function handleStep3(
272279 return ;
273280 }
274281
275- const spinner = ora ( ) . start ( 'Generating router token…' ) ;
282+ const spinner = demoSpinner ( 'Generating router token…' ) . start ( ) ;
276283 const createResult = await createRouterToken ( tokenParams ) ;
277284
278285 if ( createResult . error ) {
@@ -282,14 +289,15 @@ async function handleStep3(
282289 }
283290
284291 spinner . succeed ( 'Router token generated.' ) ;
292+ console . log ( ` ${ pc . bold ( createResult . token ) } ` ) ;
285293
286294 const sampleQuery = JSON . stringify ( {
287295 query : `query GetProductWithReviews($id: ID!) { product(id: $id) { id title price { currency amount } reviews { id author rating contents } } }` ,
288296 variables : { id : 'product-1' } ,
289297 } ) ;
290298
291299 async function fireSampleQuery ( ) {
292- const querySpinner = ora ( 'Sending sample query…' ) . start ( ) ;
300+ const querySpinner = demoSpinner ( 'Sending sample query…' ) . start ( ) ;
293301 try {
294302 const res = await fetch ( `${ routerBaseUrl } /graphql` , {
295303 method : 'POST' ,
@@ -363,7 +371,7 @@ async function handleStep1(opts: BaseCommandOptions, userInfo: UserInfo) {
363371}
364372
365373async function getUserInfo ( client : BaseCommandOptions [ 'client' ] ) {
366- const spinner = ora ( 'Retrieving information about you…' ) . start ( ) ;
374+ const spinner = demoSpinner ( 'Retrieving information about you…' ) . start ( ) ;
367375 const { userInfo, error } = await fetchUserInfo ( client ) ;
368376
369377 if ( error ) {
@@ -381,9 +389,6 @@ async function getUserInfo(client: BaseCommandOptions['client']) {
381389export default function ( opts : BaseCommandOptions ) {
382390 return async function handleCommand ( ) {
383391 const controller = new AbortController ( ) ;
384- const cleanup = ( ) => controller . abort ( ) ;
385- process . on ( 'SIGINT' , cleanup ) ;
386- process . on ( 'SIGTERM' , cleanup ) ;
387392
388393 try {
389394 clearScreen ( ) ;
@@ -425,8 +430,7 @@ export default function (opts: BaseCommandOptions) {
425430 const routerBaseUrl = new URL ( step2Result . routingUrl ) . origin ;
426431 await handleStep3 ( opts , { userInfo, routerBaseUrl, signal : controller . signal , logPath } ) ;
427432 } finally {
428- process . off ( 'SIGINT' , cleanup ) ;
429- process . off ( 'SIGTERM' , cleanup ) ;
433+ // no-op
430434 }
431435 } ;
432436}
0 commit comments