From e75ca88e61f65797944db25d1c166478b8fbdbe8 Mon Sep 17 00:00:00 2001 From: Dylan Malandain Date: Sat, 25 May 2019 00:40:53 +0200 Subject: [PATCH] Finish TypeDocs + First release --- main.ts | 48 +++++++++++++++++-------- src/content-generate.ts | 78 +++++++++++++++++++++++++++++++++-------- src/files-builder.ts | 16 ++++++--- 3 files changed, 108 insertions(+), 34 deletions(-) diff --git a/main.ts b/main.ts index 497269d..a1c74bc 100644 --- a/main.ts +++ b/main.ts @@ -2,43 +2,61 @@ import * as request from 'request'; import {FilesBuilder} from "./src/files-builder"; import {ContentGenerate} from "./src/content-generate"; +/** + * The [[Main]] class that groups together all the logical execution processes of the system. + */ export class Main { + /** + * Startup logicNom de la native fivem + * + * @param dir Location of the file where the project will be built + * + * @return void + */ public static onEnable = (dir: string): void => { request.get('https://runtime.fivem.net/doc/natives.json', (error, response, content) => { const files = new FilesBuilder(dir); + const json = JSON.parse(content); files.init().then(async () => { - files.category(json); await new Promise(resolve => setTimeout(resolve, 1000)); - const builder = new ContentGenerate(files); builder.generateTemplate(json); - - }); }); }; + /** + * Folder generate logic + * + * @param response + * + * @return void + */ public static onFolderGenerate = (response: void) => { console.info("Create build directory successfully : " + response); }; - public static onCompletionsGenerate = () => { - // TODO Implement this - }; - - public static onFileUpdate = () => { - // TODO Implement this - }; - - public static onFinish = () => { - // TODO Implement this + /** + * File update logic + * + * @param filename Name of the updated file + * @param nativename Name of the native fivem + * + * @return void + */ + public static onFileUpdate = (filename: String, nativename: String): void => { + console.log(""); + console.log("File update successfully"); + console.log("[File : " + filename + " ]"); + console.log("[Native : " + nativename + " ]"); + console.log("Done."); + console.log(""); }; } - new Main.onEnable("build"); diff --git a/src/content-generate.ts b/src/content-generate.ts index 211de20..d45909f 100644 --- a/src/content-generate.ts +++ b/src/content-generate.ts @@ -1,23 +1,36 @@ import {FilesBuilder} from "./files-builder"; +/** + * The [[ContentGenerate]] class allows to generate procedurally all the content necessary for the construction of templates + */ export class ContentGenerate { + /** + * Instance of the object [[FilesBuilder]] + */ private filesBuilder: FilesBuilder; - private generateDocs: string = ""; - /** - * @param filesBuilder + * Instance of a generated documentation */ - constructor(filesBuilder: FilesBuilder) { - this.filesBuilder = filesBuilder; - } + private generateDocs: String = ""; + /** - * @param data + * Template to generate documentation and shortcuts for native speakers + * + * @param description + * @param module + * @param submodule + * @param see + * @param usage + * @param param + * @param _return + * @param _function + * + * @return template */ - public generateTemplate = (data: JSON): void => { - const template = (description: String, module: String, submodule: String, see: String, usage: String, param: String, _return: String, _function: String) => ` + private template = (description: String, module: String, submodule: String, see: String, usage: String, param: String, _return: String, _function: String) => ` --@description ${description} --@module ${module} --@submodule ${submodule} @@ -28,19 +41,54 @@ ${param} ${_function} `; + /** + * Builder allowing the instance of difference objects / utility values for the generation of the template as well as the update of the file to contain the native + * + * @param filesBuilder Class instance [[FilesBuilder]] + */ + constructor(filesBuilder: FilesBuilder) { + this.filesBuilder = filesBuilder; + } + + + /** + * Allows to generate the native template in a procedural way one by one + * + * @param data Request the result of the query to the API of the FiveM natives + * + * @return void + */ + public generateTemplate = (data: JSON): void => { + + /** + * Current count native build + */ + let count = 0; + for (let category in data) for (let natives in data[category]) { + if (data.hasOwnProperty(category)) + count++; + + + /** + * Shortcut of data[category][natives] + */ let jsonNative: JSON = data[category][natives]; - let nativeName: String = this.nativeName(jsonNative, natives); - let nativeParams: { luaDocs: String; params: String; paramsWithType: String } = this.nativeParams(jsonNative); - this.generateDocs += template(this.nativeDescription(data), "NATIVE", category, jsonNative.name, this.nativeUsage(jsonNative, nativeParams.paramsWithType), nativeParams.luaDocs, jsonNative.results, "function " + nativeName + "(" + this.nativeParams(jsonNative).params + ") end"); + /** + * Generation of the native name + */ + let nativeName: String = this.nativeName(jsonNative, natives); - // TODO Fix issue update file don't update online with submodule value - //console.log(this.generateDocs); + /** + * Returns parameters in different formats + */ + let nativeParams: { luaDocs: String; params: String; paramsWithType: String } = this.nativeParams(jsonNative); - this.filesBuilder.update(category, this.generateDocs) + this.generateDocs = this.template(this.nativeDescription(data), "NATIVE", category, jsonNative.name, this.nativeUsage(jsonNative, nativeParams.paramsWithType), nativeParams.luaDocs, jsonNative.results, "function " + nativeName + "(" + this.nativeParams(jsonNative).params + ") end"); + this.filesBuilder.update(category, this.generateDocs, nativeName); } }; diff --git a/src/files-builder.ts b/src/files-builder.ts index 498b28b..14ee8ba 100644 --- a/src/files-builder.ts +++ b/src/files-builder.ts @@ -6,6 +6,9 @@ import {Main} from "../main"; */ export class FilesBuilder { + /** + * Location of the file where the project will be built + */ public readonly directory: string; /** @@ -50,15 +53,20 @@ export class FilesBuilder { /** + * Allows to update a file while keeping the values present in this file previously. * - * @param files - * @param data + * @param files Name of the currently updated file + * @param data Data to be inserted in the file + * @param nativeName Name of the native FiveM + * + * @return void */ - public update = (files: String, data: String): void => { + public update = (files: String, data: String, nativeName: String): void => { filesystem.appendFile(this.directory + "/" + files + ".lua", data, (error) => { if (error) - console.error("can't update file" + files) + console.error("can't update file" + files); + Main.onFileUpdate(files, nativeName) }); };