From faf5b093947f922889e6325fa88fe320b506e0cf Mon Sep 17 00:00:00 2001 From: Forketyfork Date: Mon, 1 Sep 2025 08:21:36 +0200 Subject: [PATCH] nix and just development environment --- .envrc | 1 + .gitignore | 3 +++ CLAUDE.md | 30 +++++++++++++++++++++-- README.md | 42 +++++++++++++++++++++++++++++++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 52 +++++++++++++++++++++++++++++++++++++++ justfile | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 259 insertions(+), 2 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 justfile diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore index 93bf430..6f31b48 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ data.json # Code coverage dir coverage/ + +# direnv +.direnv diff --git a/CLAUDE.md b/CLAUDE.md index 9fd306c..73b0589 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,7 +2,33 @@ This file provides guidance to AI agents when working with code in this repository. -## Build Commands +## Development Environment + +This project supports two development workflows: + +### Just Commands (Recommended) + +If you're using the Nix development environment (via `nix develop` or direnv), use these Just commands: + +- `just` - List all available commands +- `just clean` - Clean build artifacts and dependencies +- `just install` - Install dependencies +- `just build` - Full production build (includes tests, typecheck and formatting) +- `just dev` - Development build +- `just watch` - Development build with watch mode +- `just prod` - Production build without tests or type checking +- `just typecheck` - TypeScript typecheck +- `just format` - Format code with Prettier +- `just lint` - Check code style with ESLint +- `just test` - Run Jest tests +- `just test-dev` - Run development build and then tests +- `just test-watch` - Run development build and then tests in watch mode +- `just coverage` - Generate test coverage report +- `just build-css` - Minify CSS with CSSO (from src/styles.src.css to styles.css) +- `just version` - Bump version in manifest.json and versions.json +- `just release` - Full release (version, push, tags) + +### Yarn Commands (Alternative) - `yarn dev` - Development build - `yarn dev:watch` - Development build with watch mode @@ -19,7 +45,7 @@ This file provides guidance to AI agents when working with code in this reposito ## General guidelines -- IMPORTANT: After finishing your task, make sure to run `yarn build` and fix any introduced issues. +- IMPORTANT: After finishing your task, make sure to run `just build` (if using Nix/Just) or `yarn build` and fix any introduced issues. - IMPORTANT: On finishing your task, make sure the README.md file is up to date with regards to the new features, usage, and development. - IMPORTANT: Always try to extract testable logic that can be independent of Obsidian plugins to separate classes or functions and write unit tests for it. - IMPORTANT: Do not write useless tests just to increase coverage, make them actually useful for catching issues in the code. diff --git a/README.md b/README.md index fb3d5b9..e3e206b 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,48 @@ The issue `summary` can also be used as a `${title}` placeholder. ## Development +### Using Nix and Just (Recommended) + +This project includes a Nix flake and direnv configuration for reproducible development environments, along with Just commands for common tasks. + +#### Prerequisites + +- [Nix](https://nixos.org/download.html) with flakes enabled +- [direnv](https://direnv.net/) (optional but recommended) + +#### Setup + +1. Clone the repository and enter the directory +2. If using direnv, run `direnv allow` to automatically load the development environment +3. If not using direnv, run `nix develop` to enter the development shell + +#### Available Commands + +```shell +# List all available commands +just + +# Clean build artifacts +just clean + +# Install dependencies +just install + +# Full production build (includes tests, type checking, and formatting) +just build + +# Development build with watch mode +just watch + +# Run tests +just test + +# Run linter +just lint +``` + +### Using Yarn Directly + Run the development build with change watch: ```shell diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0bd6705 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1756542300, + "narHash": "sha256-tlOn88coG5fzdyqz6R93SQL5Gpq+m/DsWpekNFhqPQk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..4bc5288 --- /dev/null +++ b/flake.nix @@ -0,0 +1,52 @@ +{ + description = "Obsidian YouTrack Fetcher plugin development environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + # Node.js and package manager + nodejs_20 + yarn + + # Development tools + just + typescript + + # Build tools + esbuild + + # Optional tools + git + ]; + + shellHook = '' + echo "๐Ÿš€ Obsidian YouTrack Fetcher development environment" + echo "๐Ÿ“ฆ Node.js $(node --version)" + echo "๐Ÿงถ Yarn $(yarn --version)" + echo "โšก TypeScript $(tsc --version)" + echo "" + echo "Available commands:" + echo " just clean - Clean build artifacts" + echo " just build - Full production build" + echo " just test - Run tests" + echo " just lint - Run linter" + echo "" + echo "Run 'just --list' for all available commands" + ''; + }; + + # Optional: Add formatter for nix files + formatter = pkgs.nixpkgs-fmt; + } + ); +} \ No newline at end of file diff --git a/justfile b/justfile new file mode 100644 index 0000000..daa781f --- /dev/null +++ b/justfile @@ -0,0 +1,72 @@ +# Obsidian YouTrack Fetcher - Development Commands + +# List all available commands +default: + @just --list + +# Clean build artifacts and dependencies +clean: + rm -rf node_modules + rm -rf main.js + rm -rf styles.css + rm -rf coverage + +# Install dependencies +install: + yarn install + +# Full production build (typecheck, lint, format, build, test) +build: + yarn build + +# Development build +dev: + yarn dev + +# Development build with watch mode +watch: + yarn dev:watch + +# Production build without tests +prod: + yarn prod + +# Run TypeScript type checking +typecheck: + yarn typecheck + +# Run tests +test: + yarn test + +# Run tests in development mode +test-dev: + yarn test:dev + +# Run tests in watch mode +test-watch: + yarn test:watch + +# Run tests with coverage +coverage: + yarn coverage + +# Run ESLint +lint: + yarn lint + +# Format code with Prettier +format: + yarn format + +# Build CSS from source +build-css: + yarn build:css + +# Bump version +version: + yarn version + +# Full release (version, push, tags) +release: + yarn release