Skip to content

⭐ Serve mode with auto restart resouce on server #402

@websharik

Description

@websharik

Replace IDE watcher to integrated watcher and use it as demon for this mode.
On change, compile with inject dev script as lualib and add to files .build with timestamp/hash.

Dev scripts

AutoRestart:

Looking .build file on the root resouce dir and on change restart resource.

import '.build' //Hello from https://github.com/mtasa-typescript/mtasa-lua-utils/issues/401

new (class AutoRestart {

    private fileName = '.build'
    private build = ''
    private interval = 5 //interval checks
    private wait = 5 //wait before restart
    private debug = false //show debug
    private timer: Timer

    constructor() {
        this.build = this.getResourceBuild()
        this.timer = setTimer(() => { this.checkBuild() }, this.interval * 1000, 0)
    }

    getResourceBuild () : string {
        if (fileExists(this.fileName)) {
            const file = fileOpen(this.fileName, true)
            const build = fileRead(file, fileGetSize(file))
            fileClose(file)
            return build
        } else return this.build
    }

    checkBuild() : void {
        if (this.build !== this.getResourceBuild()) {
            outputServerLog(`Build changed! Restart after ${this.wait} seconds...`)
            killTimer(this.timer)
            setTimer(() => {
                restartResource(getThisResource())
            }, this.wait * 1000, 1)
        } else if (this.debug) outputServerLog(`Build: ${this.build}/${this.getResourceBuild()}`)
    }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions