1
1
#!/usr/bin/env node
2
2
3
- const fs = require ( "fs" ) ;
4
- const path = require ( " path" ) ;
3
+ const fs = require ( 'fs' ) ;
4
+ const path = require ( ' path' ) ;
5
5
6
6
let all = { } ;
7
7
let tfa = { } ;
8
8
let regions = { } ;
9
9
10
10
// Read all JSON files from the 'entries' directory
11
- fs . readdirSync ( " entries" ) . forEach ( ( dir ) => {
12
- fs . readdirSync ( path . join ( " entries" , dir ) ) . forEach ( ( file ) => {
13
- if ( file . endsWith ( " .json" ) ) {
11
+ fs . readdirSync ( ' entries' ) . forEach ( ( dir ) => {
12
+ fs . readdirSync ( path . join ( ' entries' , dir ) ) . forEach ( ( file ) => {
13
+ if ( file . endsWith ( ' .json' ) ) {
14
14
let data = JSON . parse (
15
- fs . readFileSync ( path . join ( " entries" , dir , file ) , " utf8" ) ,
15
+ fs . readFileSync ( path . join ( ' entries' , dir , file ) , ' utf8' ) ,
16
16
) ;
17
17
let key = Object . keys ( data ) [ 0 ] ;
18
18
all [ key ] = data [ key ] ;
@@ -21,72 +21,70 @@ fs.readdirSync("entries").forEach((dir) => {
21
21
} ) ;
22
22
23
23
// Process all entries
24
- Object . keys ( all )
25
- . sort ( )
26
- . forEach ( ( entryName ) => {
27
- let entry = all [ entryName ] ;
28
-
29
- // Process tfa methods
30
- if ( "tfa" in entry ) {
31
- entry [ "tfa" ] . forEach ( ( method ) => {
32
- if ( ! tfa [ method ] ) tfa [ method ] = { } ;
33
-
34
- tfa [ method ] [ entryName ] = entry ;
35
- } ) ;
36
- }
37
-
38
- // Process regions
39
- if ( "regions" in entry ) {
40
- entry [ "regions" ] . forEach ( ( region ) => {
41
- if ( region [ 0 ] !== "-" ) {
42
- if ( ! regions [ region ] ) regions [ region ] = { count : 0 } ;
43
-
44
- regions [ region ] [ "count" ] += 1 ;
45
- }
46
- } ) ;
47
- }
48
-
49
- // Rename 'categories' to 'keywords'
50
- if ( "categories" in entry ) {
51
- entry [ "keywords" ] = entry [ "categories" ] ;
52
- delete entry [ "categories" ] ;
53
- }
54
- } ) ;
24
+ Object . keys ( all ) . sort ( ) . forEach ( ( entryName ) => {
25
+ let entry = all [ entryName ] ;
26
+
27
+ // Process tfa methods
28
+ if ( 'tfa' in entry ) {
29
+ entry [ 'tfa' ] . forEach ( ( method ) => {
30
+ if ( ! tfa [ method ] ) tfa [ method ] = { } ;
31
+
32
+ tfa [ method ] [ entryName ] = entry ;
33
+ } ) ;
34
+ }
35
+
36
+ // Process regions
37
+ if ( 'regions' in entry ) {
38
+ entry [ 'regions' ] . forEach ( ( region ) => {
39
+ if ( region [ 0 ] !== '-' ) {
40
+ if ( ! regions [ region ] ) regions [ region ] = { count : 0 } ;
41
+
42
+ regions [ region ] [ 'count' ] += 1 ;
43
+ }
44
+ } ) ;
45
+ }
46
+
47
+ // Rename 'categories' to 'keywords'
48
+ if ( 'categories' in entry ) {
49
+ entry [ 'keywords' ] = entry [ 'categories' ] ;
50
+ delete entry [ 'categories' ] ;
51
+ }
52
+ } ) ;
55
53
56
54
// Write the all.json and tfa files
57
- const outputDir = " api/v3" ;
58
- if ( ! fs . existsSync ( outputDir ) ) fs . mkdirSync ( outputDir , { recursive : true } ) ;
55
+ const outputDir = ' api/v3' ;
56
+ if ( ! fs . existsSync ( outputDir ) ) fs . mkdirSync ( outputDir , { recursive : true } ) ;
59
57
60
58
const writeJsonFile = ( filename , data ) =>
61
59
fs . writeFileSync (
62
60
path . join ( outputDir , filename ) ,
63
- JSON . stringify ( data , null , 2 ) ,
61
+ JSON . stringify ( data ) ,
64
62
) ;
65
63
66
- writeJsonFile ( " all.json" , { all } ) ;
64
+ writeJsonFile ( ' all.json' , all ) ;
67
65
68
66
Object . keys ( tfa ) . forEach ( ( method ) =>
69
67
writeJsonFile ( `${ method } .json` , tfa [ method ] ) ,
70
68
) ;
71
69
72
70
// Add the 'int' region
73
- regions [ " int" ] = { count : Object . keys ( all ) . length , selection : true } ;
71
+ regions [ ' int' ] = { count : Object . keys ( all ) . length , selection : true } ;
74
72
75
73
// Write regions.json
76
- const sortedRegions = Object . entries ( regions )
77
- . sort ( ( [ , a ] , [ , b ] ) => b . count - a . count )
78
- . reduce ( ( acc , [ k , v ] ) => {
74
+ const sortedRegions = Object . entries ( regions ) .
75
+ sort ( ( [ , a ] , [ , b ] ) => b . count - a . count ) .
76
+ reduce ( ( acc , [ k , v ] ) => {
79
77
acc [ k ] = v ;
80
78
return acc ;
81
79
} , { } ) ;
82
- writeJsonFile ( " regions.json" , sortedRegions ) ;
80
+ writeJsonFile ( ' regions.json' , sortedRegions ) ;
83
81
84
82
// Write tfa.json
85
- const tfaEntries = Object . entries ( all )
86
- . filter ( ( [ , entry ] ) => entry . tfa )
87
- . sort ( ( [ a ] , [ b ] ) => a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) ) )
88
- . reduce ( ( acc , [ k , v ] ) => {
89
- acc [ k ] = v ;
83
+ const tfaEntries = Object . keys ( all ) .
84
+ filter ( ( key ) => all [ key ] . tfa ) .
85
+ sort ( ( a , b ) => a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) ) ) .
86
+ reduce ( ( acc , key ) => {
87
+ acc [ key ] = all [ key ] ;
90
88
return acc ;
91
89
} , { } ) ;
92
- writeJsonFile ( " tfa.json" , tfaEntries ) ;
90
+ writeJsonFile ( ' tfa.json' , tfaEntries ) ;
0 commit comments