forked from Vurv78/gmod-upload
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.lua
79 lines (60 loc) · 1.99 KB
/
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
67
68
69
70
71
72
73
74
75
76
77
78
79
local libPath = "{{LIB_PATH}}"
if libPath ~= "{{LIB" .. "_PATH}}" then
package.path = package.path .. ";" .. libPath .. "/?.lua"
end
local safeCall = require( "lib/runner" )
local function loadConfig()
local json = require( "lib/json" )
---@param list string[]
---@return table<string, string>
local function makeLookup( list )
local newList = {}
for _, v in ipairs( list ) do
newList[v] = v
end
return newList
end
local TITLE = assert( arg[1], "No title given" )
local TYPE = assert( arg[2], "No type given" )
do
local valid = makeLookup( {
"ServerContent", "gamemode", "map", "weapon", "vehicle", "npc", "tool", "effects", "model", "entity"
} )
assert( valid[TYPE], "Invalid type input: '" .. TYPE .. "'" )
end
local TAGS = {}
do
local valid = makeLookup( {
"fun", "roleplay", "scenic", "movie", "realism", "cartoon", "water", "comic", "build"
} )
local added = {}
local function addTag( tag )
if not tag then return end
if tag == "" then return end
assert( valid[tag], "Invalid tag: " .. tag )
if added[tag] then return end
table.insert( TAGS, tag )
added[tag] = true
end
addTag( arg[3] )
addTag( arg[4] )
addTag( arg[5] )
assert( #TAGS > 0, "No tags given" )
end
local path = os.time() .. ".json"
local config = {
title = TITLE,
type = TYPE,
tags = TAGS,
ignore = { path, ".git/*", ".github/*", "addon.txt" }
}
if arg[6] == "true" then -- ignore lua
table.insert( config.ignore, "*.lua" )
end
local newContents = json.encode( config )
local handle = assert( io.open( path, "wb" ), "Failed to open file for writing: " .. path )
handle:write( newContents )
handle:close()
print( path )
end
safeCall( loadConfig, "Failed to process addon config" )