Skip to content

Commit

Permalink
feat: add support for the pesde package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
4x8Matrix committed Nov 28, 2024
1 parent b96a57e commit 80ece98
Show file tree
Hide file tree
Showing 265 changed files with 3,902 additions and 2,789 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.env.luau
.env.luau
pesde.lock
lune_packages
luau_packages
bundled.luau
15 changes: 0 additions & 15 deletions .luaurc
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,5 @@
"languageMode": "strict",
"lint": {
"*": false
},
"aliases": {
"builders": "./packages/builders/src",
"cdn": "./packages/cdn/src",
"classes": "./packages/classes/src",
"core": "./packages/core/src",
"extensions": "./packages/extensions/src",
"std-polyfills": "./packages/std-polyfills/src",
"api-types": "./packages/api-types/src",
"rest": "./packages/rest/src",
"utils": "./packages/utils/src",
"vendor": "./packages/vendor/src",
"voice": "./packages/voice/src",
"websocket": "./packages/websocket/src",
"frktest": "./extern/frktest/src"
}
}
24 changes: 24 additions & 0 deletions .lune/script.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--> run a script, scripts can be found under ./lune/scripts, they're generally just luau files that are quickly put together
--> in order to achieve something quickly - such as automating files

-- NOTE: we're using the `Lune` runtime in the CI/CD environment, so we're not going to be using the `@std-polyfills`
-- package that the discord-luau package uses.

local process = require("@lune/process")
local fs = require("@lune/fs")

local task = require("./task")

local processArguments = table.clone(process.args)
local scriptName = table.remove(processArguments, 1)
local scriptPath = `.lune/scripts/{scriptName}.luau`

assert(fs.isFile(scriptPath), `Script '{scriptName}' not found! Unable to execute script!`)

local taskObject = task.new("lune"):addArgument("run"):addArgument(scriptPath)

for _, argument in processArguments do
taskObject:addArgument(argument)
end

taskObject:execute()
26 changes: 26 additions & 0 deletions .lune/scripts/countAliases.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local fs = require("@lune/fs")
local process = require("@lune/process")

local packageDir = process.args[1]

local function patchFile(dir, fileName)
local fileData = fs.readFile(`{dir}/{fileName}`)

for requirePath: string in fileData.gmatch(fileData, 'local %S+ = require%("(%S+)"%)') do
if string.sub(requirePath, 1, 1) == "@" then
print(`{dir}/{fileName}`)
end
end
end

local function readFolder(dir)
for _, object in fs.readDir(dir) do
if fs.isDir(`{dir}/{object}`) then
readFolder(`{dir}/{object}`)
else
patchFile(dir, object)
end
end
end

readFolder(packageDir)
42 changes: 42 additions & 0 deletions .lune/scripts/fsIntoTable.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local fs = require("@lune/fs")
local process = require("@lune/process")

local luaTableSource = "{\n"
local packageDir = process.args[1]

local function readFile(dir, fileName)
local fileName = string.sub(fileName, 1, -6)
local source = `{dir}/{fileName}`

luaTableSource = `local {fileName} = require("{string.gsub(source, packageDir .. "/", "")}")\n` .. luaTableSource
luaTableSource ..= `{fileName} = {fileName},\n`
end

local function openFolder(dir)
local dirSplit = string.split(dir, "/")
local dirName = dirSplit[#dirSplit]

luaTableSource ..= `{dirName} = \{\n`
end

local function closeFolder()
luaTableSource ..= `},\n`
end

local function readFolder(dir)
for _, object in fs.readDir(dir) do
if fs.isDir(`{dir}/{object}`) then
openFolder(`{dir}/{object}`)
readFolder(`{dir}/{object}`)
closeFolder()
else
readFile(dir, object)
end
end
end

readFolder(packageDir)

luaTableSource ..= "}\n"

print(luaTableSource)
8 changes: 8 additions & 0 deletions .lune/task/requireTests.luau
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ end
function requireTests(path: string)
for _, object in fs.readDir(path) do
if fs.isDir(`{path}/{object}`) then
if object == "luau_packages" or object == "lune_packages" then
continue
end

requireTests(`{path}/{object}`)
else
if not string.find(object, ".spec.luau") then
continue
end

requireFile(`{path}/{object}`)
end
end
Expand Down
6 changes: 3 additions & 3 deletions .lune/test.luau
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--> Task for running unit-tests using frktest

local frktest = require("@frktest/frktest")
local reporter = require("@frktest/reporters/lune_console_reporter")
local frktest = require("../lune_packages/frktest")
local reporter = frktest._reporters.lune_console_reporter

local requireTests = require("./task/requireTests")

requireTests("tests")
requireTests("packages")

reporter.init()

Expand Down
17 changes: 2 additions & 15 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
{
"editor.formatOnSave": true,
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.inlayHints.variableTypes": true,
"luau-lsp.inlayHints.functionReturnTypes": true,
"luau-lsp.inlayHints.parameterNames": "all",
"luau-lsp.inlayHints.parameterTypes": true,
"luau-lsp.inlayHints.typeHintMaxLength": 50,
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.8.8/",
"@builders": "./packages/builders/src",
"@cdn": "./packages/cdn/src",
"@classes": "./packages/classes/src",
"@core": "./packages/core/src",
"@extensions": "./packages/extensions/src",
"@std-polyfills": "./packages/std-polyfills/src",
"@api-types": "./packages/api-types/src",
"@rest": "./packages/rest/src",
"@utils": "./packages/utils/src",
"@vendor": "./packages/vendor/src",
"@voice": "./packages/voice/src",
"@websocket": "./packages/websocket/src",
"@frktest": "./extern/frktest/src"
"@lune/": "~/.lune/.typedefs/0.8.8/"
}
}
1 change: 1 addition & 0 deletions aftman.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ lune = "lune-org/[email protected]"
# moonwave-extractor = "evaera/[email protected]"
selene = "Kampfkarren/[email protected]"
stylua = "JohnnyMorganz/[email protected]"
darklua = "seaofvoices/[email protected]"
26 changes: 5 additions & 21 deletions development.luau
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
local botObject = require("@core/bot")
local dateTime = require("@std-polyfills/datetime")

local intentsBuilder = require("@builders/intents")
local widgetSettings = require("@builders/guild/widgetSettings")

local env = require(".env")

local PENGU_BOT_ID = "726819179054891149"
local DISCORD_LUAU_GENERAL_ID = "1273035768700338278"
local DISCORD_LUAU_SERVER = "1273035219561091193"

local discordIntents = intentsBuilder.new()
local discordLuau = require("packages/core/src")
local builders = require("packages/builders/src")

discordIntents:addIntent("Guilds")

local discordBot = botObject.new({
local discordBot = discordLuau.Bot.new({
intents = builders.intents.new({ "Guilds" }):build(),
token = env.DISCORD_BOT_TOKEN,
intents = discordIntents:build(),
})

discordBot.onAllShardsReady:listen(function()
assert(discordBot.application, ``)

local guild = discordBot:getGuildAsync(DISCORD_LUAU_SERVER):expect("1")
local textChannel = discordBot:getTextChannelAsync(DISCORD_LUAU_GENERAL_ID):expect("2")

textChannel:createMessageAsync({
content = "Hello, world!",
})
print("we're up and running!")
end)

discordBot:connectAsync():after(function()
Expand Down
Empty file removed examples/.gitkeep
Empty file.
1 change: 0 additions & 1 deletion extern/frktest
Submodule frktest deleted from 5b1ba0
1 change: 0 additions & 1 deletion init.luau

This file was deleted.

14 changes: 14 additions & 0 deletions packages/api-types/.lune/bundle.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--> Task to execute Darklua for bundling the various packages apart of Discord-Luau

local task = require("../../../.lune/task")

task.new("darklua")
:addArgument("process")
:addArgument("src/init.luau")
:addArgument("bundled.luau")
:addArgument(`-cdarklua.json`)
:execute()

task.new("stylua"):addArgument("bundled.luau"):execute()
task.new("lune"):addArgument("run"):addArgument("fixTypes"):execute()
task.new("stylua"):addArgument("bundled.luau"):execute()
110 changes: 110 additions & 0 deletions packages/api-types/.lune/fixTypes.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
--> Task responsible for bundling the API-Types package, as well as fixing types for said package because at the moment
--> types are not bundled via Darklua.

local fs = require("@lune/fs")

local stream = require("../luau_packages/stream")

local fileContent = fs.readFile("bundled.luau")
local fileTypes = {}

local hasFoundType = true

while hasFoundType do
local cursor = string.find(fileContent, `export type`)

if not cursor then
hasFoundType = false

continue
end

local stream = stream.new(fileContent, cursor + 11)
local name, generics, definition = "", "", ""

stream:trim()

name = stream:advanceUntil(function(char: string)
local isNotChar = string.match(char, "%a") == nil
local isNotNumber = tonumber(char) == nil

return isNotChar and isNotNumber
end) :: string

stream:trim()

if string.sub(name, #name, #name) == "<" then
name = string.sub(name, 1, #name - 1)

generics = `<` .. stream:advanceUntil(function(char: string)
return char == ">"
end) :: string
end

stream:trim()
stream:advance() -- skip '='
stream:trim()

local bracketScope = 0

while true do
definition ..= stream:advanceUntil(function(char)
if char == "<" or char == "{" then
bracketScope += 1
end

if char == ">" or char == "}" then
bracketScope -= 1
end

return char == "\n"
end) :: string

if bracketScope > 0 then
continue
end

stream:trim()

if stream:peek() == "|" or stream:peek() == '"' then
continue
end

break
end

fileContent = string.sub(fileContent, 1, cursor - 1) .. string.sub(fileContent, stream.cursorPosition, #fileContent)

for _, phrase in { "objects.", "apiTypes." } do
definition = string.gsub(definition, phrase, "")
end

table.insert(fileTypes, {
name = name,
generics = generics,
definition = definition,
})
end

local splitContent = string.split(fileContent, "\n")
local lastLineCount = 0

for index = #splitContent, 0, -1 do
lastLineCount += 1

if string.find(splitContent[index], "return {") then
break
end
end

for _, type in fileTypes do
table.insert(
splitContent,
#splitContent - lastLineCount + 1,
`export type {type.name}{type.generics or ""} = {type.definition}`
)
end

-- warn(table.concat(splitContent, "\n"))

fs.writeFile("bundled.luau", table.concat(splitContent, "\n"))
14 changes: 14 additions & 0 deletions packages/api-types/darklua.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"generator": "retain_lines",
"bundle": {
"require_mode": {
"name": "path",
"module_folder_name": "init",
"sources": {}
},
"modules_identifier": "__DARKLUA_BUNDLE_MODULES",
"excludes": [
"@lune/**"
]
}
}
Loading

0 comments on commit 80ece98

Please sign in to comment.