Skip to content

Commit

Permalink
refactor: create a local feature for deno (#24)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kosperera authored Mar 6, 2024
1 parent d02939b commit f1a7ecd
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 18 deletions.
23 changes: 5 additions & 18 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -33,7 +31,6 @@
// JavaScript
"oven.bun-vscode",
// TypeScript
"denoland.vscode-deno",
"bierner.lit-html",
"better-ts-errors.better-ts-errors",
// Makefile
Expand All @@ -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.
Expand All @@ -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"
}
}
46 changes: 46 additions & 0 deletions .devcontainer/local-features/deno/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
20 changes: 20 additions & 0 deletions .devcontainer/local-features/deno/install.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f1a7ecd

Please sign in to comment.