demonnic / muddler

A build tool for Mudlet package developers
MIT License
40 stars 12 forks source link

adding support for callbacks #38

Open gesslar opened 4 months ago

gesslar commented 4 months ago
gesslar commented 4 months ago

Specifically, as an example:

MuddleWatcher = MuddleWatcher or {
  paths = {
    { "D:/git/threshbuff", true, nil },
    { "D:/git/ThreshKeepalive", true, nil },
  }
}

local function preremove(pkg)
  debugc("=> Running preremove: " .. tostring(pkg))
end

local function postremove(pkg)
  debugc("=> Running postremove: " .. tostring(pkg))
end

local function preinstall(pkg)
  debugc("=> Running preinstall: " .. tostring(pkg))
end

local function postinstall(pkg)
  debugc("=> Running postinstall: " .. tostring(pkg))
end

if Muddler then
  for _, path in ipairs(MuddleWatcher.paths) do
    if path[2] == true then
    if path[3] == nil then
        path[3] = path[3] or Muddler:new({
          path = path[1],
          preremove = preremove,
          postremove = postremove,
          preinstall = preinstall,
          postinstall = postinstall,
        })
        debugc("Added Muddler watcher for " .. path[1])
      end
    end
  end
end
demonnic commented 4 months ago

Apart from preferring a space between the comma and second parameter name, this looks good to me.

gesslar commented 4 months ago

As well, one could use the example you have on your CI page to be extended as such:

local function killMDK(pkg)
  for pkgName, _ in pairs(package.loaded) do
    if pkgName:find(pkg) then
      debugc("Uncaching lua package " .. pkgName)
      package.loaded[pkgName] = nil
    end
  end
end
gesslar commented 4 months ago

Apart from preferring a space between the comma and second parameter name, this looks good to me.

fine, i'll make that change.