File tree Expand file tree Collapse file tree 1 file changed +12
-17
lines changed
Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Original file line number Diff line number Diff line change 44 */
55
66import * as fs from "fs"
7- import * as readline from "readline"
7+ import * as path from "path"
8+ import { fileURLToPath } from "url"
89
9- export async function getMcVersion ( ) {
10- let lines = readline . createInterface ( {
11- input : fs . createReadStream ( "../../gradle.properties" ) ,
12- crlfDelay : Infinity
13- } )
10+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
1411
15- let mcVersion = ""
12+ export async function getMcVersion ( ) {
13+ const filePath = path . resolve ( __dirname , "../../gradle/libs.versions.toml" )
1614
17- for await ( const line of lines ) {
18- if ( line . startsWith ( "minecraft_version" ) ) {
19- mcVersion = line . substring ( line . indexOf ( "=" ) + 1 )
20- break
21- }
15+ if ( ! fs . existsSync ( filePath ) ) {
16+ throw new Error ( `File not found: ${ filePath } ` )
2217 }
2318
24- if ( mcVersion === "" ) {
25- console . log ( "Failed to read minecraft_version" )
26- process . exit ( 1 )
27- }
19+ const content = await fs . promises . readFile ( filePath , "utf-8" )
20+
21+ const match = content . match ( / ^ \s * m i n e c r a f t \s * = \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] \s * $ / m )
22+ if ( match ) return match [ 1 ] . trim ( )
2823
29- return mcVersion
24+ throw new Error ( `Failed to find minecraft version in ${ filePath } ` )
3025}
You can’t perform that action at this time.
0 commit comments