-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract-mod-config.lua
66 lines (53 loc) · 1.86 KB
/
extract-mod-config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
if #arg == 0 then
print("Usage: lua extract-mod-config.lua ${path_to_target_mod_dir} <output_dir_path> <lang_code>")
os.exit(1)
end
-- ---------- ---------- ---------- ---------- ---------- ---------- --
-- import util functions
require("utils/shell")
require("utils/file")
require("utils/string")
require("mocks/mod-config/mock")
local json = require("utils/json")
-- ---------- ---------- ---------- ---------- ---------- ---------- --
-- prepare
local targetModDirPath = arg[1]
local modInfoPath = targetModDirPath.."/modinfo.lua"
local currentDirPath = ExecuteShellCommandReturnOutput("pwd")
local outputDirPath = arg[2] or currentDirPath.."/output/modconfig"
locale = arg[3] or "en"
if not FileExists(modInfoPath, false) then
print("Mod info not found in "..modInfoPath)
os.exit(1)
end
if not FileExists(outputDirPath, true) then
local ok = MakeDir(outputDirPath, false)
if not ok then
print("Failed to create output directory in "..outputDirPath)
os.exit(1)
end
end
-- ---------- ---------- ---------- ---------- ---------- ---------- --
---get mod id from path
---@param path string path to mod directory
---@return string string mod id
local function getModIdFromPath(path)
local lastComponent = path:getLastComponentFromPath()
local modID = lastComponent:removePrefix("workshop-")
return modID
end
print("\nLoad mod info from "..modInfoPath)
dofile(modInfoPath)
local modID = getModIdFromPath(targetModDirPath)
local modInfo = {
id = modID,
name = name or "?",
author = author or "?",
version = version or "?",
description = description or "",
configuration_options = configuration_options or {},
}
local outputFilePath = outputDirPath.."/"..locale.."."..modID..".json"
local jsonStr = json.EncodeCompliant(modInfo)
WriteToFile(outputFilePath, jsonStr)
print("Completed! Output directory: "..outputDirPath)