From 8bfc94611a91b5f047c93e50508e14f6e0534b1d Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Mon, 1 Apr 2019 09:26:15 -0500 Subject: [PATCH] build `public` --- .gitignore | 2 ++ Makefile | 31 ++++++++++++++++++++++++++++++- shell.nix | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d0bd8ab1..b73c8676 100644 --- a/.gitignore +++ b/.gitignore @@ -237,3 +237,5 @@ documentation.json # direnv config file .envrc + +/public \ No newline at end of file diff --git a/Makefile b/Makefile index 5b36215b..bff7b40e 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ format: node_modules .PHONY: clean clean: - rm -rf node_modules styleguide-app/elm.js styleguide-app/bundle.js $(shell find . -type d -name 'elm-stuff') + rm -rf node_modules styleguide-app/elm.js styleguide-app/bundle.js $(shell find . -type d -name 'elm-stuff') public .PHONY: styleguide-app styleguide-app: styleguide-app/elm.js @@ -34,6 +34,35 @@ styleguide-app/bundle.js: lib/index.js node_modules styleguide-app/elm.js: styleguide-app/bundle.js $(shell find src styleguide-app -type f -name '*.elm') cd styleguide-app; npx elm make Main.elm --output=$(@F) +# for publishing styleguide + +# We don't want to have to generate new rules for every single asset, so we find +# all the ones that exist (`STYLEGUIDE_ASSETS`) then replace the roots +# (`PUBLIC_ASSETS`). The `%` wildcard works like it does in `public/%` below. +STYLEGUIDE_ASSETS=$(shell find styleguide-app/assets -type f) +PUBLIC_ASSETS=$(STYLEGUIDE_ASSETS:styleguide-app/assets/%=public/assets/%) + +public: public/index.html public/elm.js public/bundle.js $(PUBLIC_ASSETS) + touch -m $@ + +# wildcard rule: % on the left-hand side will be matched and replaced on the +# right-hand side. So `public/index.html` depends on `styleguide-app/index.html` +# +# - automatic variables: `$@` is the target (left-hand side of the rule.) `$<` +# is the first dependency. +# - about the leading `@` in `mkdir`: leading `@` turns off echoing the +# command. We're just reducing log spam here. +# - about `$(@D)`: $@ gets the target (left-hand side of the rule). Any +# automatic variable plus `D` gets the directory of that file, so `$(@D)` is +# the target's directory. +public/%: styleguide-app/% + @mkdir -p $(@D) + cp $< $@ + +.PHONY: serve-public +serve-public: public + cd public; python -m http.server + # plumbing node_modules: package.json diff --git a/shell.nix b/shell.nix index 1254b5f4..bdd9883c 100644 --- a/shell.nix +++ b/shell.nix @@ -16,5 +16,8 @@ stdenv.mkDerivation { # node dependencies nodejs nodePackages.npm + + # preview dependencies + python3 ]; }