11import * as fs from 'node:fs'
22import * as path from 'node:path'
33import { fileURLToPath } from 'node:url'
4+ import { parseArgs } from 'node:util'
45
56const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
67const rootDir = path . resolve ( __dirname , '../../..' )
78const filePath = path . join ( rootDir , 'node_modules' , 'xvfb-maybe' , 'src' , 'xvfb-maybe.js' )
89
9- const width = 1920
10- const height = 1920
10+ const args = process . argv . slice ( 2 )
11+ const optionsDef = {
12+ width : {
13+ type : 'string' ,
14+ short : 'w' ,
15+ } ,
16+ height : {
17+ type : 'string' ,
18+ short : 'h' ,
19+ } ,
20+ } as const
21+
22+ const { values : options } = parseArgs ( { args, options : optionsDef } )
23+
24+ console . log ( 'Adjust screen resolution' )
25+ console . log ( ` Width : ${ options . width } ` )
26+ console . log ( ` Height: ${ options . height } ` )
1127
1228const insertBefore = "const dblDashPos = args.indexOf('--'),"
13- const codeToInsert = ` args.unshift('--server-args="' -screen 0 ${ width } x${ height } x24'" ', '--');`
29+ const codeToInsert = ` args.unshift('--server-args=-screen 0 ${ options . width } x${ options . height } x24', '--');`
1430
1531const sourceCode = fs . readFileSync ( filePath , 'utf-8' )
1632
@@ -23,10 +39,10 @@ const lines = sourceCode.split('\n')
2339const index = lines . findIndex ( ( line ) => line . includes ( insertBefore ) )
2440
2541if ( index !== - 1 ) {
26- lines . splice ( index , 0 , codeToInsert ) // 挿入
42+ lines . splice ( index , 0 , codeToInsert )
2743 const newCode = lines . join ( '\n' )
2844 fs . writeFileSync ( filePath , newCode , 'utf-8' )
29- console . log ( '✅ xvfb-maybe is patched successfully' )
45+ console . log ( '\n ✅ xvfb-maybe is patched successfully' )
3046} else {
31- console . log ( '💥 could not find the target line.' )
47+ console . log ( '\n 💥 could not find the target line.' )
3248}
0 commit comments