@@ -35,32 +35,9 @@ export const parseAll = (folderPath: string): { name: string; path: string }[] =
35
35
36
36
const data = [ ]
37
37
for ( const folder of folders ) {
38
- const lang = { }
38
+ const langFolderPath = folderPath + path . sep + folder
39
39
40
- fs . readdirSync ( folderPath + path . sep + folder )
41
- . sort ( )
42
- . forEach ( ( langFolderItem ) => {
43
- const langFolderPath = folderPath + path . sep + folder
44
- const langFolderItemPath = langFolderPath + path . sep + langFolderItem
45
-
46
- if ( fs . statSync ( langFolderItemPath ) . isDirectory ( ) ) {
47
- // Lang sub folder
48
- const subFolderFileKey = langFolderItem . replace ( / \. \w + $ / , '' )
49
- lang [ subFolderFileKey ] = { }
50
-
51
- fs . readdirSync ( langFolderItemPath )
52
- . filter ( ( file ) => ! fs . statSync ( langFolderItemPath + path . sep + file ) . isDirectory ( ) )
53
- . sort ( )
54
- . forEach ( ( file ) => {
55
- lang [ subFolderFileKey ] [ file . replace ( / \. \w + $ / , '' ) ] = parse (
56
- fs . readFileSync ( langFolderItemPath + path . sep + file ) . toString ( )
57
- )
58
- } )
59
- } else {
60
- // Lang file
61
- lang [ langFolderItem . replace ( / \. \w + $ / , '' ) ] = parse ( fs . readFileSync ( langFolderItemPath ) . toString ( ) )
62
- }
63
- } )
40
+ const lang = readThroughDir ( langFolderPath )
64
41
65
42
data . push ( {
66
43
folder,
@@ -147,3 +124,22 @@ export const reset = (folderPath) => {
147
124
fs . unlinkSync ( folderPath + file )
148
125
} )
149
126
}
127
+
128
+ export const readThroughDir = ( dir ) => {
129
+ const data = { }
130
+
131
+ fs . readdirSync ( dir )
132
+ . forEach ( ( file ) => {
133
+ const absoluteFile = dir + path . sep + file
134
+
135
+ if ( fs . statSync ( absoluteFile ) . isDirectory ( ) ) {
136
+ const subFolderFileKey = file . replace ( / \. \w + $ / , '' )
137
+
138
+ data [ subFolderFileKey ] = readThroughDir ( absoluteFile )
139
+ } else {
140
+ data [ file . replace ( / \. \w + $ / , '' ) ] = parse ( fs . readFileSync ( absoluteFile ) . toString ( ) )
141
+ }
142
+ } )
143
+
144
+ return data
145
+ }
0 commit comments