@@ -3,43 +3,17 @@ import process from 'process'
3
3
4
4
import { getOperators } from './shared'
5
5
6
- function withGeneratedHeader ( content : string ) {
7
- return `// Generated by update-operators.ts\n// DO NOT EDIT\n${ content } `
8
- }
9
-
10
- // at runtime, this evaluates faster than plain object
11
- function toRuntimeJSON ( o : any ) {
12
- const str = JSON . stringify ( o ) . replace ( / \\ / g, '\\\\' ) . replace ( / ' / g, "\\'" )
13
- return `JSON.parse('${ str } ')`
14
- }
15
-
16
6
async function main ( ) {
17
7
console . info ( 'Fetching operators...' )
18
8
const { operators, professions } = await getOperators ( )
19
9
20
- const content = withGeneratedHeader (
21
- `
22
- export interface OperatorInfo {
23
- id: string
24
- name: string
25
- pron: string
26
- subProf: string
27
- alias: string
28
- alt_name: string
29
- }
30
-
31
- export interface Profession {
32
- id: string
33
- name: string
34
- sub?: Profession[]
35
- }
36
-
37
- export const OPERATORS: OperatorInfo[] = ${ toRuntimeJSON ( operators ) } ;
38
- export const PROFESSIONS: Profession[] = ${ toRuntimeJSON ( professions ) } ;` ,
39
- )
10
+ const content = JSON . stringify ( {
11
+ OPERATORS : operators ,
12
+ PROFESSIONS : professions ,
13
+ } )
40
14
41
- console . info ( 'Writing to operators.ts ...' )
42
- await writeFile ( 'src/models/generated/operators.ts ' , content )
15
+ console . info ( 'Writing to operators.json ...' )
16
+ await writeFile ( 'src/models/generated/operators.json ' , content )
43
17
}
44
18
45
19
main ( )
0 commit comments