From f1a7ecd9537c0958f6f0358484926e367ea127de Mon Sep 17 00:00:00 2001 From: "Kosala (Nuwan) Perera" Date: Wed, 6 Mar 2024 01:11:48 -0500 Subject: [PATCH] refactor: create a local feature for deno (#24) this changeset is to refactor and clean up deno related configurations and settings to a local feature. - move deno to a local feature - move editor format settings to local feature - avoid clean up before restore --- .devcontainer/devcontainer.json | 23 ++-------- .../deno/devcontainer-feature.json | 46 +++++++++++++++++++ .devcontainer/local-features/deno/install.sh | 20 ++++++++ 3 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 .devcontainer/local-features/deno/devcontainer-feature.json create mode 100644 .devcontainer/local-features/deno/install.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f8750b4..c52d9a4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -18,10 +18,8 @@ "ghcr.io/devcontainers/features/docker-outside-of-docker:1": { "moby": false, "dockerDashComposeVersion": "v2" - } - }, - "containerEnv": { - "DENO_INSTALL": "/usr/local" + }, + "./local-features/deno": {} }, "remoteEnv": {}, // Configure tool-specific properties. @@ -33,7 +31,6 @@ // JavaScript "oven.bun-vscode", // TypeScript - "denoland.vscode-deno", "bierner.lit-html", "better-ts-errors.better-ts-errors", // Makefile @@ -52,17 +49,8 @@ "settings": { // Editor "editor.guides.bracketPairs": "active", + // Debug "debug.internalConsoleOptions": "neverOpen", - // Better linting & formatting - "deno.enable": true, - "editor.defaultFormatter": "denoland.vscode-deno", - "editor.formatOnPaste": true, - "editor.formatOnSave": true, - "editor.formatOnSaveMode": "file", - "editor.codeActionsOnSave": [ - "source.organizeImports", - "source.fixAll" - ], // Terminal "terminal.integrated.defaultProfile.linux": "zsh", // Prettifies the response with emojis and such. @@ -72,11 +60,10 @@ }, // Use 'updateContentCommand' to run commands after the container is successfully created. "updateContentCommand": { - "install_docsify": "bun install --global docsify-cli", - "install_deno": "curl -fsSL https://deno.land/install.sh | sh" + "install": "bun install --global docsify-cli" }, // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": { - "restore": "bun run clean && bun install" + "restore": "bun install" } } diff --git a/.devcontainer/local-features/deno/devcontainer-feature.json b/.devcontainer/local-features/deno/devcontainer-feature.json new file mode 100644 index 0000000..fcfee79 --- /dev/null +++ b/.devcontainer/local-features/deno/devcontainer-feature.json @@ -0,0 +1,46 @@ +{ + "id": "deno", + "name": "Deno", + "version": "1.0.0", + "description": "Installs Deno and needed dependencies instead of Node.js.", + "options": { + "version": { + "type": "string", + "proposals": [ + "latest" + ], + "default": "latest", + "description": "Select or enter a Deno version to install" + }, + "denoInstall": { + "type": "string", + "description": "The path where Deno will be installed.", + "default": "/usr/local" + }, + }, + "customizations": { + "vscode": { + "extensions": [ + "denoland.vscode-deno" + ], + "settings": { + // Better linting & formatting + "deno.enable": true, + "editor.defaultFormatter": "denoland.vscode-deno", + "editor.formatOnPaste": true, + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file", + "editor.codeActionsOnSave": [ + "source.organizeImports", + "source.fixAll" + ] + } + } + }, + "containerEnv": { + "DENO_INSTALL": "/usr/local" + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} diff --git a/.devcontainer/local-features/deno/install.sh b/.devcontainer/local-features/deno/install.sh new file mode 100644 index 0000000..3c96666 --- /dev/null +++ b/.devcontainer/local-features/deno/install.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +DENO_VERSION=${VERSION:-"latest"} +DENO_INSTALL=${DENO_INSTALL:-"/usr/local"} + +echo "Activating feature 'deno@${DENO_VERSION}'" + +# The 'install.sh' entrypoint script is always executed as the root user. + +# If we don't already have Deno installed, install it now. +if ! deno --version > /dev/null ; then + echo "Installing Deno..." + if [ "${DENO_VERSION}" = "latest" ]; then + curl -fsSL https://deno.land/install.sh | sh + else + curl -fsSL https://deno.land/install.sh | sh -s v${DENO_VERSION} + fi +fi