You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

68 lines
2.1 KiB

import { writeFile } from 'fs/promises'
import { getParsedScriptObjects } from './helpers/generate-script-object'
import { getParsedCallbacks } from './helpers/get-parsed-callbacks'
import { getParsedConstants } from './helpers/get-parsed-constants'
import { getParsedEnums } from './helpers/get-parsed-enums'
import { getParsedEventData } from './helpers/get-parsed-event-data'
import { getParsedStructs } from './helpers/get-parsed-structs'
import { getParsedSystems } from './helpers/get-parsed-systems'
import { Doc } from './shared/types/doc-types'
const data = require('../lua-docs/docs/docs.json') as Doc[]
const writeDeclaration = (declaration: string, name: string) => {
try {
const decoratedDeclaration = `
/* eslint-disable @typescript-eslint/no-duplicate-enum-values */
/* eslint-disable @typescript-eslint/ban-types */
/** @noSelfInFile **/
declare global {
${declaration}
}
export {}
`
return writeFile(`./src/types/Wow/${name}.d.ts`, decoratedDeclaration)
} catch (error) {
throw error as Error
}
}
const main = async () => {
try {
const enums = getParsedEnums(data)
const structs = getParsedStructs(data)
const constants = getParsedConstants(data)
const callbacks = getParsedCallbacks(data)
const eventData = getParsedEventData(data)
const systemData = getParsedSystems(data)
const scriptObjects = getParsedScriptObjects(data)
console.log('Parsed docs, writing declaration.')
try {
await Promise.all([
writeDeclaration(structs.join('\n'), 'structs'),
writeDeclaration(scriptObjects.join('\n'), 'scripts'),
writeDeclaration(callbacks.join('\n'), 'callbacks'),
writeDeclaration(enums.join('\n'), 'enums'),
writeDeclaration(constants.join('\n'), 'constants'),
writeDeclaration(eventData, 'events'),
writeDeclaration(systemData.join('\n'), 'systems')
])
} catch (error) {
console.log(`Encountered error while writting declarations.`)
console.error(error)
}
console.log('Done!')
} catch (error) {
console.log('SCRIPT ENDED IN ERROR')
console.log(error)
}
}
main()