1Axen / blink

An IDL compiler written in Luau for ROBLOX buffer networking
https://1axen.github.io/blink/
MIT License
18 stars 0 forks source link

Watch option to automatically track changes to source file and recompile #9

Closed 1Axen closed 1 month ago

1Axen commented 1 month ago

Description

A new --watch (and it's shorthand version -w) option added to the CLI version of blink to automatically watch for changes to the definition file and recompile it. There is already precedent for this in other ROBLOX cli tools like rojo's sourcemap watch and darklua's process watch.

Motivation

It can be quite tedious to continuously run the blink compile command when doing rapid iterations on a definition file.

Implementation

When --watch is passed as an option blink will enter into an infinite while loop periodically checking for changes to the file by comparing its last modified date. When the file is changed a recompilation will be triggered, note that prompts will be skipped as prompting the user defeats the purpose of this feature request. Imports may present a challenge as a list of watched files will need to be generated in order to make sure that any changes to imported files will also trigger a recompilation, this will require some sort of imports only parser to be written.

Drawbacks

It might take significant effort to handle imports correctly.

Alternatives

There's the option of not adding this feature but it's the authors belief that this feature presents a great improvement to DX and thus its worth its implementation time.

Hudison commented 1 month ago

In the mean time as a workaround for those who use any type of runtime like Lune. You can use a script similar to this.

task.spawn(function()
    local lastModified = dateTime.now():toIsoDate()
    while true do
        local metadata = fs.metadata("src/server/network.blink")
        if lastModified ~= metadata.modifiedAt then
            executeCommand("blink", { "src/server/network.blink" })
            lastModified = metadata.modifiedAt
        end
        task.wait(2)
    end
end)
1Axen commented 1 month ago

Feature added in v0.13.0.