Skip to content

Commit

Permalink
Finish TypeDocs + First release
Browse files Browse the repository at this point in the history
  • Loading branch information
ImBaphomettt committed May 24, 2019
1 parent 339fce1 commit e75ca88
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 34 deletions.
48 changes: 33 additions & 15 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
78 changes: 63 additions & 15 deletions src/content-generate.ts
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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);
}
};

Expand Down
16 changes: 12 additions & 4 deletions src/files-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
});
};

Expand Down

0 comments on commit e75ca88

Please sign in to comment.