frugal-iot-server 0.3.7 → 0.3.8
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.
- package/INSTALLATION.md +299 -0
- package/README.md +94 -19
- package/config.d/schema/devices.yaml +63 -0
- package/config.d/schema/modules.yaml +8 -37
- package/config.d/schema/topics.yaml +39 -6
- package/extras/mosquitto-bridge.conf.example +130 -0
- package/frugal-iot-server.js +50 -2
- package/lib/housekeeping.js +10 -4
- package/package.json +10 -5
- package/public/index.html +8 -0
- package/public/service-worker.js +4 -3
- package/scripts/addbridge-pi.zsh +164 -0
- package/scripts/addbridge-prod.zsh +215 -0
- package/scripts/check-published-files.js +0 -0
- package/scripts/check-schema.js +126 -15
- package/scripts/clearretained.zsh +153 -0
- package/scripts/copy-schema-to-examples.zsh +9 -5
- package/scripts/diagnostic.zsh +47 -0
- package/scripts/install-pi.sh +646 -0
- package/scripts/not-published.txt +27 -0
- package/scripts/prerelease.zsh +91 -17
package/scripts/prerelease.zsh
CHANGED
|
@@ -5,14 +5,19 @@
|
|
|
5
5
|
#
|
|
6
6
|
# npm run prerelease
|
|
7
7
|
#
|
|
8
|
-
# It checks the sensor schema
|
|
9
|
-
#
|
|
10
|
-
#
|
|
8
|
+
# It checks the sensor schema and copies it into the examples that ship with frugal-iot-logger, sets
|
|
9
|
+
# the service worker's cache version, and looks for the package being wired to a checkout on this
|
|
10
|
+
# machine, requiring versions that are not published, or containing files it should not.
|
|
11
11
|
#
|
|
12
|
-
# Two
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
12
|
+
# Two things it changes, both of which have exactly one right answer: the copied schema files, and
|
|
13
|
+
# the CACHE_NAME line in public/service-worker.js. Everything else it only reports on. Nothing is
|
|
14
|
+
# committed and nothing is published - that is still yours.
|
|
15
|
+
#
|
|
16
|
+
# Three kinds of finding:
|
|
17
|
+
# - Schema warnings are judgement calls: it says what it noticed and leaves it to you.
|
|
18
|
+
# - "Worth a look" warnings are usually worth acting on but can be deliberate.
|
|
19
|
+
# - "Blockers" are never what you want in a published package, so this exits non-zero for those,
|
|
20
|
+
# and "npm run prerelease" fails visibly rather than scrolling past.
|
|
16
21
|
|
|
17
22
|
set -euo pipefail
|
|
18
23
|
|
|
@@ -21,7 +26,8 @@ SCHEMA="${HERE}/config.d/schema"
|
|
|
21
26
|
|
|
22
27
|
cd "$HERE"
|
|
23
28
|
|
|
24
|
-
BLOCKERS=()
|
|
29
|
+
BLOCKERS=() # never right in a published package - this script exits non-zero for these
|
|
30
|
+
WARNINGS=() # probably worth doing something about, but yours to judge
|
|
25
31
|
|
|
26
32
|
echo "=== Checking ${SCHEMA} ==="
|
|
27
33
|
node scripts/check-schema.js config.d/schema || true
|
|
@@ -87,9 +93,19 @@ fi
|
|
|
87
93
|
|
|
88
94
|
# ---- Are the versions this requires actually available? ----
|
|
89
95
|
# 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.
|
|
96
|
+
# on a Pi as well as here, and nothing in the repo shows it. Asking for one that is published but
|
|
97
|
+
# not the newest is a lesser problem - a fresh install resolves to the newest anyway, but an
|
|
98
|
+
# existing one is free to stay where it is, so your changes reach nobody who already has it.
|
|
91
99
|
echo
|
|
92
100
|
echo "=== Checking the versions this requires have been published ==="
|
|
101
|
+
|
|
102
|
+
# Highest published version of $1 satisfying range $2, or empty if none - and it prints nothing and
|
|
103
|
+
# exits 1 when nothing matches, which is an answer rather than a failure, hence the "|| true"
|
|
104
|
+
# (this script runs under "set -e -o pipefail", so without it a 404 would stop everything here)
|
|
105
|
+
published_match() {
|
|
106
|
+
npm view "${1}@${2}" version 2>/dev/null | awk '{print $NF}' | tr -d "'" | tail -1 || true
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
for p in frugal-iot-logger frugal-iot-client; do
|
|
94
110
|
RANGE=$(node -e "console.log(require('./package.json').dependencies['$p'] || '')")
|
|
95
111
|
if [[ -z "$RANGE" ]]; then continue; fi
|
|
@@ -97,26 +113,84 @@ for p in frugal-iot-logger frugal-iot-client; do
|
|
|
97
113
|
echo " $p: could not ask npm (offline?) - requires ${RANGE}, check it yourself"
|
|
98
114
|
continue
|
|
99
115
|
fi
|
|
100
|
-
|
|
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)
|
|
116
|
+
MATCH=$(published_match "$p" "$RANGE")
|
|
104
117
|
if [[ -z "$MATCH" ]]; then
|
|
105
118
|
echo " $p: requires ${RANGE}, but the newest published is ${LATEST}"
|
|
106
119
|
BLOCKERS+=("Nothing published satisfies ${p}@${RANGE} (newest is ${LATEST}) - publish ${p} first, or every \"npm install frugal-iot-server\" fails.")
|
|
120
|
+
elif [[ "$MATCH" != "$LATEST" ]]; then
|
|
121
|
+
echo " $p: requires ${RANGE} -> ${MATCH}, but ${LATEST} is published"
|
|
122
|
+
WARNINGS+=("${p}@${RANGE} resolves to ${MATCH}, not the newest published ${LATEST} - bump the range if you meant installs to pick up ${LATEST}.")
|
|
107
123
|
else
|
|
108
|
-
|
|
124
|
+
# The range allows the newest, but if its floor is older then an existing install can sit on
|
|
125
|
+
# that floor - "npm install" with a lockfile will not move it, only "npm update" will
|
|
126
|
+
FLOOR=${RANGE#[\^~>=]}
|
|
127
|
+
FLOOR=${FLOOR#=}
|
|
128
|
+
if [[ -n "$FLOOR" && "$FLOOR" != "$LATEST" ]]; then
|
|
129
|
+
echo " $p: requires ${RANGE}, newest published ${LATEST} (an existing install may stay on ${FLOOR})"
|
|
130
|
+
WARNINGS+=("${p} requires ${RANGE}, so an install that already has ${FLOOR} is not obliged to move to ${LATEST}. Raise the range to ^${LATEST} if this release needs it.")
|
|
131
|
+
else
|
|
132
|
+
echo " $p: requires ${RANGE}, newest published ${LATEST} - in step"
|
|
133
|
+
fi
|
|
109
134
|
fi
|
|
110
135
|
done
|
|
111
136
|
|
|
137
|
+
# ---- The web client's cache-busting version ----
|
|
138
|
+
# public/service-worker.js caches the app in the browser, and CACHE_NAME is what makes an already
|
|
139
|
+
# installed PWA fetch it again. Left behind, people keep running the client they already had, which
|
|
140
|
+
# looks exactly like a release that did nothing. It tracks the client version, so set it from
|
|
141
|
+
# whichever published client this release will actually resolve to.
|
|
142
|
+
echo
|
|
143
|
+
echo "=== Checking the service worker's cache version ==="
|
|
144
|
+
SW=public/service-worker.js
|
|
145
|
+
CLIENT_RANGE=$(node -e "console.log(require('./package.json').dependencies['frugal-iot-client'] || '')")
|
|
146
|
+
if [[ ! -f "$SW" ]]; then
|
|
147
|
+
echo " no ${SW} here"
|
|
148
|
+
elif [[ -z "$CLIENT_RANGE" ]]; then
|
|
149
|
+
echo " package.json has no frugal-iot-client dependency to match against"
|
|
150
|
+
else
|
|
151
|
+
SW_VERSION=$(sed -n "s/^const CACHE_NAME = 'frugal-iot-cache-\([^']*\)'.*/\1/p" "$SW" | head -1)
|
|
152
|
+
CLIENT_LATEST=$(npm view frugal-iot-client version 2>/dev/null || true)
|
|
153
|
+
CLIENT_WANTED=$(published_match frugal-iot-client "$CLIENT_RANGE")
|
|
154
|
+
if [[ -z "$SW_VERSION" ]]; then
|
|
155
|
+
echo " could not find a CACHE_NAME line of the form frugal-iot-cache-<version> in ${SW}"
|
|
156
|
+
WARNINGS+=("Could not read CACHE_NAME from ${SW} - check by hand that it changes when the client does.")
|
|
157
|
+
elif [[ -z "$CLIENT_WANTED" ]]; then
|
|
158
|
+
echo " CACHE_NAME says ${SW_VERSION}, and nothing published satisfies ${CLIENT_RANGE}"
|
|
159
|
+
BLOCKERS+=("Cannot set CACHE_NAME: no published frugal-iot-client satisfies ${CLIENT_RANGE}.")
|
|
160
|
+
else
|
|
161
|
+
if [[ "$SW_VERSION" == "$CLIENT_WANTED" ]]; then
|
|
162
|
+
echo " CACHE_NAME is ${SW_VERSION}, matching the client this release installs"
|
|
163
|
+
else
|
|
164
|
+
# An in-place edit rather than a warning: there is only one right answer, and a stale cache
|
|
165
|
+
# name is invisible until somebody's browser keeps serving them last month's dashboard
|
|
166
|
+
sed -i.bak "s/^const CACHE_NAME = 'frugal-iot-cache-[^']*'/const CACHE_NAME = 'frugal-iot-cache-${CLIENT_WANTED}'/" "$SW"
|
|
167
|
+
rm -f "${SW}.bak"
|
|
168
|
+
echo " CACHE_NAME updated from ${SW_VERSION} to ${CLIENT_WANTED} - commit ${SW}"
|
|
169
|
+
fi
|
|
170
|
+
if [[ -n "$CLIENT_LATEST" && "$CLIENT_WANTED" != "$CLIENT_LATEST" ]]; then
|
|
171
|
+
WARNINGS+=("CACHE_NAME follows ${CLIENT_WANTED} because that is what ${CLIENT_RANGE} allows, while ${CLIENT_LATEST} is published.")
|
|
172
|
+
fi
|
|
173
|
+
fi
|
|
174
|
+
fi
|
|
175
|
+
|
|
176
|
+
# ---- What would and would not be published ----
|
|
177
|
+
echo
|
|
178
|
+
echo "=== Checking what the package would contain ==="
|
|
179
|
+
if ! node scripts/check-published-files.js; then
|
|
180
|
+
BLOCKERS+=("Something git ignores would be published - see above.")
|
|
181
|
+
fi
|
|
182
|
+
|
|
112
183
|
echo
|
|
113
184
|
echo "=== Reminders ==="
|
|
114
185
|
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
186
|
echo " - Nothing here is committed or published - do that yourself."
|
|
119
187
|
|
|
188
|
+
if (( ${#WARNINGS} )); then
|
|
189
|
+
echo
|
|
190
|
+
echo "=== Worth a look - ${#WARNINGS} warning(s) ==="
|
|
191
|
+
for w in $WARNINGS; do echo " - $w"; done
|
|
192
|
+
fi
|
|
193
|
+
|
|
120
194
|
if (( ${#BLOCKERS} )); then
|
|
121
195
|
echo
|
|
122
196
|
echo "=== Do not publish yet - ${#BLOCKERS} blocker(s) ==="
|