How do I pre-install plugins?
-
@julian Let's do it with
sed
:#!/bin/bash sed_json() { # Input stream: JSON content # Parameters: key # Returns: string or null value, full JSON if key not found, last occurrence of key # Requires: no two keys (including nested ones) shall be named alike the given key string_value_matcher='\([[:blank:]]*\(null\)\|[^"]*"\([^"]*\)"\)' cat | sed -n " # concat all lines within hold buffer 1h 1!H $ { g # replace buffer with string value of key within JSON s/^.*\"$1\"[[:blank:]]*:$string_value_matcher.*$/\\2\\3/ # print value p } " } nbb_version=$(sed_json version < package.json) echo -e "NodeBB version \033[1m$nbb_version\033[0m" i=0 packages=() url="https://packages.nodebb.org/api/v1/suggest?version=$nbb_version&package=" while [ "$1" ]; do package="nodebb-$1" version=$(curl -s "$url$package" | sed_json version) if [ "$version" == "null" ]; then echo -e "\033[31;1mNo suggested version of $package for NodeBB $nbb_version. Skipping.\033[0m" else packages[$i]="$package@$version" i=$(($i+1)) fi shift done if [ ${#packages[@]} -ge 1 ]; then echo "> npm install ${packages[@]}" npm install ${packages[@]} else echo "No package to be installed." exit 2 fi
-
Couldn't you just modify the package.json to include the plugins you want as a dependency?
-
Well yeah, but you can install the wrong version using the script too.
Under the hood, the ACP plugin installer just runs an
npm i
for the plugin you want, which installs the package in the node_modules folder.Npm uses the package.json file to figure out what to install as dependencies for the NodeBB platform, which get installed in the same folder. So when you run
npm i
in the NodeBB folder, it looks at the package.json file, and installs the dependencies. So, technically you can add whatever plugin you want as a dependency in the package.json folder (adding the appropriate version number that you know will work). At that point, you'd just have to go into the ACP and activate them.The only caveat is you'd have to mind what's happening to that root package.json file when you're updating, to avoid conflicts / losing your settings.
Addressing the original question, you can specify a specific version you want to install by specifying the version of a package you want, i.e.
"nodebb-plugin-imgbed": "0.2.1"
https://docs.npmjs.com/files/package.json @ "dependencies"
-
@BDHarrington7 I understand that but the script installs the specific version that's compatible with my nodebb based on the response from packages.nodebb.org/api/v1/suggest.
For example: https://packages.nodebb.org/api/v1/suggest?package=nodebb-plugin-composer-default&version=0.9.1
-
@BDHarrington7 said:
Under the hood, the ACP plugin installer just runs an
npm i
for the plugin you want, which installs the package in the node_modules folder.Under the hood NodeBB runs an
npm i package@version
with the version resolved via NBBPM (packages.nodebb.org). And this is exactly what @ferik wanted without the need of using the NodeBB web-interface.Well yeah, but you can install the wrong version using the script too.
True if you have listings within the package.json that are not compatible with the plugin authors suggestion.
But if you have such listings, you wouldn't call the script with this package in the first place since you already know which version you want to have installed.Addressing the original question, you can specify a specific version you want to install by specifying the version of a package you want, i.e.
"nodebb-plugin-imgbed": "0.2.1"
As @ferik already said this requires you to know the version of the package you want to use that is compatible with your version of NodeBB. And the original question is how to do this automatically. You might want to read the second sentence of the original question again
@ferik said:
I can
npm install them
but that requires me to know what exact version I need for that version of NodeBB. Is there a way to through the command line ask NodeBB to install the version of a plugin that works with it? -
@frissdiegurke Yup, you answered all my questions, thank you!
-
@frissdiegurke yeah I missed that "automatically" part
In my defense, I'd rather reduce the number of external dependencies, and knowing the versions compatible, could still make an installation reproducible without needing to depend on anything. Maybe I just like doing things the hard way, haha.
Still, kudos for that quick script! Wasn't trying to make it sound like wasted work.
-
Seriously, a down vote for admitting I missed something and lauding frissdiegurke's script?
-
Haha! True, those voting buttons are really tiny on mobile... @psychobunny
-
Just keeping you guys on your toes
Tbh a forum like this should be using the "Likes" plugin instead, flagging is enough for spam etc
-
@psychobunny There's just something with pressing the flagging button for some reason on bots, it feels... Rewarding.