commit 6f67a0dc1a96bf43eb86388b9acfe54c30d7ecc9 Author: jasmine Date: Mon Oct 27 20:02:55 2025 +0800 Initial commit: minimal JavaScript template with Nix Features: - Nix + Flakes for reproducible environments - Bun (fast JavaScript runtime) - Vite (development server & build tool) - ESLint + Prettier (linting & formatting) - Devshell commands via just - Modular structure using flake-parts - Omnix template support for initialization diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..248e5ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Dependencies +node_modules/ + +# Build output +dist/ +build/ + +# Direnv +.direnv/ diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..a239a33 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +# Dependencies +node_modules + +# Build output +dist +build diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..0ce057f --- /dev/null +++ b/Justfile @@ -0,0 +1,58 @@ +# List available commands +default: + @just --list + +# Start development server with hot reload +dev: + bun run dev + +# Add a package dependency +add package: + bun add {{package}} + +# Add a dev dependency +add-dev package: + bun add -d {{package}} + +# Remove a package dependency +remove package: + bun remove {{package}} + +# Build for production +build: + bun run build + +# Preview production build +preview: + bun run preview + +# Install dependencies +install: + bun install + +# Update flake inputs +update: + nix flake update + +# Clean build artifacts and dependencies +clean: + rm -rf dist node_modules bun.lockb + +# Format code with prettierd +format: + prettierd --write . + +# Check formatting without making changes +format-check: + prettierd --check . + +# Lint code with eslint +lint: + eslint . + +# Lint and auto-fix issues +lint-fix: + eslint --fix . + +# Check both formatting and linting +check: format-check lint diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..461f024 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 sajenim + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..24cd418 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# JavaScript Template + +A minimal JavaScript development template using Nix. Key features: + +- Nix + Flakes for reproducible environments +- Bun (fast JavaScript runtime) +- Vite (development server & build tool) +- ESLint + Prettier (linting & formatting) +- Devshell commands via just + +## Prerequisites + +- [Nix](https://nixos.org/download.html) with flakes enabled +- [direnv](https://direnv.net/) (optional but recommended) + +## Getting Started + +Initialize a new project using [omnix](https://omnix.page): + +```sh +nix run nixpkgs#omnix -- \ + init github:sajenim/javascript-template -o ./my-project +``` + +Then enter the development environment: + +```sh +cd my-project +direnv allow # Or use: nix develop +just dev +``` + +**NixOS users:** If bun-installed binaries fail to find system libraries, enable FHS compatibility: + +```nix +# nix/modules/devshell.nix +fhs = true; +``` + +## Customization + +This template provides minimal, sensible defaults. Customize as needed: + +- Add dependencies: `just add ` +- Modify linting rules in `eslint.config.js` +- Add Prettier config via `.prettierrc` if needed +- Extend `Justfile` with project-specific commands + +## Acknowledgments + +- [srid's haskell-template](https://github.com/srid/haskell-template) diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..56a97aa Binary files /dev/null and b/bun.lockb differ diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..78300bc --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,13 @@ +export default [ + { + ignores: ["dist", "build", "node_modules"], + }, + { + files: ["**/*.js"], + languageOptions: { + ecmaVersion: "latest", + sourceType: "module", + }, + rules: {}, + }, +]; diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..395470a --- /dev/null +++ b/flake.lock @@ -0,0 +1,77 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1760948891, + "narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1751274312, + "narHash": "sha256-/bVBlRpECLVzjV19t5KMdMFWSwKLtb5RyXdjz3LJT+g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "50ab793786d9de88ee30ec4e4c24fb4236fc2674", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1754788789, + "narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "a73b9c743612e4244d865a2fdee11865283c04e6", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "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..2fa174a --- /dev/null +++ b/flake.nix @@ -0,0 +1,18 @@ +{ + description = "Nix template for JavaScript projects, powered by Bun"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; + systems.url = "github:nix-systems/default"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = inputs: + inputs.flake-parts.lib.mkFlake {inherit inputs;} { + systems = import inputs.systems; + imports = [ + ./nix/modules/devshell.nix + ./nix/modules/template.nix + ]; + }; +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..111f7e3 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + JavaScript App + + + +
+ + + diff --git a/nix/modules/devshell.nix b/nix/modules/devshell.nix new file mode 100644 index 0000000..70265b1 --- /dev/null +++ b/nix/modules/devshell.nix @@ -0,0 +1,43 @@ +{inputs, lib, ...}: let + # FHS compatibility for NixOS (steam-run wrapper) + # Enable if bun-installed binaries fail to find system libraries + fhs = false; +in { + perSystem = {system, ...}: let + pkgs = import inputs.nixpkgs { + inherit system; + config.allowUnfree = fhs; + }; + + fhsPackages = lib.optionals fhs [ + pkgs.steam-run + ]; + + fhsSetup = lib.optionalString fhs '' + alias bun="steam-run bun" + ''; + in { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; + [ + bun + eslint + just + prettierd + ] + ++ fhsPackages; + + shellHook = '' + ${fhsSetup} + + if [ -f package.json ]; then + echo "Installing dependencies..." + bun install + fi + + echo "" + echo "💡 Run 'just' to see available commands" + ''; + }; + }; +} diff --git a/nix/modules/template.nix b/nix/modules/template.nix new file mode 100644 index 0000000..c936a64 --- /dev/null +++ b/nix/modules/template.nix @@ -0,0 +1,19 @@ +{inputs, ...}: { + flake = rec { + templates.default = { + description = "A minimal JavaScript project template with Bun and Nix"; + path = inputs.self; + }; + + om.templates.javascript-template = { + template = templates.default; + params = [ + { + name = "package-name"; + description = "Name of the JavaScript package"; + placeholder = "javascript-template"; + } + ]; + }; + }; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..9cf1dc5 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "javascript-template", + "version": "1.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "devDependencies": { + "vite": "^6.0.0" + } +} diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..9721113 --- /dev/null +++ b/src/main.js @@ -0,0 +1,8 @@ +const app = document.getElementById("app"); + +app.innerHTML = ` +

JavaScript Template

+

Edit src/main.js to get started.

+`; + +console.log("Development server running"); diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..ca371ab --- /dev/null +++ b/src/style.css @@ -0,0 +1,35 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: system-ui, -apple-system, sans-serif; + line-height: 1.6; + padding: 2rem; + background: #f5f5f5; + color: #333; +} + +#app { + max-width: 800px; + margin: 0 auto; + padding: 2rem; + background: white; + border-radius: 8px; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); +} + +h1 { + margin-bottom: 1rem; + color: #2c3e50; +} + +code { + padding: 0.2em 0.4em; + background: #f0f0f0; + border-radius: 3px; + font-family: "Monaco", "Courier New", monospace; + font-size: 0.9em; +}