feat: add cli commands to help with setup #29

Merged
Ghost merged 0 commits from refs/pull/29/head into main 2025-10-29 21:24:04 +00:00
Ghost commented 2025-10-29 21:22:46 +00:00 (Migrated from codeberg.org)

This work started small but slowly went a bit out of control. Excuse the huge diff. ^-^'

CLI

I want the project to be as simple to set up as possible (or at least as practical). I've added common CLI libraries in the Node.js ecosystem like commander, @inquirer, and yocto-spinner to offer a fairly modern experience.

All commands that use them allow input to be specified through arguments or interactively. If arguments are specified, it disabled all interaction for that input, including any validation or fluff. I opted to treat it so that:

Arguments Interactive
Advanced / I know what I'm doing mode. Guided / Please hold my hand mode.

This isn't a conventional rule. It's just my way of trying to offer a positive UX, while also having a way to use it that stays out of your way.

I introduce four commands:

Command Description
init Write a dummy/template config file out to config.yml or where the user specified for the user to fill out.
bot-token Get a Matrix access token from username and password. We refer to it as "bot token" to be explicit we mean for the Matrix bot, and this term may be familiar to those from Discord.
twitch-id Get the Twitch ID of a streamer from their display name. Our config only accepts Twitch user IDs, so the user needs to convert it.
run Actually run the bot once the server is all configured.

I'm tempted to make a "test" feature as well, which will just try to do a bit of everything and report back any issues. For example, could it login, can it post messages, can it receive payloads from Twitch, etc. But I have not made this yet.

The init command is the only one that writes directly to a file. The rest provide information to the user to insert into their file manually. I'll reconsider this later, but it seems annoying to edit their config file while ensuring we maintain formatting and comments. This is probably possible if we use a YAML library that exposes tokens rather than a POJO.

Config

  • The default value for lang is now process.env.LANG. So the system language. This can easily be overridden by the user of course.
  • Replace the default value for matrix.homeserverUrl for https://matrix.org. I don't recall where I got the original value from, but matrix.org achieves the same thing and is more widely known.

Docs

  • Formats the config in the README to be more verbose about and easier to read. (With feedback from @JenTheBluePanda.)

CI

  • Adds a coverage task which will report code coverage to GitLab so we can put the badge at the top. We'll work on fleshing out more tests.

Node.js v24

Upgrades to Node.js v24 so that I can use t.mock.property which is only available from Node.js v24.3.0 onwards.

Given this is a standalone application and has had no official releases, I see no problem with requiring a very recent version. The production run should still work with v22, but for convenience we'll only support v24 on onwards anyway.

Chores

  • Cleans up the .gitignore file. I used to just inline one from github.com/github/gitignore, but it contains too much noise. I'll still start from the GitHub one, but will clear things out that are not relevant to the project.
  • Add linting rule to enforce that stdlib modules must be prefixed with node:.
  • Adds more tests.
This work started small but slowly went a bit out of control. Excuse the huge diff. ^-^' ## CLI I want the project to be as simple to set up as possible (or at least as practical). I've added common CLI libraries in the Node.js ecosystem like `commander`, `@inquirer`, and `yocto-spinner` to offer a fairly modern experience. All commands that use them allow input to be specified through arguments or interactively. If arguments are specified, it disabled all interaction for that input, including any validation or fluff. I opted to treat it so that: | Arguments | Interactive | |---|---| | Advanced / I know what I'm doing mode. | Guided / Please hold my hand mode. | This isn't a conventional rule. It's just my way of trying to offer a positive UX, while also having a way to use it that stays out of your way. I introduce four commands: | Command | Description | |---|---| | `init` | Write a dummy/template config file out to `config.yml` or where the user specified for the user to fill out. | | `bot-token` | Get a Matrix access token from username and password. We refer to it as "bot token" to be explicit we mean for the Matrix bot, and this term may be familiar to those from Discord. | | `twitch-id` | Get the Twitch ID of a streamer from their display name. Our config only accepts Twitch user IDs, so the user needs to convert it. | | `run` | Actually run the bot once the server is all configured. | I'm tempted to make a "test" feature as well, which will just try to do a bit of everything and report back any issues. For example, could it login, can it post messages, can it receive payloads from Twitch, etc. But I have not made this yet. The `init` command is the only one that writes directly to a file. The rest provide information to the user to insert into their file manually. I'll reconsider this later, but it seems annoying to edit their config file while ensuring we maintain formatting and comments. This is probably possible if we use a YAML library that exposes tokens rather than a POJO. ## Config * The default value for `lang` is now `process.env.LANG`. So the system language. This can easily be overridden by the user of course. * Replace the default value for `matrix.homeserverUrl` for `https://matrix.org`. I don't recall where I got the original value from, but `matrix.org` achieves the same thing and is more widely known. ## Docs * Formats the config in the README to be more verbose about and easier to read. (With feedback from @JenTheBluePanda.) ## CI * Adds a `coverage` task which will report code coverage to GitLab so we can put the badge at the top. We'll work on fleshing out more tests. ## Node.js v24 Upgrades to Node.js v24 so that I can use [`t.mock.property`](https://nodejs.org/api/test.html#mockpropertyobject-propertyname-value) which is only available from Node.js v24.3.0 onwards. Given this is a standalone application and has had no official releases, I see no problem with requiring a very recent version. The production run should still work with v22, but for convenience we'll only support v24 on onwards anyway. ## Chores * Cleans up the `.gitignore` file. I used to just inline one from [github.com/github/gitignore](https://github.com/github/gitignore), but it contains too much noise. I'll still start from the GitHub one, but will clear things out that are not relevant to the project. * Add linting rule to enforce that stdlib modules must be prefixed with `node:`. * Adds more tests. ## Related * Closes https://gitlab.com/SethFalco/matrix-stream-alerts/-/issues/7
Ghost commented 2025-10-29 21:24:06 +00:00 (Migrated from codeberg.org)

mentioned in commit 60efa172c2

mentioned in commit 60efa172c2898c5a2df7ee63fb63e6f4598712ec
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
SethFalco/matrix-stream-alerts!29
No description provided.