Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thinknathan/tstl-export-to-global
TypeScriptToLua plugin that transforms all exported variables to global declarations
https://github.com/thinknathan/tstl-export-to-global
lua tstl tstl-extension tstl-plugin typescript
Last synced: 6 days ago
JSON representation
TypeScriptToLua plugin that transforms all exported variables to global declarations
- Host: GitHub
- URL: https://github.com/thinknathan/tstl-export-to-global
- Owner: thinknathan
- License: cc0-1.0
- Created: 2024-01-07T03:33:30.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-10-01T23:23:22.000Z (about 1 month ago)
- Last Synced: 2024-10-02T11:07:44.864Z (about 1 month ago)
- Topics: lua, tstl, tstl-extension, tstl-plugin, typescript
- Language: TypeScript
- Homepage:
- Size: 894 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tstl-export-to-global
[![CI](https://github.com/thinknathan/tstl-export-to-global/actions/workflows/ci.yml/badge.svg)](https://github.com/thinknathan/tstl-export-to-global/actions/workflows/ci.yml) ![GitHub License](https://img.shields.io/github/license/thinknathan/tstl-export-to-global)
TypeScriptToLua plugin that transforms all exported variables in a given file to global declarations.
Can be used as an alternative to [tstl-export-as-global](https://github.com/ts-defold/tstl-export-as-global). The benefits from switching to this plugin are as follows:
1. Saves allocating one table
2. Allows you to use `export const FOO = function()` instead of `export function FOO()` if you prefer that syntax
3. All variables are transformed, not just functions:exclamation: Use this and any code transformation plugin with caution. Mistakes are possible.
## Example
```lua
local ____exports = {}
____exports.foo = 10
____exports.bar = function(self)
...
end
return ____exports
```Becomes:
```lua
foo = 10
function bar(self)
...
end
```## Installation
Requires TSTL >= 1.22.0.
1. Install this plugin
```bash
yarn add tstl-export-to-global -D
# or
npm install tstl-export-to-global --save-dev
```2. Add `tstl-export-to-global` to `tstl.luaPlugins` in `tsconfig.json`
3. Define `match`, which will only apply the transformation to files if their _input_ (TypeScript file) path matches.
```diff
{
"tstl": {
"luaPlugins": [
+ {
+ "name": "tstl-export-to-global",
+ "match": ".*\\..*script.ts$"
+ }
],
}
}
```## License
CC0