2022-11-10 11:07:31 +01:00
|
|
|
|
#!/usr/bin/env node
|
|
|
|
|
const hap = require('hap-nodejs')
|
|
|
|
|
const { format } = require('prettier')
|
|
|
|
|
const prettierConfig = require('../prettier.config')
|
|
|
|
|
const { writeFileSync } = require('fs')
|
|
|
|
|
const { join, basename } = require('path')
|
|
|
|
|
|
|
|
|
|
const uuidToServiceMap = {}
|
|
|
|
|
const serviceToUuidMap = {}
|
2022-11-10 13:06:16 +01:00
|
|
|
|
const file = join(__dirname, '../src/generated/services.ts')
|
|
|
|
|
|
|
|
|
|
console.log(`Starting code generation for ${file}`)
|
2022-11-10 11:07:31 +01:00
|
|
|
|
|
|
|
|
|
for (const [name, service] of Object.entries(hap.Service)) {
|
|
|
|
|
if (typeof service !== 'function' || typeof service.UUID !== 'string') {
|
|
|
|
|
console.log(`Skipping ${typeof service} ${name}`)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uuidToServiceMap[service.UUID] = name
|
|
|
|
|
serviceToUuidMap[name] = service.UUID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const code = format(
|
|
|
|
|
`
|
|
|
|
|
// Auto-generated by "${join(basename(__dirname), basename(__filename))}", don’t manually edit
|
2022-11-24 22:12:40 +01:00
|
|
|
|
export const Uuids = ${JSON.stringify(uuidToServiceMap)} as const
|
2022-11-10 11:07:31 +01:00
|
|
|
|
|
2022-11-24 22:12:40 +01:00
|
|
|
|
export const Services = ${JSON.stringify(serviceToUuidMap)} as const
|
2022-11-10 11:07:31 +01:00
|
|
|
|
`,
|
|
|
|
|
{ filepath: 'codegen.ts', ...prettierConfig },
|
|
|
|
|
)
|
|
|
|
|
|
2022-11-10 13:06:16 +01:00
|
|
|
|
writeFileSync(file, code)
|
|
|
|
|
|
|
|
|
|
console.log(`Finished code generation for ${file}`)
|