@thigasdevelopment/luam 0.10.6 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/luam.mjs +8226 -7615
- package/package.json +1 -1
- package/template/luam.manifest +15 -2
- package/lua/dotenv.lua +0 -160
- package/lua/env.lua +0 -18
package/package.json
CHANGED
package/template/luam.manifest
CHANGED
|
@@ -2,8 +2,21 @@ name = 'luam-resource'
|
|
|
2
2
|
version = '1.0.0'
|
|
3
3
|
description = 'A Luam resource scaffolded by luam init.'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
compilerOptions = {
|
|
6
|
+
strict = true,
|
|
7
|
+
oop = false,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
sources = {
|
|
11
|
+
server = { 'src/server/**/*.luam' },
|
|
12
|
+
client = { 'src/client/**/*.luam' },
|
|
13
|
+
shared = { 'src/shared/**/*.luam' },
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
assets = {
|
|
17
|
+
{ from = 'assets/**/*', to = 'assets' },
|
|
18
|
+
}
|
|
19
|
+
|
|
7
20
|
outDir = 'build'
|
|
8
21
|
|
|
9
22
|
transport = {
|
package/lua/dotenv.lua
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
local DEFAULT_FILE = '.env'
|
|
2
|
-
|
|
3
|
-
local KEYWORDS = {
|
|
4
|
-
['true'] = true,
|
|
5
|
-
['false'] = false,
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
local ESCAPES = {
|
|
9
|
-
['n'] = '\n',
|
|
10
|
-
['r'] = '\r',
|
|
11
|
-
['t'] = '\t',
|
|
12
|
-
['"'] = '"',
|
|
13
|
-
["'"] = "'",
|
|
14
|
-
['\\'] = '\\',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
local function trim(value)
|
|
18
|
-
return value:match('^%s*(.-)%s*$') or ''
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
local function unescape(character)
|
|
22
|
-
return ESCAPES[character] or ('\\' .. character)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
local function cast(raw)
|
|
26
|
-
local quote = raw:sub(1, 1)
|
|
27
|
-
|
|
28
|
-
if quote == '"' or quote == "'" then
|
|
29
|
-
local quoted = raw:match('^' .. quote .. '(.*)' .. quote)
|
|
30
|
-
|
|
31
|
-
if quoted then
|
|
32
|
-
return (quoted:gsub('\\(.)', unescape))
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
local value = trim((raw:gsub('%s+#.*$', '')))
|
|
37
|
-
local keyword = KEYWORDS[value]
|
|
38
|
-
|
|
39
|
-
if keyword ~= nil then
|
|
40
|
-
return keyword
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
return tonumber(value) or value
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
local function read(path)
|
|
47
|
-
local file = fileOpen(path, true)
|
|
48
|
-
|
|
49
|
-
if not file then
|
|
50
|
-
return nil
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
local content = fileRead(file, fileGetSize(file))
|
|
54
|
-
|
|
55
|
-
fileClose(file)
|
|
56
|
-
|
|
57
|
-
return content
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
local function parse(path, content)
|
|
61
|
-
local values = {}
|
|
62
|
-
local number = 0
|
|
63
|
-
|
|
64
|
-
for line in (content .. '\n'):gmatch('(.-)\r?\n') do
|
|
65
|
-
number = number + 1
|
|
66
|
-
|
|
67
|
-
local trimmed = trim(line)
|
|
68
|
-
|
|
69
|
-
if trimmed ~= '' and trimmed:sub(1, 1) ~= '#' then
|
|
70
|
-
local key, raw = trimmed:match('^([%a_][%w_]*)%s*=%s*(.*)$')
|
|
71
|
-
|
|
72
|
-
if not key then
|
|
73
|
-
error('Malformed entry in "' .. path .. '" on line ' .. number .. '. Expected "KEY=value".')
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
values[key] = cast(raw)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
return values
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
local function seal(path, values)
|
|
84
|
-
return setmetatable({}, {
|
|
85
|
-
__index = function(_, key)
|
|
86
|
-
local value = values[key]
|
|
87
|
-
|
|
88
|
-
if value == nil then
|
|
89
|
-
error('"' .. tostring(key) .. '" is not declared in "' .. path .. '".', 2)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
return value
|
|
93
|
-
end,
|
|
94
|
-
|
|
95
|
-
__newindex = function(_, key)
|
|
96
|
-
error('The environment is read-only and "' .. tostring(key) .. '" cannot be assigned.', 2)
|
|
97
|
-
end,
|
|
98
|
-
|
|
99
|
-
__metatable = false,
|
|
100
|
-
})
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
if localPlayer ~= nil then
|
|
104
|
-
return
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
Dotenv = {}
|
|
108
|
-
Dotenv.__index = Dotenv
|
|
109
|
-
|
|
110
|
-
function Dotenv.new(path)
|
|
111
|
-
path = path or DEFAULT_FILE
|
|
112
|
-
|
|
113
|
-
local content = read(path)
|
|
114
|
-
|
|
115
|
-
if not content then
|
|
116
|
-
error('Failed to read the environment file "' .. tostring(path) .. '".', 2)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
local self = setmetatable({}, Dotenv)
|
|
120
|
-
|
|
121
|
-
self.path = path
|
|
122
|
-
self.values = parse(path, content)
|
|
123
|
-
|
|
124
|
-
return self
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
function Dotenv:get(key, default)
|
|
128
|
-
local value = self.values[key]
|
|
129
|
-
|
|
130
|
-
if value == nil then
|
|
131
|
-
return default
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
return value
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
function Dotenv:has(key)
|
|
138
|
-
return self.values[key] ~= nil
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
function Dotenv:all()
|
|
142
|
-
local copy = {}
|
|
143
|
-
|
|
144
|
-
for key, value in pairs(self.values) do
|
|
145
|
-
copy[key] = value
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
return copy
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
function Dotenv:apply()
|
|
152
|
-
if type(process) ~= 'table' then
|
|
153
|
-
process = {}
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
process.env = seal(self.path, self.values)
|
|
157
|
-
env = process.env
|
|
158
|
-
|
|
159
|
-
return process.env
|
|
160
|
-
end
|
package/lua/env.lua
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
local ENVIRONMENT_FILE = '.env'
|
|
2
|
-
|
|
3
|
-
if localPlayer ~= nil then
|
|
4
|
-
return
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
if not fileExists(ENVIRONMENT_FILE) then
|
|
8
|
-
if type(process) ~= 'table' then
|
|
9
|
-
process = {}
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
process.env = {}
|
|
13
|
-
env = process.env
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
Dotenv.new(ENVIRONMENT_FILE):apply()
|