This is a simple template for a Crankscript library project.
Install dependencies:
npm install
To generate a .d.ts and a Lua file:
npm run transpile
When you transpile your library, Crankscript will generate both index.lua
and index.d.ts
inside the Source
directory. This allows your library to be:
- Used via npm in CrankScript projects (with full TypeScript types)
- Imported in Toybox projects with zero setup
Toybox support is enabled by default via the --toybox
flag:
This will generate a Toybox-compatible Source/import.lua
, which:
- Automatically exposes your exports under a global table (
MyLib
) - Can be imported and used by others:
import "toyboxes"
MyLib.someFunction()
- Make sure to commit the
Source/import.lua
file - Your library will be usable from Toybox with:
toybox add github-username/repository-name
To disable Toybox support, remove the --toybox
option in your package.json
.