$ npm install -g ts2gamesparks
$ npm install --save-dev gamesparks-typings
Add to tsconfig.json
// tsconfig.json
{
"compilerOptions": {
...
"types": [
"gamesparks-typings"
],
}
}
$ mkdir src && cd src
$ ts2gs --init
These three files will be created:
- src/tsconfig.json
- src/rtScript/tsconfig.json
- src/rtModules/tsconfig.json
If you are not sure, please do not modify these files.
If the script does not import or export anything, the script will not be recognized as a module, and the variables in the script will exist in the global namespace.
In order to solve it, just add export { }
to the first line of the script.
modules/
and rtModules/
// src/modules/foo.ts
export function func() {
/* ... */
}
export const bar = "bar"
✅ Do it
import /* ... */ from "foo";
❌ Don't do it!
import /* ... */ from "./foo";
import /* ... */ from "../modules/foo";
When tsconfig.json under root directory
$ ts2gs
When tsconfig.json under ./src
$ cd src && ts2gs
https://github.com/johnsoncodehk/gamesparks-cloud-code-typescript-example