-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert-mod-override.lua
More file actions
49 lines (39 loc) · 1.38 KB
/
convert-mod-override.lua
File metadata and controls
49 lines (39 loc) · 1.38 KB
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
if #arg == 0 then
print("Usage: lua convert-mod-override.lua ${path_to_shard_dir} <output_dir_path>")
os.exit(1)
end
-- ---------- ---------- ---------- ---------- ---------- ---------- --
-- import util functions
require("utils/shell")
require("utils/file")
require("utils/string")
local json = require("utils/json")
-- ---------- ---------- ---------- ---------- ---------- ---------- --
-- prepare
local shardDirPath = arg[1]
local overrideFilePath = shardDirPath.."/modoverrides.lua"
local currentDirPath = ExecuteShellCommandReturnOutput("pwd")
local outputDirPath = arg[2] or currentDirPath.."/output"
if not FileExists(overrideFilePath, false) then
print("Mod override file not found in "..shardDirPath)
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
-- ---------- ---------- ---------- ---------- ---------- ---------- --
local config = dofile(overrideFilePath)
local result = {}
for k, v in pairs(config) do
assert(type(k) == "string")
local modID = k:removePrefix("workshop-")
result[modID] = v
end
local jsonStr = json.EncodeCompliant(result)
local outputFilePath = outputDirPath.."/modoverrides.json"
WriteToFile(outputFilePath, jsonStr)
print("Completed! Output: "..outputFilePath)