From 8e9bc4ec711fdbaa52d676dad68cebd932416701 Mon Sep 17 00:00:00 2001 From: FlorianGareis Date: Fri, 1 Mar 2024 14:08:35 +0000 Subject: [PATCH] Rename `node-js-nvm` to `nodejs` and apply review --- {node-via-nvm => nodejs}/README.md | 24 ++++++++++++------------ {node-via-nvm => nodejs}/main.test.ts | 2 +- {node-via-nvm => nodejs}/main.tf | 9 +++++---- {node-via-nvm => nodejs}/run.sh | 19 +++++++++++-------- 4 files changed, 29 insertions(+), 25 deletions(-) rename {node-via-nvm => nodejs}/README.md (50%) rename {node-via-nvm => nodejs}/main.test.ts (87%) rename {node-via-nvm => nodejs}/main.tf (82%) rename {node-via-nvm => nodejs}/run.sh (55%) diff --git a/node-via-nvm/README.md b/nodejs/README.md similarity index 50% rename from node-via-nvm/README.md rename to nodejs/README.md index 62a0905..e95a51f 100644 --- a/node-via-nvm/README.md +++ b/nodejs/README.md @@ -1,19 +1,19 @@ --- -display_name: node-via-nvm -description: Install node via nvm +display_name: nodejs +description: Install Node.js via nvm icon: ../.icons/node.svg -maintainer_github: coder +maintainer_github: TheZoker verified: true 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 -module "node-via-nvm" { - source = "registry.coder.com/modules/node-via-nvm/coder" +module "nodejs" { + source = "registry.coder.com/modules/nodejs/coder" version = "1.0.2" agent_id = coder_agent.example.id } @@ -21,11 +21,11 @@ module "node-via-nvm" { ### Install multiple versions -This installs multiple versions of node +This installs multiple versions of Node.js: ```tf -module "node-via-nvm" { - source = "registry.coder.com/modules/node-via-nvm/coder" +module "nodejs" { + source = "registry.coder.com/modules/nodejs/coder" version = "1.0.2" agent_id = coder_agent.example.id node_versions = [ @@ -42,8 +42,8 @@ module "node-via-nvm" { A example with all available options: ```tf -module "node-via-nvm" { - source = "registry.coder.com/modules/node-via-nvm/coder" +module "nodejs" { + source = "registry.coder.com/modules/nodejs/coder" version = "1.0.2" agent_id = coder_agent.example.id nvm_version = "v0.39.7" diff --git a/node-via-nvm/main.test.ts b/nodejs/main.test.ts similarity index 87% rename from node-via-nvm/main.test.ts rename to nodejs/main.test.ts index b7b62a9..07fc7a5 100644 --- a/node-via-nvm/main.test.ts +++ b/nodejs/main.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "bun:test"; import { runTerraformInit, testRequiredVariables } from "../test"; -describe("node-via-nvm", async () => { +describe("nodejs", async () => { await runTerraformInit(import.meta.dir); testRequiredVariables(import.meta.dir, { diff --git a/node-via-nvm/main.tf b/nodejs/main.tf similarity index 82% rename from node-via-nvm/main.tf rename to nodejs/main.tf index 0b948d7..79d055a 100644 --- a/node-via-nvm/main.tf +++ b/nodejs/main.tf @@ -28,19 +28,19 @@ variable "nvm_install_prefix" { variable "node_versions" { type = list(string) - description = "A list of node versions to install." + description = "A list of Node.js versions to install." default = ["node"] } variable "default_node_version" { type = string - description = "The default node version" + description = "The default Node.js version" default = "node" } -resource "coder_script" "node" { +resource "coder_script" "nodejs" { agent_id = var.agent_id - display_name = "node-via-nvm" + display_name = "Node.js:" script = templatefile("${path.module}/run.sh", { NVM_VERSION : var.nvm_version, INSTALL_PREFIX : var.nvm_install_prefix, @@ -48,4 +48,5 @@ resource "coder_script" "node" { DEFAULT : var.default_node_version, }) run_on_start = true + start_blocks_login = true } diff --git a/node-via-nvm/run.sh b/nodejs/run.sh similarity index 55% rename from node-via-nvm/run.sh rename to nodejs/run.sh index 2664dd1..f9240f2 100755 --- a/node-via-nvm/run.sh +++ b/nodejs/run.sh @@ -1,23 +1,26 @@ #!/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' CODE='\033[36;40;1m' RESET='\033[0m' 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 echo "Failed to install nvm: $output" exit 1 fi printf "🥳 nvm has been installed\n\n" -# Set up nvm in the current shell session -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +# Set up nvm for the rest of the script. +[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # Install each node version... IFS=',' read -r -a VERSIONLIST <<< "$${NODE_VERSIONS}" @@ -26,7 +29,7 @@ for version in "$${VERSIONLIST[@]}"; do continue fi printf "🛠️ Installing node version $${CODE}$version$${RESET}...\n" - output=$(nvm install "$version") + output=$(nvm install "$version" 2>&1) if [ $? -ne 0 ]; then echo "Failed to install version: $version: $output" exit 1 @@ -35,6 +38,6 @@ done # Set default if provided if [ -n "${DEFAULT}" ]; then - printf "🛠️ Setting default node version $${CODE}$DEFAULT$${RESET}...\n" - output=$(nvm alias default $DEFAULT) + printf "🛠️ Setting default node version $${CODE}$${DEFAULT}$${RESET}...\n" + output=$(nvm alias default $DEFAULT 2>&1) fi