@@ -4,49 +4,52 @@ import fs from "fs";
4
4
import path from "path" ;
5
5
dotenv . config ( ) ;
6
6
7
- if ( process . env . GITHUB_OWNER === undefined || process . env . GITHUB_REPO === undefined ) {
8
- throw Error ( "Please specify GITHUB_OWNER, GITHUB_REPO to pull EN XML from!" ) ;
7
+ if (
8
+ process . env . GITHUB_OWNER === undefined ||
9
+ process . env . GITHUB_REPO === undefined
10
+ ) {
11
+ throw Error ( "Please specify GITHUB_OWNER, GITHUB_REPO to pull EN XML from!" ) ;
9
12
}
10
13
11
14
// initialize GitHub API
12
15
const octokit = new Octokit ( ) ;
13
16
14
17
async function getSource ( filePath : string ) : Promise < string > {
15
- let toTranslate ;
16
-
17
- try {
18
- const result = await octokit . request (
19
- "GET /repos/{owner}/{repo}/contents/{path}" ,
20
- {
21
- owner : process . env . GITHUB_OWNER ! ,
22
- repo : process . env . GITHUB_REPO ! ,
23
- path : filePath ,
24
- headers : {
25
- accept : "application/vnd.github.raw+json" ,
26
- } ,
27
- }
28
- ) ;
29
-
30
- toTranslate = result . data ;
31
- const output_dir = path . join ( import . meta. dirname , "../../ori" ) ;
32
-
33
- // Ensure directory exists
34
- const dir = path . dirname ( path . join ( output_dir , filePath ) ) ;
35
- fs . mkdirSync ( dir , { recursive : true } ) ;
36
-
37
- const fullPath = path . resolve ( path . join ( output_dir , filePath ) ) ;
38
- fs . writeFileSync ( fullPath , toTranslate ) ;
39
-
40
- console . log (
41
- `Successfully retrieved ${ filePath } from GitHub, retrieval status: ${ result . status } `
42
- ) ;
43
- } catch ( error ) {
44
- console . log (
45
- `Error retrieving ${ filePath } from GitHub.\n Status: ${ error . status } .\n Rate limit remaining: ${ error . response . headers [ "x-ratelimit-remaining" ] } .\n Message: ${ error . response . data . message } `
46
- ) ;
47
- }
48
-
49
- return toTranslate as string ;
18
+ let toTranslate ;
19
+
20
+ try {
21
+ const result = await octokit . request (
22
+ "GET /repos/{owner}/{repo}/contents/{path}" ,
23
+ {
24
+ owner : process . env . GITHUB_OWNER ! ,
25
+ repo : process . env . GITHUB_REPO ! ,
26
+ path : filePath ,
27
+ headers : {
28
+ accept : "application/vnd.github.raw+json"
29
+ }
30
+ }
31
+ ) ;
32
+
33
+ toTranslate = result . data ;
34
+ const output_dir = path . join ( import . meta. dirname , "../../ori" ) ;
35
+
36
+ // Ensure directory exists
37
+ const dir = path . dirname ( path . join ( output_dir , filePath ) ) ;
38
+ fs . mkdirSync ( dir , { recursive : true } ) ;
39
+
40
+ const fullPath = path . resolve ( path . join ( output_dir , filePath ) ) ;
41
+ fs . writeFileSync ( fullPath , toTranslate ) ;
42
+
43
+ console . log (
44
+ `Successfully retrieved ${ filePath } from GitHub, retrieval status: ${ result . status } `
45
+ ) ;
46
+ } catch ( error ) {
47
+ console . log (
48
+ `Error retrieving ${ filePath } from GitHub.\n Status: ${ error . status } .\n Rate limit remaining: ${ error . response . headers [ "x-ratelimit-remaining" ] } .\n Message: ${ error . response . data . message } `
49
+ ) ;
50
+ }
51
+
52
+ return toTranslate as string ;
50
53
}
51
54
52
55
async function commitTranslated ( ) { }
0 commit comments