mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Make nodejs helpers easier to use
This commit is contained in:
parent
08f9091257
commit
4c5f280aef
1 changed files with 44 additions and 8 deletions
|
@ -28,14 +28,37 @@ SOURCE_SUM=3983fa3f00d4bf85ba8e21f1a590f6e28938093abe0bb950aeea52b1717471fc" > "
|
|||
# Load the version of node for an app, and set variables.
|
||||
#
|
||||
# ynh_use_nodejs has to be used in any app scripts before using node for the first time.
|
||||
# This helper will provide alias and variables to use in your scripts.
|
||||
#
|
||||
# 2 variables are available:
|
||||
# - $nodejs_path: The absolute path of node for the chosen version.
|
||||
# To use npm or node, use the alias `ynh_npm` and `ynh_node`
|
||||
# Those alias will use the correct version installed for the app
|
||||
# For example: use `ynh_npm install` instead of `npm install`
|
||||
#
|
||||
# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_npm` and `$ynh_node`
|
||||
# Exemple: `ynh_exec_as $app $ynh_npm install`
|
||||
#
|
||||
# $PATH contains the path of the requested version of node.
|
||||
# However, $PATH is duplicated into $node_PATH to outlast any manipulation of $PATH
|
||||
# You can use the variable `$ynh_node_load_PATH` to quickly load your node version
|
||||
# in $PATH for an usage into a separate script.
|
||||
# Exemple: $ynh_node_load_PATH $final_path/script_that_use_npm.sh`
|
||||
#
|
||||
#
|
||||
# Finally, to start a nodejs service with the correct version, 2 solutions
|
||||
# Either the app is dependent of node or npm, but does not called it directly.
|
||||
# In such situation, you need to load PATH
|
||||
# `Environment="__NODE_ENV_PATH__"`
|
||||
# `ExecStart=__FINALPATH__/my_app`
|
||||
# You will replace __NODE_ENV_PATH__ with $ynh_node_load_PATH
|
||||
#
|
||||
# Or node start the app directly, then you don't need to load the PATH variable
|
||||
# `ExecStart=__YNH_NODE__ my_app run`
|
||||
# You will replace __YNH_NODE__ with $ynh_node
|
||||
#
|
||||
#
|
||||
# 2 other variables are also available
|
||||
# - $nodejs_path: The absolute path to node binaries for the chosen version.
|
||||
# - $nodejs_version: Just the version number of node for this app. Stored as 'nodejs_version' in settings.yml.
|
||||
# And 2 alias stored in variables:
|
||||
# - $nodejs_use_version: An old variable, not used anymore. Keep here to not break old apps
|
||||
# NB: $PATH will contain the path to node, it has to be propagated to any other shell which needs to use it.
|
||||
# That's means it has to be added to any systemd script.
|
||||
#
|
||||
# usage: ynh_use_nodejs
|
||||
#
|
||||
|
@ -43,13 +66,24 @@ SOURCE_SUM=3983fa3f00d4bf85ba8e21f1a590f6e28938093abe0bb950aeea52b1717471fc" > "
|
|||
ynh_use_nodejs () {
|
||||
nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version)
|
||||
|
||||
nodejs_use_version="echo \"Deprecated command, should be removed\""
|
||||
|
||||
# Get the absolute path of this version of node
|
||||
nodejs_path="$node_version_path/$nodejs_version/bin"
|
||||
|
||||
# Allow alias to be used into bash script
|
||||
shopt -s expand_aliases
|
||||
|
||||
# Create an alias for the specific version of node and a variable as fallback
|
||||
ynh_node="$nodejs_path/node"
|
||||
alias ynh_node="$ynh_node"
|
||||
# And npm
|
||||
ynh_npm="$nodejs_path/npm"
|
||||
alias ynh_npm="$ynh_npm"
|
||||
|
||||
# Load the path of this version of node in $PATH
|
||||
[[ :$PATH: == *":$nodejs_path"* ]] || PATH="$nodejs_path:$PATH"
|
||||
node_PATH="$PATH"
|
||||
# Create an alias to easily load the PATH
|
||||
ynh_node_load_PATH="PATH=$node_PATH"
|
||||
}
|
||||
|
||||
# Install a specific version of nodejs
|
||||
|
@ -62,6 +96,8 @@ ynh_use_nodejs () {
|
|||
# usage: ynh_install_nodejs --nodejs_version=nodejs_version
|
||||
# | arg: -n, --nodejs_version - Version of node to install. When possible, your should prefer to use major version number (e.g. 8 instead of 8.10.0). The crontab will then handle the update of minor versions when needed.
|
||||
#
|
||||
# Refer to ynh_use_nodejs for more information about available commands and variables
|
||||
#
|
||||
# Requires YunoHost version 2.7.12 or higher.
|
||||
ynh_install_nodejs () {
|
||||
# Use n, https://github.com/tj/n to manage the nodejs versions
|
||||
|
|
Loading…
Add table
Reference in a new issue