Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeakAurasAPI #5216

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/scripts/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
doc.json
output.json
doc.md
*.log
*utf8*
128 changes: 128 additions & 0 deletions .github/scripts/docs/parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
const fs = require('fs');
const path = require('path');
const namespace = "WeakAuras"

console.log(
`if not WeakAuras.IsLibsOK() then return end
---@type string
local AddonName = ...
---@class OptionsPrivate
local OptionsPrivate = select(2, ...)
local WeakAurasAPI =
{
Name = "WeakAuras",
Type = "System",
Namespace = "WeakAuras",
Functions =
{`
)

function isNilable(obj) {
return obj.view.match("nil|\\?") ? "true" : "false"
}

function wowType(obj) {
if (obj.view.match("string")) {
return "string";
}
if (obj.view.match("boolean")) {
return "bool";
}
if (obj.view.match("integer|number")) {
return "number";
}
if (obj.view === "unknown|nil") {
return "unknown"
}
if (obj.view === "(\"friendly\"|\"hostile\")?") { // I don't know how to handle this alias properly
return "string"
}
return obj.view;
}

const data = fs.readFileSync(path.join(__dirname, 'doc.json'), { encoding: 'utf8', flags: 'r' });
const obj = JSON.parse(data);
const allFunctions = new Object;
for (const entry of obj) {
if (entry.name === namespace) {
if (entry.fields) {
for (const field of entry.fields) {
if (field?.extends?.type === "function" && field?.visible === "public") {
const currFunction = new Object;
const args = field?.extends?.args
if (args && args.length > 0) {
currFunction.arguments = new Array;
for (const arg of args) {
currFunction.arguments.push({ name: arg.name, type: wowType(arg), nilable: isNilable(arg)});
};
}
const returns = field?.extends?.returns
if (returns && returns.length > 0) {
currFunction.returns = new Array;
for (const ret of returns) {
currFunction.returns.push({ name: ret.name, type: wowType(ret), nilable: isNilable(ret)})
};
}
// if there is already a function with this name, we check if the new has more args or returns
if (allFunctions[field.name]) {
const currArgs = currFunction.args ? currFunction.args.length : 0
const oldArgs = allFunctions[field.name].args ? allFunctions[field.name].length : 0
const currRets = currFunction.returns ? currFunction.returns.length : 0
const oldRets = allFunctions[field.name].returns ? allFunctions[field.name].returns.length : 0
if (currArgs > oldArgs || currRets > oldRets) {
allFunctions[field.name] = currFunction
}
} else {
allFunctions[field.name] = currFunction
}
}
};
}
}
}

for (var key in allFunctions) {
const currFunction = allFunctions[key]
console.log(` {`);
console.log(` Name = "${key}",`);
console.log(` Type = "Function",`);
if (currFunction.arguments) {
console.log("");
console.log(` Arguments =`);
console.log(` {`);
for (const arg of currFunction.arguments) {
console.log(` { Name = "${arg.name}", Type = "${arg.type}", Nilable = ${arg.nilable} },`);
};
console.log(` },`);
}
if (currFunction.returns) {
console.log("");
console.log(` Returns =`);
console.log(` {`);
for (const ret of currFunction.returns) {
console.log(` { Name = "${ret.name}", Type = "${ret.type}", Nilable = ${ret.nilable} },`);
};
console.log(` },`);
}
console.log(` },`);
}

console.log(
`
},
Events =
{
},
Tables =
{
},
};
local loaded = false
function OptionsPrivate.LoadDocumentation()
if not loaded then
APIDocumentation:AddDocumentationTable(WeakAurasAPI);
loaded = true
end
end
`
);
7 changes: 7 additions & 0 deletions .github/scripts/docs/update-documentation-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

lua-language-server --doc="." --doc_out_path=".github/scripts/docs" --logpath=".github/scripts/docs" --metapath=".github/scripts/docs"

# jq '[.[] | select(.name | index("WeakAuras") != -1)]' doc.json > output.json

node .github/scripts/docs/parser.js > WeakAurasOptions/WeakAurasAPI.lua
2 changes: 1 addition & 1 deletion .github/workflows/atlas-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

jobs:
atlasUpdate:
atlas-update:
if: github.repository == 'WeakAuras/WeakAuras2'
runs-on: ubuntu-latest
steps:
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/documentation-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Regenerate Type Definitions

on:
push:
branches:
- main
pull_request_target:

jobs:
type-definitions-update:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout WeakAuras
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Install LuaLS
run: |
brew install lua-language-server
- name: Regenerate Type Definitions
run: |
./.github/scripts/docs/update-documentation-files.sh
shell: bash

- name: Push Changes to PR
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update generated types from ${GITHUB_SHA:0:7}"
2 changes: 1 addition & 1 deletion .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [opened, edited]

jobs:
auto_close_issues:
auto-close-issues:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/modelpaths-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

jobs:
modelPathsUpdate:
modelpaths-update:
if: github.repository == 'WeakAuras/WeakAuras2'
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_notifications.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Send Release Notifications

# See https://github.com/WeakAuras/WeakAuras2/wiki/%5BTEAM-INTERNAL%5D-Setting-up-Release-Notification-Hooks

on:
workflow_dispatch:
release:
types: [published]

jobs:
release-notification-output:
Expand Down
123 changes: 0 additions & 123 deletions .github/workflows/release_notifications_manual_tests.yml

This file was deleted.

Loading