|
1 | 1 | .POSIX:
|
2 | 2 |
|
3 |
| -cmd = node index.js |
| 3 | +all: tmp tmp/all-done |
4 | 4 |
|
5 |
| -all: tmp/all-done |
6 |
| - |
7 |
| -check: tmp/check-done |
| 5 | +check: tmp tmp/check-done |
8 | 6 |
|
9 | 7 | clean:
|
10 | 8 | rm -rf tmp/
|
11 | 9 |
|
12 |
| -.dockerignore: |
13 |
| - printf '*\n!package.json\n' > $@ |
14 |
| - |
15 | 10 | .gitignore:
|
16 | 11 | printf '.env\ntmp/\n' > $@
|
17 | 12 |
|
18 |
| -Dockerfile: |
19 |
| - printf 'FROM node\nRUN apt-get update && apt-get install -y jq\nWORKDIR /usr/src/app\nCOPY package.json /usr/src/\nRUN npm install --omit=dev --prefix /usr/src\nRUN npm install --global $$(jq --raw-output ".devDependencies | to_entries[] | \\"\(.key)@\(.value)\\"" /usr/src/package.json)\n' > $@ |
20 |
| - |
21 |
| -index.js: |
22 |
| - printf 'const dns = require("node:dns"); const fs = require("node:fs"); const https = require("node:https"); const os = require("node:os"); const serveHandler = require("serve-handler"); const server = https.createServer({ cert: fs.readFileSync("tmp/fullchain.pem"), key: fs.readFileSync("tmp/privkey.pem"), }, (request, response) => { return serveHandler(request, response); }); if (process.env.STAGE) { server.listen(443, "0.0.0.0", () => { dns.lookup(os.hostname(), (err, address) => { console.log(`Container IP address: https://$${address}`); }); process.on("SIGINT", () => { process.exit(0); }); }); }' > $@ |
| 13 | +flake.nix: |
| 14 | + nix flake init |
23 | 15 |
|
24 |
| -package.json: |
25 |
| - printf '{"stylelint":{"extends":"stylelint-config-standard","plugins":["stylelint-order"],"rules":{"order/properties-alphabetical-order":true}},"dependencies":{"serve":"latest"},"devDependencies":{"@biomejs/biome":"latest","css-validator":"latest","html-validate":"latest","js-beautify":"latest","linkinator":"latest","sort-package-json":"latest","stylelint":"latest","stylelint-config-standard":"latest","stylelint-order":"latest"}}' > $@ |
| 16 | +index.html: |
| 17 | + touch $@ |
26 | 18 |
|
27 | 19 | tmp:
|
28 | 20 | mkdir $@
|
29 | 21 |
|
30 |
| -tmp/all-done: index.js tmp tmp/fullchain.pem |
31 |
| - docker container run \ |
32 |
| - $$(test -t 0 && printf '%s' '--interactive --tty') \ |
33 |
| - --detach-keys 'ctrl-^,ctrl-^' \ |
34 |
| - --env STAGE=$(STAGE) \ |
35 |
| - --rm \ |
36 |
| - --user $$(id -u):$$(id -g) \ |
37 |
| - --volume $$(pwd):/usr/src/app/ \ |
38 |
| - $$(docker image build --quiet .) $(cmd) |
39 |
| - touch $@ |
40 |
| - |
41 |
| -tmp/check-css-done: style.css |
42 |
| - docker container run \ |
43 |
| - --rm \ |
44 |
| - --volume $$(pwd):/usr/src/app/ \ |
45 |
| - $$(docker image build --quiet .) /bin/sh -c '\ |
46 |
| - stylelint --fix style.css && \ |
47 |
| - css-validator --profile css3svg style.css' |
| 22 | +tmp/all-done: .gitignore flake.nix index.html |
| 23 | + nix develop --command sh -c "\ |
| 24 | + [ ! -z $$STAGE ] && openssl req -subj '/C=..' -nodes -x509 -keyout tmp/privkey.pem -out tmp/fullchain.pem && http-server --tls --cert tmp/fullchain.pem --key tmp/privkey.pem || true" |
48 | 25 | touch $@
|
49 | 26 |
|
50 |
| -tmp/check-done: .dockerignore .gitignore Dockerfile package.json tmp |
51 |
| - $(MAKE) $$(test -s style.css && printf 'tmp/check-css-done') $$(test -s index.html && printf 'tmp/check-html-done') tmp/check-js-done |
52 |
| - if ls -ap | grep -v -E -x './|../|.dockerignore|.env|.gitignore|CNAME|Dockerfile|Makefile|docs/|index.html|index.js|package.json|prm/|pyscript/|python/|script.js|style.css|tmp/' | grep -q .; then false; fi |
53 |
| - test $$(basename $$(pwd)) = "docs" |
| 27 | +tmp/check-done: .gitignore flake.nix index.html |
| 28 | + nix develop .#check --command sh -c "\ |
| 29 | + set -e && \ |
| 30 | + nixfmt flake.nix && \ |
| 31 | + nix flake check && \ |
| 32 | + [ -e index.html ] && js-beautify --end-with-newline --indent-inner-html --no-preserve-newlines --type html --replace index.html && \ |
| 33 | + [ -e script.js ] && biome check --unsafe --write script.js || true && \ |
| 34 | + if ls -ap | grep -v -E -x './|../|.env|.gitignore|CNAME|Makefile|index.html|index.js|flake.lock|flake.nix|prm/|python/|script.js|style.css|tmp/' | grep -q .; then exit 1; fi && \ |
| 35 | + test $$(basename $$(pwd)) = 'docs'" |
54 | 36 | touch $@
|
55 |
| - |
56 |
| -tmp/check-html-done: index.html |
57 |
| - docker container run \ |
58 |
| - --rm \ |
59 |
| - --volume $$(pwd):/usr/src/app/ \ |
60 |
| - $$(docker image build --quiet .) /bin/sh -c '\ |
61 |
| - js-beautify --end-with-newline --indent-inner-html --no-preserve-newlines --type html --replace index.html && \ |
62 |
| - linkinator index.html && \ |
63 |
| - html-validate index.html' |
64 |
| - touch $@ |
65 |
| - |
66 |
| -tmp/check-js-done: index.js |
67 |
| - docker container run \ |
68 |
| - --rm \ |
69 |
| - --volume $$(pwd):/usr/src/app/ \ |
70 |
| - $$(docker image build --quiet .) /bin/sh -c "\ |
71 |
| - script_js=$$([ -e script.js ] && echo script.js) && \ |
72 |
| - style_css=$$([ -e style.css ] && echo style.css) && \ |
73 |
| - sort-package-json package.json && \ |
74 |
| - biome check --apply-unsafe index.js package.json \$$script_js \$$style_css" |
75 |
| - touch $@ |
76 |
| - |
77 |
| -tmp/fullchain.pem: .dockerignore .gitignore Dockerfile package.json |
78 |
| - docker container run \ |
79 |
| - --rm \ |
80 |
| - --user $$(id -u):$$(id -g) \ |
81 |
| - --volume $$(pwd):/usr/src/app/ \ |
82 |
| - $$(docker image build --quiet .) openssl req -subj "/C=.." -nodes -x509 -keyout tmp/privkey.pem -out $@ |
0 commit comments