import { FilesBuilder } from "./files-builder" ; import { stat } from "fs-extra" ; /**
 * 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 ; /**
     * Instance of a generated documentation
     */ private generateDocs : String = "" ; param description param module param submodule param see param usage param param param _return param _function return private template = ( description , module , submodule , see , usage , param , _return , _function ) => `
--@description ${ description }
--@module ${ module }
--@submodule ${ submodule }
--@see ${ see }
--@usage ${ usage }
${ param }
--@return ${ _return }
${ _function }
` ; param filesBuilder constructor ( filesBuilder ) { this . filesBuilder = filesBuilder ; } param field private fieldToReplace = ( field ) : string => { if ( field == "repeat" ) { return "_repeat" ; } else { return field ; } } ; param data return public generateTemplate = ( data ) : void => { /**
         * Current count native build
         */ let stats = { native : { total : 0 , current : 0 , } } ; for ( let category in data ) for ( let natives in data [ category ] ) { stats . native . total ++ ; } for ( let category in data ) for ( let natives in data [ category ] ) { /**
                 * Shortcut of data[category][natives]
                 */ let jsonNative = data [ category ] [ natives ] ; /**
                 * Generation of the native name
                 */ let nativeName = this . nativeName ( jsonNative , natives ) ; /**
                 * Returns parameters in different formats
                 */ let nativeParams = this . nativeParams ( jsonNative ) ; 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 ( stats , category , this . generateDocs , nativeName ) ; } } ; param data param natives return private nativeName = ( data , natives ) : String => { if ( data . name !== undefined || natives !== undefined ) return ( data . name || natives ) . toLowerCase ( ) . replace ( '0x' , 'n_0x' ) . replace ( /_([a-z])/g , ( sub , bit ) => bit . toUpperCase ( ) ) . replace ( /^([a-z])/ , ( sub , bit ) => bit . toUpperCase ( ) ) ; } ; param data return private nativeParams = ( data ) : { luaDocs : String ; params : String ; paramsWithType : String ; } => { /**
         * "luaDocs" Allows to save the generation of LUA documentation and return it
         *
         * "params" Allows to save the generation of the native parameters and to return it.
         */ let luaDocs = "" , params = "" , paramsWithType = "" ; for ( let i = 0 ; i <= data . params . length - 1 ; i ++ ) { luaDocs += ( ( i != 0 ? "\n" : "" ) + "--@params " + data . params [ i ] . name + " " + data . params [ i ] . type ) ; params += ( ( i != 0 ? "," : "" ) + this . fieldToReplace ( data . params [ i ] . name ) ) ; paramsWithType += ( ( i != 0 ? "," : "" ) + data . params [ i ] . type + " " + this . fieldToReplace ( data . params [ i ] . name ) ) ; } return { luaDocs : luaDocs , params : params , paramsWithType : paramsWithType } ; } ; param data return private nativeDescription = ( data ) : String => { if ( data . description !== undefined ) return data . description ; else return "This natives does not have an official description." ; } ; param data param nativeParams return private nativeUsage = ( data , nativeParams ) : String => { const template = ( result , native , params ) => `${ result } ${ native }(${ params });` ; return template ( data . results , data . name , nativeParams ) ; } ; }