Skip to content

Conversation

@SnaveSutit
Copy link
Contributor

@SnaveSutit SnaveSutit commented Feb 6, 2025

A rewrite of the Blockbench CLI, making it more powerful, and easier to understand.

Notable Changes so Far

  • Switched to using the commander library for argument parsing.
  • Added --no-auto-update option: Prevents Blockbench from auto-updating.
  • Added --install-custom-plugins <paths...> option: Attempts to load the listed file paths or URLs as plugins on startup.
  • Added --install-plugins <ids...> option: Attempts to install the listed IDs from the official plugins repository on startup.
  • Added --clean-installed-plugins option: Removes all installed plugins before startup.
  • Added --open-dev-tools option: Opens the dev tools on startup.
  • Added -v, --version option: Prints the installed version of Blockbench, then exits.
  • Added --hidden option: Hides the main window.
  • Added app.terminal console instance: Logs output to the terminal Blockbench was launched from with a fancy prefix:
    [00/00/0000 00:00:00] [Blockbench] ...
  • Added Blockbench.log function: Alias of app.terminal.
  • Added Plugin.log function: Alias of Blockbench.log, but includes the plugin ID in the prefix:
    [00/00/0000 00:00:00] [Blockbench] <plugin-id> ...
  • Added optional environment variables that mirror the CLI arguments. Eg. BLOCKBENCH_USER_DATA for --userData.
  • Added a -h, -help CLI option:
    image

- Switched CLI parsing to `commander` library.
- Added `--no-auto-update` CLI option.
- Added `--with-plugin-files <paths...>` CLI option.
- Added `--with-plugin-urls <urls...>` CLI option.
- Added optional environment variables that mirror the CLI arguments.
It should *just* output the version, and exit. It was throwing a `CommandError` and printing a bunch of extra text we don't want.
This file might be moved to `blockbench-types` later?
Whether or not that happens will be up to @JannisX11
- Added `app.terminal`: A Console instance that always prints to the terminal Blockbench was launched from (console.log switches to the web console after the window opens).
- Added `Blockbench.log`: An alias of `app.terminal`.
- Added `Plugin.log`: An alias of `Blockbench.log` that adds a `<plugin-id>` prefix to the output.
- Added a help option to all commands: `-h, --help`.
- Improved error handling, and user feedback when CLI encounters unexpected or unknown arguments.
- Added `--open-dev-tools` option: Opens the chrome developer tools on startup.
@SnaveSutit SnaveSutit changed the base branch from master to next February 8, 2025 23:48
@SnaveSutit SnaveSutit changed the base branch from next to master February 8, 2025 23:49
@SnaveSutit SnaveSutit marked this pull request as ready for review February 8, 2025 23:51
- Added `--clean-installed-plugins` option: Removes all installed plugins before launching.
- Fixed `app.console` references in `plugin_loader.js`.
- Replaced `--with-plugin-files` and `--with-plugin-urls` options with `--install-custom-plugins`.
- Added `--install-plugins <ids...>` option.
- Replaced all (new) `process.exit()` calls with `app.exit()`.
- Fixed `Blockbench.log` referencing `app.console` instead of `app.terminal`.
-
Copy link
Contributor

@TheAfroOfDoom TheAfroOfDoom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ive had to migrate my map back from Smithed Summit work (haven't touched it since november, so ~4 months of afk), but i finally have time to check this out. i know i'm the main audience here so thank you </3

i tried using each CLI option and integrating it with my CI flow (the one that automates Animated Java's export process in Github Actions):

(i kept getting this error when opening dist/win-unpacked/Blockbench.exe through command prompt)
image

note: i had to update to AJ v1.6.4 (from v1.4.2) in order for my auto-exporter to run. it got some error that i don't think either of us care about given i can just easily update once i update my stuff to use these


  • clean-installed-plugins: according to the log appears to always run even when i don't specify the flag
  • no-auto-update: seems to work as intended 👍
  • install-custom-plugins: not immediately clear how to specify multiple plugins. comma-separated?

untested args:

  • open-dev-tools
  • install-plugins (probably useful and good to have as an alternative to install-custom-plugins, i just wont need it for my CI process/scripts since i want to tightly control plugin versions)
  • clean-installed-plugins (makes sense, don't think i have a real need for it currently though)
  • userData (would love some elaboration on this, i think i get what it's for but not sure)
  • hidden (i forgot, this one ill probably try using...maybe eventually)

@TheAfroOfDoom
Copy link
Contributor

also question: is there a significant increase in load time when installing AJ via URL from "clean Blockbench" vs the normal startup AJ needs to do when it's already in Blockbench's plugin list?

@SnaveSutit
Copy link
Contributor Author

Animated Java is the largest plugin ever made for Blockbench. It takes a while to download, then download all of it's required external assets.

I haven't noticed any abnormally long delay when testing the CLI URL installation with AJ

Copy link
Contributor

@TheAfroOfDoom TheAfroOfDoom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praying this gets merged

@JannisX11 JannisX11 changed the base branch from master to next May 20, 2025 20:43
@JannisX11
Copy link
Owner

I did a preliminary review of the feature now. Here are my notes.

Generally, let's try to integrate the features into Blockbench better so they work in context of the whole program.

  • Some changes to the code currently break the web app. All code inside ./js should be written to be compatible with both the desktop and web app (with some exceptions). For a feature like this, that means conditioning code on whether Blockbench is running in the desktop app, or using the desktop.js file which only gets loaded in this case.
  • The ./js folder is purely intended for renderer process code. Once the target branch has been changed to next, the cli.js file can be moved into the ./electron directory.
  • Since it's called from the renderer process, the expectations of the new log methods would be to print logs in the Chrome dev tools console. These should be renamed to something like logMainProcess, or have an argument that instructs them to log to the main process and default to the renderer process. It should be considered how this works in the web app.

@SnaveSutit
Copy link
Contributor Author

Ahh, all good points. I didn't even consider the web app.

How does one run the web app in dev mode?

@TheAfroOfDoom
Copy link
Contributor

does it make sense to support a cli in web mode?

@JannisX11
Copy link
Owner

JannisX11 commented May 23, 2025

How does one run the web app in dev mode?

Run npm run serve on the next branch.
On old branches, just launch the directory in your preferred local http server, like vercel/serve or xampp.

does it make sense to support a cli in web mode?

Well there is already support for some URL parameters, like opening a model or installing plugins. But it only makes sense for a limited set of arguments, and requires extra care and/or user confirmation because anyone can make anyone else open a link with those parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants