commit 0995870b95fefeb13980b433cff764261872ee5a Author: Joshua Potter Date: Wed Dec 13 15:32:55 2023 -0700 Initial commit. diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..817939c --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +if command -v git > /dev/null && on_git_branch; then + git config --local core.hooksPath .githooks/ +fi + +use flake diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..749f5d3 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +STAGED=$( + git --no-pager diff --name-only --no-color --cached --diff-filter=d | + # Remove quotations used to surrounding filenames with special characters. + sed -e "s/^\"//" -e "s/\"$//g" +) + +TARGETS=() +while IFS= read -r FILENAME +do + if [[ "$FILENAME" =~ .*\.jsx?$ ]] || [[ "$FILENAME" == .*\.tsx?$ ]]; then + TARGETS+=("${FILENAME}") + fi +done <<< "$STAGED" + +if (( ${#TARGETS[@]} )); then + prettier --write "${TARGETS[@]}" + git add "${TARGETS[@]}" +fi diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ae6a44 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Directory used by `direnv` to hold `use flake`-generated profiles. +/.direnv/ + +# The directory containing all build outputs. +/dist/ + +# A symlink produced by default when running `nix build`. +/result + +# The NodeJS dependency directory. +/node_modules/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..3bc0677 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# NodeJS Flake Template + +This is a template for constructing a working environment for +[Node.js](https://nodejs.org/en) development (version v18.18.2) with the [npm](https://www.npmjs.com/) +(version 9.8.1) packaging tool. [direnv](https://direnv.net/) can be used to +launch a dev shell upon entering this directory (refer to `.envrc`). Otherwise +run via: +```bash +$ nix develop +``` + +## Language Server + +The [typescript-language-server](https://github.com/typescript-language-server/typescript-language-server) +(version 4.1.2) is included in this flake. + +## Formatting + +Formatting depends on [prettier](https://prettier.io/) (version 3.1.0). A +`pre-commit` hook is included in `.githooks` that can be used to format all +`*.jsx?` and `*.tsx?` files prior to commit. Install via: +```bash +$ git config --local core.hooksPath .githooks/ +``` +If running [direnv](https://direnv.net/), this hook is installed automatically +when entering the directory. + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..fdd5e26 --- /dev/null +++ b/flake.lock @@ -0,0 +1,76 @@ +{ + "nodes": { + "flake-compat": { + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "revCount": 57, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701253981, + "narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "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..091a78b --- /dev/null +++ b/flake.nix @@ -0,0 +1,54 @@ +{ + description = '' + An opinionated nodejs flake. + + To generate a copy of this template elsewhere, install + [bootstrap](https://github.com/jrpotter/bootstrap) and run: + ```bash + $ bootstrap nodejs + ``` + ''; + + inputs = { + flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + packages = { + lib = pkgs.buildNpmPackage { + pname = "portfolio"; + version = "0.1.0"; + src = ./.; + npmDepsHash = "sha256-eGfiDf/BKQcGhwGvmqpHTQNkAfiKSSPIfrmrPsGyOHw="; + + # Needed to properly invoke npm run build. + nativeBuildInputs = [ pkgs.typescript ]; + + installPhase = '' + mkdir $out + cp src/index.html $out + cp dist/main.js $out + ''; + }; + + default = self.packages.${system}.lib; + }; + + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + nodePackages.prettier + nodePackages.typescript-language-server + nodejs + prefetch-npm-deps + typescript + ]; + }; + }); +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..efd8cdb --- /dev/null +++ b/package-lock.json @@ -0,0 +1,21 @@ +{ + "name": "portfolio", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "portfolio", + "version": "0.1.0", + "license": "ISC", + "dependencies": { + "lodash": "^4.17.21" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b063f62 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "portfolio", + "version": "0.1.0", + "description": "", + "main": "main.js", + "scripts": { + "build": "tsc", + "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "lodash": "^4.17.21" + } +} diff --git a/prettier.config.cjs b/prettier.config.cjs new file mode 100644 index 0000000..ee2e235 --- /dev/null +++ b/prettier.config.cjs @@ -0,0 +1,7 @@ +/** @type {import('prettier').Options} */ +module.exports = { + arrowParens: "always", + semi: false, + tabWidth: 2, + trailingComma: "es5", +} diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..1b5a1a5 --- /dev/null +++ b/src/index.html @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..a8141d3 --- /dev/null +++ b/src/main.ts @@ -0,0 +1 @@ +console.log("Hello, world!"); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c027276 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + // Visit https://aka.ms/tsconfig to read more about this file. + "compilerOptions": { + "target": "es2016", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "outDir": "dist" + }, + "include": ["src"], + "$schema": "https://json.schemastore.org/tsconfig" +}