frugal-iot-server 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env zsh
2
+ #
3
+ # Things to do before publishing frugal-iot-server, that are easy to forget and awkward to notice
4
+ # afterwards. Run it, read what it says, then publish:
5
+ #
6
+ # npm run prerelease
7
+ #
8
+ # It checks the sensor schema, copies it into the examples that ship with frugal-iot-logger so they
9
+ # do not drift away from the schema this server actually uses, and looks for the package being wired
10
+ # to a local checkout. Nothing is published here and nothing is committed - that is still yours.
11
+ #
12
+ # Two kinds of finding, deliberately treated differently:
13
+ # - The schema warnings are judgement calls: it says what it noticed and leaves it to you.
14
+ # - The ones under "blockers" are never what you want in a published package, so this exits
15
+ # non-zero for those, and "npm run prerelease" fails visibly rather than scrolling past.
16
+
17
+ set -euo pipefail
18
+
19
+ HERE="${0:A:h:h}" # The frugal-iot-server checkout this script is in
20
+ SCHEMA="${HERE}/config.d/schema"
21
+
22
+ cd "$HERE"
23
+
24
+ BLOCKERS=()
25
+
26
+ echo "=== Checking ${SCHEMA} ==="
27
+ node scripts/check-schema.js config.d/schema || true
28
+
29
+ echo
30
+ echo "=== Copying the schema into the frugal-iot-logger examples ==="
31
+ zsh scripts/copy-schema-to-examples.zsh
32
+
33
+ # ---- Is this package wired to a checkout on this machine? ----
34
+ # Developing the server, logger and client together means pointing the server at sibling checkouts,
35
+ # and every way of doing that is invisible once you have got used to it. Published, each one either
36
+ # breaks every install outright or ships code nobody else has.
37
+ echo
38
+ echo "=== Checking nothing is wired to a local checkout ==="
39
+
40
+ # 1. "file:" or "link:" dependencies - these would make "npm install frugal-iot-server" fail for
41
+ # everybody, because the path they name does not exist on anyone else's machine
42
+ LOCALDEPS=$(node -e '
43
+ const p = require("./package.json");
44
+ const out = [];
45
+ for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
46
+ for (const [name, range] of Object.entries(p[section] || {})) {
47
+ if (/^(file:|link:|\.\.?\/)/.test(String(range))) out.push(`${section} ${name} = ${range}`);
48
+ }
49
+ }
50
+ console.log(out.join("\n"));
51
+ ')
52
+ if [[ -n "$LOCALDEPS" ]]; then
53
+ print -r -- "$LOCALDEPS" | sed 's/^/ /'
54
+ BLOCKERS+=("package.json names a dependency by path - publishing that breaks every install. Put the version range back.")
55
+ else
56
+ echo " package.json names no dependencies by path"
57
+ fi
58
+
59
+ # 2. npm link - node_modules/<pkg> being a symlink means what you have been testing is your
60
+ # checkout, not the published package, so the version you require may not contain your changes
61
+ LINKED=()
62
+ for p in frugal-iot-logger frugal-iot-client; do
63
+ if [[ -L "node_modules/$p" ]]; then
64
+ LINKED+=("$p -> $(readlink node_modules/$p)")
65
+ fi
66
+ done
67
+ if (( ${#LINKED} )); then
68
+ for l in $LINKED; do echo " linked: $l"; done
69
+ echo " What you have been running is that checkout, not the published package."
70
+ echo " Publish the linked package first, then require the new version here."
71
+ else
72
+ echo " node_modules holds published packages, not links to checkouts"
73
+ fi
74
+
75
+ # 3. The development alternatives inside the source, which are switched by editing rather than by
76
+ # configuration, so they are only ever one forgotten comment away from being published
77
+ if grep -qE '^\s*import .*from\s+"\.\./frugal-iot-logger' frugal-iot-server.js 2>/dev/null; then
78
+ BLOCKERS+=("frugal-iot-server.js is importing the logger from ../frugal-iot-logger - comment that line out and uncomment the \"frugal-iot-logger\" one.")
79
+ else
80
+ echo " frugal-iot-server.js imports the logger as a package, not by path"
81
+ fi
82
+ if grep -qE '^\s*(htmldir|nodemodulesdir):\s*\.\./' config.d/server.yaml 2>/dev/null; then
83
+ BLOCKERS+=("config.d/server.yaml points htmldir or nodemodulesdir at ../frugal-iot-client - that is the development setting and ships to everyone who installs.")
84
+ else
85
+ echo " config.d/server.yaml points at ./node_modules, not at a sibling checkout"
86
+ fi
87
+
88
+ # ---- Are the versions this requires actually available? ----
89
+ # Requiring a version that has not been published yet is the trap that stops "npm install" dead,
90
+ # on a Pi as well as here, and nothing in the repo shows it.
91
+ echo
92
+ echo "=== Checking the versions this requires have been published ==="
93
+ for p in frugal-iot-logger frugal-iot-client; do
94
+ RANGE=$(node -e "console.log(require('./package.json').dependencies['$p'] || '')")
95
+ if [[ -z "$RANGE" ]]; then continue; fi
96
+ if ! LATEST=$(npm view "$p" version 2>/dev/null); then
97
+ echo " $p: could not ask npm (offline?) - requires ${RANGE}, check it yourself"
98
+ continue
99
+ fi
100
+ # "npm view <pkg>@<range> version" prints nothing and exits 1 when no published version satisfies
101
+ # the range - which is the answer we are after, not a failure, hence the "|| true" (this script
102
+ # runs under "set -e -o pipefail", so without it the 404 would stop the whole thing here)
103
+ MATCH=$(npm view "${p}@${RANGE}" version 2>/dev/null | tail -1 || true)
104
+ if [[ -z "$MATCH" ]]; then
105
+ echo " $p: requires ${RANGE}, but the newest published is ${LATEST}"
106
+ BLOCKERS+=("Nothing published satisfies ${p}@${RANGE} (newest is ${LATEST}) - publish ${p} first, or every \"npm install frugal-iot-server\" fails.")
107
+ else
108
+ echo " $p: requires ${RANGE}, satisfied by a published version (newest is ${LATEST})"
109
+ fi
110
+ done
111
+
112
+ echo
113
+ echo "=== Reminders ==="
114
+ echo " - Is the version in package.json the one you mean to publish? $(node -e 'console.log(require("./package.json").version)')"
115
+ echo " - Check what would actually go into the package, since \"files\" in package.json is an"
116
+ echo " allow-list and anything not named in it is left out:"
117
+ echo " npm pack --dry-run"
118
+ echo " - Nothing here is committed or published - do that yourself."
119
+
120
+ if (( ${#BLOCKERS} )); then
121
+ echo
122
+ echo "=== Do not publish yet - ${#BLOCKERS} blocker(s) ==="
123
+ for b in $BLOCKERS; do echo " * $b"; done
124
+ exit 1
125
+ fi
@@ -5,10 +5,10 @@
5
5
  #
6
6
  # Typically used on a new installation to give the seeded 'superuser' account a password,
7
7
  # since the database is created with that account having none:
8
- # npx frugal-iot-setpassword superuser "secret!123"
8
+ # npx --no frugal-iot-setpassword superuser "secret!123"
9
9
  #
10
10
  # Usage:
11
- # npx frugal-iot-setpassword <username> <password>
11
+ # npx --no frugal-iot-setpassword <username> <password>
12
12
  # scripts/setpassword.zsh <username> <password>
13
13
 
14
14
  set -euo pipefail
@@ -38,7 +38,7 @@ fi
38
38
 
39
39
  if [[ ! -f "$DB" ]]; then
40
40
  echo "Error: database ${DB} not found in this directory - prepare the directory first with:" >&2
41
- echo " npx frugal-iot-init" >&2
41
+ echo " npx --no frugal-iot-init" >&2
42
42
  exit 1
43
43
  fi
44
44