1
1
import path from "path" ;
2
2
3
+ import { existsSync , mkdirSync } from "fs" ;
4
+ import { writeFile } from "fs/promises" ;
3
5
import fetch from "node-fetch" ;
4
6
import { Octokit } from "octokit" ;
5
- import { writeFile } from "fs/promises" ;
6
7
import { SERVER_VERSION_FILE , SERVER_VERSION_TAG } from "./connection/SCVersion" ;
7
8
8
9
async function work ( ) {
@@ -26,12 +27,15 @@ async function work() {
26
27
console . log ( `Asset found: ${ newAsset . name } ` ) ;
27
28
28
29
const url = newAsset . browser_download_url ;
30
+ const distDirectory = path . join ( `.` , `dist` ) ;
31
+ if ( ! existsSync ( distDirectory ) ) {
32
+ mkdirSync ( distDirectory ) ;
33
+ }
29
34
30
- const dist = path . join ( `.` , `dist` , SERVER_VERSION_FILE ) ;
31
-
32
- await downloadFile ( url , dist ) ;
35
+ const serverFile = path . join ( distDirectory , SERVER_VERSION_FILE ) ;
36
+ await downloadFile ( url , serverFile ) ;
33
37
34
- console . log ( `Asset downloaded. ` ) ;
38
+ console . log ( `Asset downloaded: ${ serverFile } ` ) ;
35
39
36
40
} else {
37
41
console . log ( `Release found but no asset found.` ) ;
@@ -45,8 +49,8 @@ async function work() {
45
49
46
50
function downloadFile ( url , outputPath ) {
47
51
return fetch ( url )
48
- . then ( x => x . arrayBuffer ( ) )
49
- . then ( x => writeFile ( outputPath , Buffer . from ( x ) ) ) ;
52
+ . then ( x => x . arrayBuffer ( ) )
53
+ . then ( x => writeFile ( outputPath , Buffer . from ( x ) ) ) ;
50
54
}
51
55
52
56
work ( ) ;
0 commit comments