|
| 1 | +// defs.ts generator |
| 2 | +// Data pulled from https://docs.raid-gaming.net source code |
| 3 | +// Ignore this if you're not an internal developer |
| 4 | + |
| 5 | +const fs = require('fs') |
| 6 | +const api = require('./api').categories.cod4 |
| 7 | + |
| 8 | +const escapeString = (str) => { |
| 9 | + return str.replace(/\\/g, '\\\\') |
| 10 | +} |
| 11 | + |
| 12 | +console.log('Collecting metadata...') |
| 13 | + |
| 14 | +let functionNames = []; |
| 15 | +let functions = {}; |
| 16 | + |
| 17 | +// Loop over every namespace |
| 18 | +for (let namespace in api.namespaces) { |
| 19 | + // Loop over every method/function |
| 20 | + for (let method in api.namespaces[namespace].methods) { |
| 21 | + functionNames.push(method) |
| 22 | + functions[method] = api.namespaces[namespace].methods[method] |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +let template = `/* tslint:disable:max-line-length */ |
| 27 | +
|
| 28 | +export class DefFunction { |
| 29 | + name: string; |
| 30 | + decl: string; |
| 31 | + callon: string; |
| 32 | + desc: string; |
| 33 | + reqArgs: string[]; |
| 34 | + optArgs: string[]; |
| 35 | + example: string; |
| 36 | +
|
| 37 | + constructor () { |
| 38 | + this.name = ""; |
| 39 | + this.decl = ""; |
| 40 | + this.callon = ""; |
| 41 | + this.desc = ""; |
| 42 | + this.reqArgs = []; |
| 43 | + this.optArgs = []; |
| 44 | + this.example = ""; |
| 45 | + } |
| 46 | +} |
| 47 | +
|
| 48 | +export let defs: Array<DefFunction> = new Array<DefFunction>(); |
| 49 | +
|
| 50 | +let funcDef: DefFunction; |
| 51 | +` |
| 52 | + |
| 53 | +functionNames = functionNames.sort() |
| 54 | +for (let name of functionNames) { |
| 55 | + let func = functions[name] |
| 56 | + // Omitted unused metadata like "callon", "reqArgs" etc. |
| 57 | + template += ` |
| 58 | +funcDef = new DefFunction; |
| 59 | +funcDef.name = \`${escapeString(name)}\`; |
| 60 | +funcDef.decl = \`${escapeString(func.usage)}\`; |
| 61 | +funcDef.desc = \`${escapeString(func.description)}\`; |
| 62 | +funcDef.example = \`${escapeString(func.example)}\`; |
| 63 | +defs.push(funcDef); |
| 64 | +` |
| 65 | +} |
| 66 | + |
| 67 | +fs.writeFile('../src/defs/defs.ts', template, (err) => { |
| 68 | + if (err) throw err |
| 69 | + console.log('Wrote metadata to /src/defs/defs.ts') |
| 70 | +}) |
0 commit comments