Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
.vscode-test
package-lock.json
images/logo.psd
/src/defs/defs.ts.bak
/generator/api.js
70 changes: 70 additions & 0 deletions generator/defGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// defs.ts generator
// Data pulled from https://docs.raid-gaming.net source code
// Ignore this if you're not an internal developer

const fs = require('fs')
const api = require('./api').categories.cod4

const escapeString = (str) => {
return str.replace(/\\/g, '\\\\')
}

console.log('Collecting metadata...')

let functionNames = [];
let functions = {};

// Loop over every namespace
for (let namespace in api.namespaces) {
// Loop over every method/function
for (let method in api.namespaces[namespace].methods) {
functionNames.push(method)
functions[method] = api.namespaces[namespace].methods[method]
}
}

let template = `/* tslint:disable:max-line-length */

export class DefFunction {
name: string;
decl: string;
callon: string;
desc: string;
reqArgs: string[];
optArgs: string[];
example: string;

constructor () {
this.name = "";
this.decl = "";
this.callon = "";
this.desc = "";
this.reqArgs = [];
this.optArgs = [];
this.example = "";
}
}

export let defs: Array<DefFunction> = new Array<DefFunction>();

let funcDef: DefFunction;
`

functionNames = functionNames.sort()
for (let name of functionNames) {
let func = functions[name]
// Omitted unused metadata like "callon", "reqArgs" etc.
template += `
funcDef = new DefFunction;
funcDef.name = \`${escapeString(name)}\`;
funcDef.decl = \`${escapeString(func.usage)}\`;
funcDef.desc = \`${escapeString(func.description)}\`;
funcDef.example = \`${escapeString(func.example)}\`;
defs.push(funcDef);
`
}

fs.writeFile('../src/defs/defs.ts', template, (err) => {
if (err) throw err
console.log('Wrote metadata to /src/defs/defs.ts')
})
Loading