Skip to content

Commit cb561fd

Browse files
author
gemini2035
committed
refactor(scripts): try to use .json
1 parent 93414af commit cb561fd

File tree

5 files changed

+2315
-63
lines changed

5 files changed

+2315
-63
lines changed

scripts/shared.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ function transformOperatorName(name: string) {
4747
})
4848
return {
4949
name,
50-
pron: [
51-
fullPinyin.flatMap((el) => el).join(''),
52-
partialPinyin.flatMap((el) => el).join(''),
53-
].join(' '),
5450
alias: uniq([
5551
...pinyinify(cleanedName),
5652
traditional,

scripts/update-operators.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,17 @@ import process from 'process'
33

44
import { getOperators } from './shared'
55

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-
166
async function main() {
177
console.info('Fetching operators...')
188
const { operators, professions } = await getOperators()
199

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+
})
4014

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)
4317
}
4418

4519
main()

0 commit comments

Comments
 (0)