@@ -2,6 +2,7 @@ import { copyFileSync, existsSync, mkdirSync, readdirSync } from "fs"
2
2
import { join } from "path"
3
3
4
4
import i18Config from "../../../../i18n.config.json"
5
+ import { INTL_JSON_DIR , TRANSLATIONS_DIR } from "../../../lib/constants"
5
6
import { DOT_CROWDIN } from "../translations/constants"
6
7
7
8
import { BucketsList , SelectionItem , SummaryItem , TrackerObject } from "./types"
@@ -18,26 +19,26 @@ export const getCrowdinCode = (code: string): string =>
18
19
* to their corresponding destinations in the repo. Function is called
19
20
* again recursively for subdirectories.
20
21
*
21
- * @param _path An absolute path to the directory being scraped.
22
+ * @param path An absolute path to the directory being scraped.
22
23
* @param contentSubpath The subpath deep to the lang-code directory,
23
24
* used to construct destination for markdown content files
24
25
* @param repoLangCode Language code used within the repo
25
26
* @returns void
26
27
*/
27
28
export const scrapeDirectory = (
28
- _path : string ,
29
+ path : string ,
29
30
contentSubpath : string ,
30
31
repoLangCode : string ,
31
32
trackers : TrackerObject
32
33
) : void => {
33
- if ( ! existsSync ( _path ) ) return
34
- const ls : string [ ] = readdirSync ( _path ) . filter (
34
+ if ( ! existsSync ( path ) ) return
35
+ const ls : string [ ] = readdirSync ( path ) . filter (
35
36
( dir : string ) => ! dir . startsWith ( "." )
36
37
)
37
38
ls . forEach ( ( item : string ) => {
38
- const source : string = join ( _path , item )
39
+ const source : string = join ( path , item )
39
40
if ( item . endsWith ( ".json" ) ) {
40
- const jsonDestDirPath : string = join ( "src" , "intl" , repoLangCode )
41
+ const jsonDestDirPath : string = join ( INTL_JSON_DIR , repoLangCode )
41
42
if ( ! existsSync ( jsonDestDirPath ) )
42
43
mkdirSync ( jsonDestDirPath , { recursive : true } )
43
44
const jsonDestinationPath : string = join ( jsonDestDirPath , item )
@@ -50,9 +51,7 @@ export const scrapeDirectory = (
50
51
item . endsWith ( ".xlsx" )
51
52
) {
52
53
const mdDestDirPath : string = join (
53
- "public" ,
54
- "content" ,
55
- "translations" ,
54
+ TRANSLATIONS_DIR ,
56
55
repoLangCode ,
57
56
contentSubpath
58
57
)
@@ -65,7 +64,7 @@ export const scrapeDirectory = (
65
64
} else {
66
65
// If another directory, recursively call `scrapeDirectory`
67
66
scrapeDirectory (
68
- `${ _path } /${ item } ` ,
67
+ `${ path } /${ item } ` ,
69
68
`${ contentSubpath } /${ item } ` ,
70
69
repoLangCode ,
71
70
trackers
@@ -126,14 +125,14 @@ export const processLanguage = (
126
125
error : "" ,
127
126
}
128
127
// Initialize working directory and check for existence
129
- const _path : string = join ( DOT_CROWDIN , crowdinLangCode )
130
- if ( ! existsSync ( _path ) ) {
128
+ const path : string = join ( DOT_CROWDIN , crowdinLangCode )
129
+ if ( ! existsSync ( path ) ) {
131
130
trackers . langs [
132
131
repoLangCode
133
132
] . error = `Path doesn't exist for lang ${ crowdinLangCode } `
134
133
return
135
134
}
136
- const langLs : string [ ] = readdirSync ( _path )
135
+ const langLs : string [ ] = readdirSync ( path )
137
136
// Iterate over each selected bucket, scraping contents with `scrapeDirectory`
138
137
buckets . forEach ( ( bucket ) =>
139
138
processBucket ( bucket , crowdinLangCode , repoLangCode , langLs , trackers )
0 commit comments