Skip to content

Commit c5c3c2e

Browse files
committed
Initial Release
0 parents  commit c5c3c2e

24 files changed

+2818
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# System
2+
.DS_Store
3+
Thumbs.db
4+
5+
# Temporary
6+
/doc
7+
info.json
8+
ref-doc.zip
9+
json_list.txt
10+
11+
# Generated
12+
/api
13+
lock
14+
/node_modules
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"license": {
3+
"prefix": "license",
4+
"description": "license",
5+
"scope": "typescript",
6+
"body": [
7+
"/*[[",
8+
" ${1}.ts",
9+
" https://github.com/elMuso/defold-annotations-typescript",
10+
" with some code from on github.com/astrochili/defold-annotations",
11+
" Copyright (c) 2024 elMuso",
12+
" MIT license. See LICENSE for details.",
13+
" --*/"
14+
]
15+
}
16+
}

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"tomblind.local-lua-debugger-vscode"
4+
]
5+
}

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug Lua Interpreter",
6+
"type": "lua-local",
7+
"request": "launch",
8+
"program": {
9+
"lua": "lua",
10+
"file": "main.lua"
11+
}
12+
}
13+
]
14+
}

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Lua.diagnostics.disable": [
3+
"redefined-local"
4+
]
5+
}

.vscode/tasks.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"tasks": [
3+
{
4+
"label": "run_program",
5+
"type": "shell",
6+
"command": "npm run start",
7+
},
8+
]
9+
}

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Roman Silin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Defold Annotations for Typescript
2+
3+
Hugely based around the idea of [Defold annotations](https://github.com/astrochili/defold-annotations/), this repository aims to be the same, for typescript, but better.
4+
5+
It parses the official documentation from [Defold](https://defold.com) and translates it to 2 typescript definition files.
6+
7+
Node 20.15.1 was used for this. Might not run with other versions
8+
9+
<!-- Generated annotations are available on the [Releases](https://github.com/astrochili/defold-annotations/releases) page. -->
10+
11+
## Use case
12+
13+
These annotations can be used by anyone just by dragging the file to your project
14+
15+
- index.d.ts contains the Defold API, constants and functions
16+
- messages.d.ts contains a useful `dfld` object that can serve as a helper to avoid sending messages (prefix msg*) or to look up the documentation of something. It also contains the propertyes of each module (prefix p*) and the return messages to use on on*message (prefix msg_id*)
17+
18+
## Manual Generation
19+
20+
Install Node, run `npm install` and then `npm run start`. **_The output will be on the api folder_**
21+
22+
### Issues
23+
24+
If you find a typo in the annotations or outdated meta information, create an issue.
25+
26+
### Settings
27+
28+
By default it uses Defold version 1.9.1 , you can change this by editing the src_new/settings.ts file. There are other useful conditionals there to remove information from the final build

eslint.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
5+
6+
export default [
7+
{
8+
rules: {
9+
"@typescript-eslint/explicit-function-return-type": "error"
10+
}
11+
},
12+
{files: ["**/*.{js,mjs,cjs,ts}"]},
13+
{languageOptions: { globals: globals.browser }},
14+
pluginJs.configs.recommended,
15+
...tseslint.configs.recommended,
16+
];

main.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import config from "./src_new/config";
2+
import fetch_docs from "./src_new/fetcher";
3+
import { Generator } from "./src_new/generator";
4+
import { Parser } from "./src_new/parser";
5+
import settings from "./src_new/settings";
6+
import { Terminal } from "./src_new/terminal";
7+
import Utils from "./src_new/utils";
8+
9+
// Parse .json files to namespace modules
10+
// const modules = parser.parse_json(json_paths)
11+
12+
async function generate_documentation() {
13+
const json_paths = await fetch_docs(settings.defold_version);
14+
const api_path = config.api_folder + settings.folder_separator;
15+
const modules = Parser.parse_json(json_paths);
16+
const filtered = Parser.filter_json(modules);
17+
Terminal.create_folder(api_path);
18+
Utils.save_file(JSON.stringify(filtered), api_path + "raw_data.json");
19+
const output = Generator.generate(filtered);
20+
Utils.save_file(output.typedata, api_path + "index.d.ts");
21+
Utils.save_file(output.optionaldata, api_path + "messages.d.ts");
22+
console.log("Parsing done. Check the api folder");
23+
}
24+
25+
generate_documentation();

0 commit comments

Comments
 (0)