@@ -13,14 +13,18 @@ const gExistingShortcuts = new WeakSet<Options>()
1313
1414interface Options {
1515 api : RsbuildPluginAPI
16- entries : string [ ]
16+ entries : {
17+ all : string [ ]
18+ lynx : string [ ]
19+ web : string [ ]
20+ }
1721 schema : CustomizedSchemaFn
1822 port : number
1923 customShortcuts ?: Record <
2024 string ,
2125 { value : string , label : string , hint ?: string , action ?( ) : Promise < void > }
2226 >
23- onPrint ?: ( ( url : string ) => Promise < void > ) | undefined
27+ onPrint ?: ( ( lynx ?: string , web ? : string ) => Promise < void > ) | undefined
2428}
2529
2630export async function registerConsoleShortcuts (
@@ -32,22 +36,29 @@ export async function registerConsoleShortcuts(
3236 import ( './showQRCode.js' ) ,
3337 ] )
3438
35- const currentEntry = options . entries [ 0 ] !
39+ // keep the default entry to be lynx explorer entry if exists
40+ const currentEntry = ( options . entries . lynx [ 0 ] ?? options . entries . web [ 0 ] ) !
3641 const devUrls = generateDevUrls (
3742 options . api ,
3843 currentEntry ,
3944 options . schema ,
4045 options . port ,
4146 )
4247
43- const value : string | symbol = Object . values ( devUrls ) [ 0 ] !
44- await options . onPrint ?.( value )
45- showQRCode ( value )
48+ const hasLynxEntry = options . entries . lynx . includes ( currentEntry )
49+ const hasWebEntry = options . entries . web . includes ( currentEntry )
50+ const lynxUrl = hasLynxEntry ? Object . values ( devUrls . lynx ) [ 0 ] : undefined
51+ const webUrl = hasWebEntry ? devUrls . web : undefined
52+ await options . onPrint ?.(
53+ lynxUrl ,
54+ webUrl ,
55+ )
56+ showQRCode ( lynxUrl , webUrl )
4657
4758 gExistingShortcuts . add ( options )
4859
4960 // We should not `await` on this since it would block the NodeJS main thread.
50- void loop ( options , value , devUrls )
61+ void loop ( options , { lynx : lynxUrl , web : webUrl } , devUrls , currentEntry )
5162
5263 function off ( ) {
5364 gExistingShortcuts . delete ( options )
@@ -57,8 +68,9 @@ export async function registerConsoleShortcuts(
5768
5869async function loop (
5970 options : Options ,
60- value : string | symbol ,
61- devUrls : Record < string , string > ,
71+ value : { lynx : string | symbol | undefined , web : string | undefined } ,
72+ devUrls : { lynx : Record < string , string | symbol > , web : string } ,
73+ currentEntry : string ,
6274) {
6375 const [
6476 { autocomplete, select, selectKey, isCancel, cancel } ,
@@ -70,10 +82,11 @@ async function loop(
7082
7183 const selectFn = ( length : number ) => length > 5 ? autocomplete : select
7284
73- let currentEntry = options . entries [ 0 ] !
74- let currentSchema = Object . keys ( devUrls ) [ 0 ] !
85+ let currentSchema = Object . keys ( devUrls . lynx ) [ 0 ] !
7586
76- while ( ! isCancel ( value ) ) {
87+ while (
88+ ! ( value . lynx && isCancel ( value . lynx ) || value . web && isCancel ( value . web ) )
89+ ) {
7790 const name = await selectKey ( {
7891 message : 'Usage' ,
7992 options : [
@@ -95,18 +108,21 @@ async function loop(
95108 break
96109 }
97110 if ( name === 'r' ) {
98- const selection = await selectFn ( options . entries . length ) ( {
111+ const selection = await selectFn ( options . entries . all . length ) ( {
99112 message : 'Select entry' ,
100- options : options . entries . map ( entry => ( {
101- value : entry ,
102- label : entry ,
103- hint : generateDevUrls (
113+ options : options . entries . all . map ( entry => {
114+ const newDevUrls = generateDevUrls (
104115 options . api ,
105116 entry ,
106117 options . schema ,
107118 options . port ,
108- ) [ currentSchema ] ! ,
109- } ) ) ,
119+ )
120+ return {
121+ value : entry ,
122+ label : entry ,
123+ hint : ( newDevUrls . lynx [ currentSchema ] ?? newDevUrls . web ) ,
124+ }
125+ } ) ,
110126 initialValue : currentEntry ,
111127 } )
112128 if ( isCancel ( selection ) ) {
@@ -121,9 +137,9 @@ async function loop(
121137 options . schema ,
122138 options . port ,
123139 )
124- const selection = await selectFn ( Object . keys ( devUrls ) . length ) ( {
140+ const selection = await selectFn ( Object . keys ( devUrls . lynx ) . length ) ( {
125141 message : 'Select schema' ,
126- options : Object . entries ( devUrls ) . map ( ( [ name , url ] ) => ( {
142+ options : Object . entries ( devUrls . lynx ) . map ( ( [ name , url ] ) => ( {
127143 value : name ,
128144 label : name ,
129145 hint : url ,
@@ -138,8 +154,8 @@ async function loop(
138154 } else if ( options . customShortcuts ?. [ name ] ) {
139155 await options . customShortcuts [ name ] . action ?.( )
140156 }
141- await options . onPrint ?.( value )
142- showQRCode ( value )
157+ await options . onPrint ?.( value . lynx as string | undefined , value . web )
158+ showQRCode ( value . lynx as string , value . web )
143159 }
144160
145161 // If the `options` is not deleted from `gExistingShortcuts`, means that this is an explicitly
@@ -151,13 +167,17 @@ async function loop(
151167
152168 return
153169
154- function getCurrentUrl ( ) : string {
155- return generateDevUrls (
170+ function getCurrentUrl ( ) : {
171+ lynx : string | undefined
172+ web : string | undefined
173+ } {
174+ const { lynx, web } = generateDevUrls (
156175 options . api ,
157176 currentEntry ,
158177 options . schema ,
159178 options . port ,
160- ) [ currentSchema ] !
179+ )
180+ return { lynx : lynx [ currentSchema ] , web }
161181 }
162182
163183 function exit ( code ?: number ) {
0 commit comments