Rename `node-js-nvm` to `nodejs` and apply review

pull/165/head
FlorianGareis 1 year ago
parent 4a6f6bfe38
commit 8e9bc4ec71
No known key found for this signature in database

@ -1,19 +1,19 @@
--- ---
display_name: node-via-nvm display_name: nodejs
description: Install node via nvm description: Install Node.js via nvm
icon: ../.icons/node.svg icon: ../.icons/node.svg
maintainer_github: coder maintainer_github: TheZoker
verified: true verified: true
tags: [helper] tags: [helper]
--- ---
# node-via-nvm # nodejs
Automatically installs the latest version of [node](https://github.com/nodejs/node) versions via [nvm](https://github.com/nvm-sh/nvm). It can also install multiple versions of node and set a default version. Automatically installs [Node.js](https://github.com/nodejs/node) via [nvm](https://github.com/nvm-sh/nvm). It can also install multiple versions of node and set a default version. If no options are specified, the latest version is installed.
```tf ```tf
module "node-via-nvm" { module "nodejs" {
source = "registry.coder.com/modules/node-via-nvm/coder" source = "registry.coder.com/modules/nodejs/coder"
version = "1.0.2" version = "1.0.2"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
} }
@ -21,11 +21,11 @@ module "node-via-nvm" {
### Install multiple versions ### Install multiple versions
This installs multiple versions of node This installs multiple versions of Node.js:
```tf ```tf
module "node-via-nvm" { module "nodejs" {
source = "registry.coder.com/modules/node-via-nvm/coder" source = "registry.coder.com/modules/nodejs/coder"
version = "1.0.2" version = "1.0.2"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
node_versions = [ node_versions = [
@ -42,8 +42,8 @@ module "node-via-nvm" {
A example with all available options: A example with all available options:
```tf ```tf
module "node-via-nvm" { module "nodejs" {
source = "registry.coder.com/modules/node-via-nvm/coder" source = "registry.coder.com/modules/nodejs/coder"
version = "1.0.2" version = "1.0.2"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
nvm_version = "v0.39.7" nvm_version = "v0.39.7"

@ -1,7 +1,7 @@
import { describe, expect, it } from "bun:test"; import { describe, expect, it } from "bun:test";
import { runTerraformInit, testRequiredVariables } from "../test"; import { runTerraformInit, testRequiredVariables } from "../test";
describe("node-via-nvm", async () => { describe("nodejs", async () => {
await runTerraformInit(import.meta.dir); await runTerraformInit(import.meta.dir);
testRequiredVariables(import.meta.dir, { testRequiredVariables(import.meta.dir, {

@ -28,19 +28,19 @@ variable "nvm_install_prefix" {
variable "node_versions" { variable "node_versions" {
type = list(string) type = list(string)
description = "A list of node versions to install." description = "A list of Node.js versions to install."
default = ["node"] default = ["node"]
} }
variable "default_node_version" { variable "default_node_version" {
type = string type = string
description = "The default node version" description = "The default Node.js version"
default = "node" default = "node"
} }
resource "coder_script" "node" { resource "coder_script" "nodejs" {
agent_id = var.agent_id agent_id = var.agent_id
display_name = "node-via-nvm" display_name = "Node.js:"
script = templatefile("${path.module}/run.sh", { script = templatefile("${path.module}/run.sh", {
NVM_VERSION : var.nvm_version, NVM_VERSION : var.nvm_version,
INSTALL_PREFIX : var.nvm_install_prefix, INSTALL_PREFIX : var.nvm_install_prefix,
@ -48,4 +48,5 @@ resource "coder_script" "node" {
DEFAULT : var.default_node_version, DEFAULT : var.default_node_version,
}) })
run_on_start = true run_on_start = true
start_blocks_login = true
} }

@ -1,23 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
NODE_VERSIONS=("${NODE_VERSIONS}") NVM_VERSION='${NVM_VERSION}'
NODE_VERSIONS='${NODE_VERSIONS}'
INSTALL_PREFIX='${INSTALL_PREFIX}'
DEFAULT='${DEFAULT}'
BOLD='\033[0;1m' BOLD='\033[0;1m'
CODE='\033[36;40;1m' CODE='\033[36;40;1m'
RESET='\033[0m' RESET='\033[0m'
printf "$${BOLD}Installing nvm!$${RESET}\n" printf "$${BOLD}Installing nvm!$${RESET}\n"
export NVM_DIR="${INSTALL_PREFIX}/nvm" export NVM_DIR="$${INSTALL_PREFIX}/nvm"
output=$(curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh | bash) output=$(curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/$${NVM_VERSION}/install.sh" | bash)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to install nvm: $output" echo "Failed to install nvm: $output"
exit 1 exit 1
fi fi
printf "🥳 nvm has been installed\n\n" printf "🥳 nvm has been installed\n\n"
# Set up nvm in the current shell session # Set up nvm for the rest of the script.
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
# Install each node version... # Install each node version...
IFS=',' read -r -a VERSIONLIST <<< "$${NODE_VERSIONS}" IFS=',' read -r -a VERSIONLIST <<< "$${NODE_VERSIONS}"
@ -26,7 +29,7 @@ for version in "$${VERSIONLIST[@]}"; do
continue continue
fi fi
printf "🛠️ Installing node version $${CODE}$version$${RESET}...\n" printf "🛠️ Installing node version $${CODE}$version$${RESET}...\n"
output=$(nvm install "$version") output=$(nvm install "$version" 2>&1)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to install version: $version: $output" echo "Failed to install version: $version: $output"
exit 1 exit 1
@ -35,6 +38,6 @@ done
# Set default if provided # Set default if provided
if [ -n "${DEFAULT}" ]; then if [ -n "${DEFAULT}" ]; then
printf "🛠️ Setting default node version $${CODE}$DEFAULT$${RESET}...\n" printf "🛠️ Setting default node version $${CODE}$${DEFAULT}$${RESET}...\n"
output=$(nvm alias default $DEFAULT) output=$(nvm alias default $DEFAULT 2>&1)
fi fi
Loading…
Cancel
Save