From ca0cebb3c6571c6db84d493a2685d6e338e56cb4 Mon Sep 17 00:00:00 2001 From: Wei He Date: Sun, 15 Dec 2024 11:11:36 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Add=20dev?= =?UTF-8?q?=20container=20(#447)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/calm-zoos-bow.md | 5 +++++ .devcontainer/Dockerfile | 3 +++ .devcontainer/devcontainer.json | 36 +++++++++++++++++++++++++++++++++ .devcontainer/post-start.sh | 18 +++++++++++++++++ .gitignore | 3 --- .husky/prepare-commit-msg | 2 +- .vscode/settings.json | 6 ++++++ README.md | 9 ++++++++- package.json | 1 + 9 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 .changeset/calm-zoos-bow.md create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/post-start.sh create mode 100644 .vscode/settings.json diff --git a/.changeset/calm-zoos-bow.md b/.changeset/calm-zoos-bow.md new file mode 100644 index 00000000..114a1513 --- /dev/null +++ b/.changeset/calm-zoos-bow.md @@ -0,0 +1,5 @@ +--- +"socialify": patch +--- + +Set up dev container 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..5b3da302 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,36 @@ +{ + "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": { + "vscode": { + "extensions": [ + "GitHub.copilot", + "biomejs.biome", + "ms-playwright.playwright" + ] + } + } +} 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/.gitignore b/.gitignore index 81ff896c..89faabbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. -# Local vscode -.vscode - # Playwright /.playwright/.cache /.playwright/test-report 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/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..b2d79f0c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.defaultFormatter": "biomejs.biome", + "editor.formatOnSave": true, + "editor.tabSize": 2, + "files.insertFinalNewline": true +} diff --git a/README.md b/README.md index 2908bc30..af685e38 100644 --- a/README.md +++ b/README.md @@ -78,11 +78,18 @@ pnpm dev ### Testing and Committing +[![Open in Dev Container](https://img.shields.io/static/v1?label=Dev%20Containers&message=Click%20to%20Launch&color=blue)](https://open.vscode.dev/wei/socialify) + +If you already have VS Code and Docker installed locally, you can also click [here](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/wei/socialify) to get started. Clicking this link will cause VS Code to automatically install the Dev Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use. + Socialify uses [`biomejs`](https://biomejs.dev/) as linter/formatter, [`Jest`](https://jestjs.io/) for unit testing, and [`Playwright`](https://playwright.dev/) for end-to-end testing. Make sure to run and pass the linter, unit and end-to-end tests locally before committing your code. Please let us know in case you need to update the test snapshots. More in `"scripts"` section in your `package.json` file. ```shell +# Required: Set environment variables in .env. +cp .env.example .env + # Run linter/formatter pnpm lint @@ -93,7 +100,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..e560b171 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 chromium", "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" },