From 4646543060f35d742518d1ce68f4f9d3815a49f7 Mon Sep 17 00:00:00 2001 From: Wei He Date: Sat, 14 Dec 2024 23:44:46 +0000 Subject: [PATCH] WIP Setup devcontainer --- .devcontainer/Dockerfile | 3 +++ .devcontainer/devcontainer.json | 28 ++++++++++++++++++++++++++++ .devcontainer/post-start.sh | 18 ++++++++++++++++++ .husky/prepare-commit-msg | 2 +- README.md | 2 +- package.json | 1 + 6 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/post-start.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..a7885f77 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,3 @@ +ARG VARIANT="22-bookworm" + +FROM mcr.microsoft.com/devcontainers/typescript-node:1-${VARIANT} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..eb39658c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,28 @@ +{ + "name": "Socialify Dev Environment", + + "build": { + "dockerfile": "Dockerfile" + }, + + "features": { + "ghcr.io/devcontainers/features/github-cli:1": { + "installDirectlyFromGitHubRelease": true, + "version": "latest" + } + }, + + "forwardPorts": [3000], + + "containerEnv": { + "NEXT_TELEMETRY_DISABLED": "1", + "PNPM_HOME": "/home/node/.local/share/pnpm", + "PNPM_STORE_DIR": "/home/node/.local/share/.pnpm-store" + }, + + "postCreateCommand": "corepack install", + + "postStartCommand": ".devcontainer/post-start.sh", + + "customizations": {} +} diff --git a/.devcontainer/post-start.sh b/.devcontainer/post-start.sh new file mode 100755 index 00000000..7236cb96 --- /dev/null +++ b/.devcontainer/post-start.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ ! -f /home/node/.first_run ]; then + git config --global --add safe.directory $(pwd) + git config --global core.autocrlf true + git config --global core.editor nano + + pnpm config set store-dir $PNPM_STORE_DIR + pnpm install + pnpm playwright:install + + if [ ! -f .env ]; then + cp .env.example .env + echo -e "\e[31mPlease fill in the .env file\e[0m" + fi + + touch /home/node/.first_run +fi diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg index 1d00a734..102361b6 100755 --- a/.husky/prepare-commit-msg +++ b/.husky/prepare-commit-msg @@ -1,4 +1,4 @@ #!/bin/sh # gitmoji as a commit hook exec < /dev/tty -npx gitmoji-cli --hook $1 $2 +npx --yes gitmoji-cli --hook $1 $2 diff --git a/README.md b/README.md index 2908bc30..4cddc82f 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ pnpm lint pnpm test:unit # Install Playwright dependencies (first-time) -# pnpm playwright install --with-deps chrome +# pnpm playwright:install # Run e2e tests pnpm test:e2e diff --git a/package.json b/package.json index c1650385..f6301dc8 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "ncu": "npx npm-check-updates -u", "verify": "pnpm lint && pnpm test && pnpm build", "download-font": "./fonts/download-font.sh", + "playwright:install": "pnpm playwright install --with-deps chrome", "postinstall": "mkdir -p ./public && cp ./node_modules/yoga-wasm-web/dist/yoga.wasm ./public/yoga.wasm && cp ./node_modules/@resvg/resvg-wasm/index_bg.wasm ./public/resvg_bg.wasm", "prepare": "is-ci || husky" },