Created tools.func (markdown)
parent
a1cef579be
commit
9efbf95c36
48
tools.func.md
Normal file
48
tools.func.md
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# This page describes all helper functions defined in `misc/tools.func`
|
||||||
|
|
||||||
|
## `install_node_and_modules` Bash Function
|
||||||
|
|
||||||
|
This function automates the installation of a specified version of Node.js and a list of global Node modules on a Debian-based system. It ensures the desired Node.js version is installed (replacing any existing version if necessary) and installs or updates specified Node.js global modules.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🧰 Function Description
|
||||||
|
|
||||||
|
`install_node_and_modules()`:
|
||||||
|
|
||||||
|
- Checks if Node.js is installed.
|
||||||
|
- If Node.js is installed but not the desired version, it replaces it.
|
||||||
|
- If Node.js is not installed, it installs the specified version using the NodeSource APT repository.
|
||||||
|
- It can also install or update a list of global Node modules.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🚀 How to Use/Example
|
||||||
|
|
||||||
|
```bash
|
||||||
|
install_node_and_modules
|
||||||
|
```
|
||||||
|
to install the latest version of Node.js with no additional Modules.
|
||||||
|
If you want to define a specified Version and install Modules use something like this:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NODE_VERSION=20 NODE_MODULE="yarn@latest,@vue/cli-service@5.0.0" install_node_and_modules
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🧩 User-Configurable Variables
|
||||||
|
|
||||||
|
| Variable | Description | Default Value |
|
||||||
|
|----------------|----------------------------------------------------------------------------------------------------------------|---------------|
|
||||||
|
| `NODE_VERSION` | Specifies the major version of Node.js to install (e.g., `20`, `22`). | `22` |
|
||||||
|
| `NODE_MODULE` | Comma-separated list of global npm modules to install or update. <br>Examples: <br>• `yarn@latest` <br>• `@vue/cli-service@5.0.0` <br>• `typescript` | *(empty)* |
|
||||||
|
|
||||||
|
|
||||||
|
### 🔧 Notes
|
||||||
|
|
||||||
|
Global npm packages are only processed if NODE_MODULE is set.
|
||||||
|
If the requested module version is already installed, it is skipped.
|
||||||
|
Modules are updated if the installed version does not match the requested one (unless latest is used).
|
||||||
|
On failure, the script exits with exit 1.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user