@@ -28,7 +28,7 @@ import { getCurrentDirectoryPath } from './dirname.js';
28
28
29
29
const UI_BUILD_DIR = join ( getCurrentDirectoryPath ( ) , 'ui' ) ;
30
30
31
- type InteractiveUIOptions = {
31
+ type UIOptions = {
32
32
project : Project ;
33
33
releaseType : 'ordinary' | 'backport' ;
34
34
defaultBranch : string ;
@@ -38,24 +38,24 @@ type InteractiveUIOptions = {
38
38
} ;
39
39
40
40
/**
41
- * Starts the interactive UI for the release process.
41
+ * Starts the UI for the release process.
42
42
*
43
- * @param options - The options for the interactive UI.
43
+ * @param options - The options for the UI.
44
44
* @param options.project - The project object.
45
45
* @param options.releaseType - The type of release.
46
46
* @param options.defaultBranch - The default branch name.
47
47
* @param options.port - The port number for the server.
48
48
* @param options.stdout - The stdout stream.
49
49
* @param options.stderr - The stderr stream.
50
50
*/
51
- export async function startInteractiveUI ( {
51
+ export async function startUI ( {
52
52
project,
53
53
releaseType,
54
54
defaultBranch,
55
55
port,
56
56
stdout,
57
57
stderr,
58
- } : InteractiveUIOptions ) : Promise < void > {
58
+ } : UIOptions ) : Promise < void > {
59
59
const { version : newReleaseVersion , firstRun } = await createReleaseBranch ( {
60
60
project,
61
61
releaseType,
@@ -69,6 +69,59 @@ export async function startInteractiveUI({
69
69
) ;
70
70
}
71
71
72
+ const app = createApp ( {
73
+ project,
74
+ defaultBranch,
75
+ stderr,
76
+ version : newReleaseVersion ,
77
+ closeServer : ( ) => {
78
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
79
+ server . close ( ) ;
80
+ stdout . write ( 'Release process completed. Server shutdown.\n' ) ;
81
+ } ,
82
+ } ) ;
83
+
84
+ const server = app . listen ( port , async ( ) => {
85
+ const url = `http://localhost:${ port } ` ;
86
+ stdout . write ( `UI server running at ${ url } \n` ) ;
87
+ } ) ;
88
+
89
+ return new Promise ( ( resolve , reject ) => {
90
+ server . on ( 'error' , ( error ) => {
91
+ stderr . write ( `Failed to start server: ${ error } \n` ) ;
92
+ reject ( error ) ;
93
+ } ) ;
94
+
95
+ server . on ( 'close' , ( ) => {
96
+ resolve ( ) ;
97
+ } ) ;
98
+ } ) ;
99
+ }
100
+
101
+ /**
102
+ * Creates an Express application for the UI server.
103
+ *
104
+ * @param options - The options for creating the app.
105
+ * @param options.project - The project object.
106
+ * @param options.defaultBranch - The default branch name.
107
+ * @param options.stderr - The stderr stream.
108
+ * @param options.version - The release version.
109
+ * @param options.closeServer - The function to close the server.
110
+ * @returns The Express application.
111
+ */
112
+ function createApp ( {
113
+ project,
114
+ defaultBranch,
115
+ stderr,
116
+ version,
117
+ closeServer,
118
+ } : {
119
+ project : Project ;
120
+ defaultBranch : string ;
121
+ stderr : Pick < WriteStream , 'write' > ;
122
+ version : string ;
123
+ closeServer : ( ) => void ;
124
+ } ) : express . Application {
72
125
const app = express ( ) ;
73
126
74
127
app . use ( express . static ( UI_BUILD_DIR ) ) ;
@@ -223,22 +276,20 @@ export async function startInteractiveUI({
223
276
const releasePlan = await planRelease ( {
224
277
project,
225
278
releaseSpecificationPackages,
226
- newReleaseVersion,
279
+ newReleaseVersion : version ,
227
280
} ) ;
228
281
await executeReleasePlan ( project , releasePlan , stderr ) ;
229
282
await fixConstraints ( project . directoryPath ) ;
230
283
await updateYarnLockfile ( project . directoryPath ) ;
231
284
await deduplicateDependencies ( project . directoryPath ) ;
232
285
await commitAllChanges (
233
286
project . directoryPath ,
234
- `Update Release ${ newReleaseVersion } ` ,
287
+ `Update Release ${ version } ` ,
235
288
) ;
236
289
237
290
res . json ( { status : 'success' } ) ;
238
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
239
- server . close ( ( ) => {
240
- stdout . write ( 'Release process completed. Server shutdown.\n' ) ;
241
- } ) ;
291
+
292
+ closeServer ( ) ;
242
293
} catch ( error ) {
243
294
stderr . write ( `Release error: ${ error } \n` ) ;
244
295
res . status ( 400 ) . send ( 'Invalid request' ) ;
@@ -250,14 +301,5 @@ export async function startInteractiveUI({
250
301
res . sendFile ( join ( UI_BUILD_DIR , 'index.html' ) ) ;
251
302
} ) ;
252
303
253
- const server = app . listen ( port , ( ) => {
254
- stdout . write ( `Interactive UI server running at http://localhost:${ port } \n` ) ;
255
- } ) ;
256
-
257
- return new Promise ( ( _ , reject ) => {
258
- server . on ( 'error' , ( error ) => {
259
- stderr . write ( `Failed to start server: ${ error } \n` ) ;
260
- reject ( error ) ;
261
- } ) ;
262
- } ) ;
304
+ return app ;
263
305
}
0 commit comments