computable-pandoc/scripts/make_dist.lua

66 lines
2.1 KiB
Lua

-- Makes bundle and min distribution
-- Adds local luarocks modules
local optpath = "./opt/share/lua/5.4/"
package.path = optpath .. "?.lua;" .. package.path
-- Adds Lua custom extensions
require "dog"
-- Makes distribution
local function make_dist(name, bundle)
-- Chomps file
local function chomp(str)
local without = without or false
str = string.readtext(str):strip()
return "\n" .. str .. "\n"
end
-- Variables
local bundle = (bundle == nil or bundle == true)
local dist = pandoc.path.join({"dist", name})
local ext = chomp(optpath .. "dog.lua")
local fnl = chomp(optpath .. "fennel.lua")
local fnl = fnl:gsub("\nreturn mod\n", "\nlocal fnl = mod\n")
local pan = chomp("src/pandoc.lua")
local nat = chomp("src/natural.lua"):gsub("\nreturn nat\n", "")
local msg = ("src/locale.yaml"):readtext()
local lit = chomp("src/literate.lua"):gsub("\nreturn lit\n", "")
local lit = lit:gsub("#locale%(%)", msg)
local license = string.strip([[
Computable Pandoc:
(C) 2023 perro hi@perrotuerto.blog
License: GPLv3 https://git.cuates.net/perro/computable-pandoc/src/branch/no-masters/LICENSE.txt
Source: https://git.cuates.net/perro/computable-pandoc
]])
local extralicense = string.strip([[
Computable Pandoc & Fennel Bundle:
A Pandoc filter for literate and natural programming
]] .. license .. "\n" .. [[
Fennel:
(C) 2016-2023 Calvin Rose and contributors
License: MIT License https://git.sr.ht/~technomancy/fennel/tree/main/item/LICENSE
Source: https://sr.ht/~technomancy/fennel or https://github.com/bakpakin/Fennel/issues
Website: https://fennel-lang.org
]])
-- Bundles Fennel and Computable Pandoc
-- TODO: lit and nat should be rocks and, therefore, should be:
-- added only in bundle
-- use 'require' in minimal
file = io.open(dist, "w")
if bundle then
file:write("--[[\n", extralicense, "\n]]--\n")
file:write(fnl, ext)
else
file:write("--[[\n", license, "\n]]--\n")
file:write('\nrequire "fennel"\nrequire "dog"\n')
end
file:write(nat, lit, pan)
file:close()
end
make_dist("lin.bundle.lua")
make_dist("lin.min.lua", false)