generated from array-in-a-matrix/matrix-bot-template
rewrite
This commit is contained in:
parent
e30cdb6385
commit
7f7c17b104
91
README.md
91
README.md
|
@ -2,37 +2,88 @@
|
|||
|
||||
Nim wrapper for the [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk).
|
||||
|
||||
## Setup
|
||||
|
||||
Make sure you have [Nim](https://nim-lang.org/install.html) and [Node.js](https://nodejs.org/) installed before starting your own project or to contribute.
|
||||
|
||||
The library needs the [Matrix Bot SDK](https://github.com/turt2live/matrix-bot-sdk) JavaScript module:
|
||||
|
||||
```sh
|
||||
pnpm add matrix-bot-sdk
|
||||
```
|
||||
This library aims to take TypeScript functions, classes and whatever else that is needed from the [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk) and expose them to Nim code with a JavaScript target.
|
||||
|
||||
## Development
|
||||
|
||||
Nim files inside `nimbotsdk/` are named after the file they wrap (`MatrixAuth.nim` is a wrapper to `MatrixAuth.d.ts`). `matrixTypes.nim` defines the object types used throughout the entire library.
|
||||
Nim files inside `src/nimbotsdk/` are named after the original TypeScript file they wrap (`MatrixAuth.nim` warps `MatrixAuth.d.ts`). `matrixTypes.nim` defines the object types used throughout the entire library.
|
||||
|
||||
Procedures that have been tested to work are imported into `nimbotsdk.nim` in the root of the project.
|
||||
### Development Setup
|
||||
|
||||
To start developing, make sure you have the needed dependencies installed:
|
||||
|
||||
- [Nim](https://nim-lang.org/)
|
||||
- Nimble (comes with Nim compiler)
|
||||
- [Node.js](https://nodejs.org/)
|
||||
- NPM package manager ([pnpm](https://pnpm.io/), [yarn](https://yarnpkg.com/), [npm](https://www.npmjs.com/), etc.)
|
||||
- [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk)
|
||||
|
||||
Clone the repository and download the SDK:
|
||||
|
||||
```sh
|
||||
git clone https://git.inamatrix.xyz/array-in-a-matrix/nimbotsdk
|
||||
cd nimbotsdk/src/ && pnpm install
|
||||
|
||||
```
|
||||
|
||||
### Tests
|
||||
|
||||
Procedures that have been tested to work are imported into `src/nimbotsdk.nim`.
|
||||
|
||||
Run tests:
|
||||
|
||||
```sh
|
||||
nimble test
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
To use the library in your Nim program, import `nimbotsdk.nim` from the root of the repository. To import a specific module without importing the whole library, you can import `matrixTypes.nim` and the needed module(s) from `nimbotsdk/`.
|
||||
### Project Setup
|
||||
|
||||
There are code examples inside the `examples/` directory.
|
||||
You will need the following installed:
|
||||
|
||||
Make sure the homeserver URL and token (or username and password) are valid then you can compile and run code:
|
||||
- [Nim](https://nim-lang.org/)
|
||||
- Nimble (comes with Nim compiler)
|
||||
- [Node.js](https://nodejs.org/)
|
||||
- NPM package manager ([pnpm](https://pnpm.io/), [yarn](https://yarnpkg.com/), [npm](https://www.npmjs.com/), etc.)
|
||||
- [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk)
|
||||
|
||||
You can install this library using `nimble`:
|
||||
|
||||
```sh
|
||||
nimble install https://git.inamatrix.xyz/array-in-a-matrix/nimbotsdk
|
||||
```
|
||||
|
||||
Now you will be able to import and use it in your Nim code:
|
||||
|
||||
```nim
|
||||
# imports everything
|
||||
import nimbotsdk
|
||||
|
||||
# imports only select modules
|
||||
import nimbotsdk/[matrixTypes, MatrixClient]
|
||||
|
||||
```
|
||||
|
||||
You can compile your Nim code without downloading the NPM module but it will not work. To deal with this, download the [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk) if you haven't already:
|
||||
|
||||
```sh
|
||||
# If using pnpm
|
||||
pnpm add matrix-bot-sdk
|
||||
|
||||
#If using yarn
|
||||
yarn add matrix-bot-sdk
|
||||
|
||||
#If using npm
|
||||
npm install matrix-bot-sdk
|
||||
```
|
||||
|
||||
Now you can run your compiled Nim code or compile and run directly:
|
||||
|
||||
```sh
|
||||
nim js printToken.nim && node printToken.js
|
||||
|
||||
nim js -r printToken.nim
|
||||
```
|
||||
|
||||
You can inspect the produced JavaScript this way if you want:
|
||||
|
||||
```sh
|
||||
nim js printToken.nim
|
||||
node printToken.js
|
||||
```
|
||||
There are code examples inside the `examples/` directory.
|
||||
|
|
Loading…
Reference in a new issue