UNPKG

@atproto/api

Version:

Client library for atproto and Bluesky

69 lines (60 loc) 1.59 kB
import * as url from 'url' import { readFileSync, writeFileSync } from 'fs' import { join } from 'path' import * as prettier from 'prettier' const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) const labelsDef = JSON.parse( readFileSync( join(__dirname, '..', '..', 'definitions', 'labels.json'), 'utf8', ), ) const labelsEn = JSON.parse( readFileSync( join(__dirname, '..', '..', 'definitions', 'locale', 'en', 'labels.json'), 'utf8', ), ) writeFileSync( join(__dirname, '..', '..', 'src', 'moderation', 'const', 'labels.ts'), await gen(), 'utf8', ) async function gen() { return prettier.format( `/** this doc is generated by ./scripts/code/labels.mjs **/ import {LabelDefinitionMap} from '../types' export const LABELS: LabelDefinitionMap = ${JSON.stringify( genDefMap(), null, 2, )} `, { semi: false, parser: 'babel', singleQuote: true }, ) } function genDefMap() { const labels = {} for (const group of labelsDef) { for (const label of group.labels) { labels[label.id] = { ...label, groupId: group.id, configurable: group.configurable, strings: { settings: getLabelStrings(label.id, 'settings'), account: getLabelStrings(label.id, 'account'), content: getLabelStrings(label.id, 'content'), }, } } } return labels } function getLabelStrings(id, type) { if (labelsEn[id] && labelsEn[id][type]) { return { en: labelsEn[id][type] } } throw new Error('Label strings not found for ' + id) } export {}