|
1 | 1 | (local {: autoload : define} (require :nfnl.module)) |
2 | 2 | (local core (autoload :nfnl.core)) |
| 3 | +(local str (autoload :nfnl.string)) |
3 | 4 | (local compile (autoload :nfnl.compile)) |
4 | 5 | (local config (autoload :nfnl.config)) |
5 | 6 | (local notify (autoload :nfnl.notify)) |
6 | 7 | (local fs (autoload :nfnl.fs)) |
| 8 | +(local gc (autoload :nfnl.gc)) |
7 | 9 |
|
8 | 10 | (local M (define :nfnl.api)) |
9 | 11 |
|
| 12 | +(fn M.find-orphans [] |
| 13 | + "Find orphan Lua files that were compiled from a Fennel file that no longer exists. Display them with notify." |
| 14 | + (let [dir (vim.fn.getcwd) |
| 15 | + {: config : root-dir : cfg} (config.find-and-load dir)] |
| 16 | + (if config |
| 17 | + (let [orphan-files (gc.find-orphan-lua-files {: root-dir : cfg})] |
| 18 | + (if (core.empty? orphan-files) |
| 19 | + (notify.info "No orphan files detected.") |
| 20 | + (notify.warn |
| 21 | + "Orphan files detected, delete them with :NfnlDeleteOrphans.\n" |
| 22 | + (->> orphan-files |
| 23 | + (core.map |
| 24 | + (fn [f] |
| 25 | + (.. " - " f))) |
| 26 | + (str.join "\n")))) |
| 27 | + orphan-files) |
| 28 | + (do |
| 29 | + (notify.warn "No .nfnl.fnl configuration found.") |
| 30 | + [])))) |
| 31 | + |
| 32 | +(fn M.delete-orphans [] |
| 33 | + "Delete orphan Lua files that were compiled from a Fennel file that no longer exists." |
| 34 | + (let [dir (vim.fn.getcwd) |
| 35 | + {: config : root-dir : cfg} (config.find-and-load dir)] |
| 36 | + (if config |
| 37 | + (let [orphan-files (gc.find-orphan-lua-files {: root-dir : cfg})] |
| 38 | + (if (core.empty? orphan-files) |
| 39 | + (notify.info "No orphan files detected.") |
| 40 | + (do |
| 41 | + (notify.info |
| 42 | + "Deleting orphan files:\n" |
| 43 | + (->> orphan-files |
| 44 | + (core.map |
| 45 | + (fn [f] |
| 46 | + (.. " - " f))) |
| 47 | + (str.join "\n"))) |
| 48 | + (core.map os.remove orphan-files))) |
| 49 | + orphan-files) |
| 50 | + (do |
| 51 | + (notify.warn "No .nfnl.fnl configuration found.") |
| 52 | + [])))) |
| 53 | + |
10 | 54 | (fn M.compile-file [{: path : dir}] |
11 | 55 | "Compiles a file into the matching Lua file. Returns the compilation result. Takes an optional `dir` key that changes the working directory. |
12 | 56 |
|
|
0 commit comments