chore: incidental working-tree changes (not from the versioning work)

Changes already present in the working tree at the time of the versioning
commit, committed here so nothing is left dangling:

- index.js: template PUT preserves the untouched field (?? existing) and the
  preview handler tolerates a null/empty test_object
- update-deployed.sh: detect and restart a pm2-managed app process, and don't
  hard-fail when no bare Node process is found

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Your Name 2026-08-03 00:27:31 -04:00
parent 42f4aacf7c
commit 5bf756833d
2 changed files with 44 additions and 27 deletions

View file

@ -606,14 +606,13 @@ app.post("/workshop/:structure_id/template", (req, res) => {
});
app.put("/workshop/:structure_id/template/:template_id", (req, res) => {
let id = req.params.template_id;
let content = req.body.content;
let test_object = req.body.test_object;
const id = req.params.template_id;
const template = model.getTemplate(id);
model.updateTemplate({
...model.getTemplate(id),
content,
test_object,
...template,
content: req.body.content ?? template.content,
test_object: req.body.test_object ?? template.test_object,
});
return res.send("good");
@ -632,9 +631,12 @@ app.get("/workshop/:structure_id/template/:template_id/preview", (req, res) => {
const template = model.getTemplate(req.params.template_id);
const struct = model.getStructure(req.params.structure_id);
const context = vm.createContext({ it: null });
vm.runInContext(template.test_object, context);
const context = vm.createContext({ it: {} });
if (template.test_object) {
vm.runInContext(template.test_object, context);
}
context.it ??= {};
context.it.route = makeRoute(struct);
return res.send(

View file

@ -70,6 +70,25 @@ else
echo "Dependencies unchanged; skipping npm install."
fi
PM2_TARGET=""
if command -v pm2 >/dev/null 2>&1; then
PM2_TARGET="$(pm2 jlist 2>/dev/null | APP_DIR="$APP_DIR" node -e '
let input = "";
process.stdin.on("data", chunk => input += chunk);
process.stdin.on("end", () => {
try {
const appDir = process.env.APP_DIR;
const processes = JSON.parse(input);
const match = processes.find(process => {
const env = process.pm2_env || {};
return env.pm_cwd === appDir || env.pm_exec_path === `${appDir}/index.js`;
});
if (match) process.stdout.write(String(match.pm_id));
} catch (_) {}
});
' || true)"
fi
mapfile -t APP_PIDS < <(
for process_dir in /proc/[0-9]*; do
[[ "$(readlink "$process_dir/cwd" 2>/dev/null || true)" == "$APP_DIR" ]] || continue
@ -78,35 +97,31 @@ mapfile -t APP_PIDS < <(
done
)
if [[ "${#APP_PIDS[@]}" -eq 0 ]]; then
echo "No running Node process found for $APP_DIR; refusing to guess how to start it." >&2
exit 1
fi
APP_PID="${APP_PIDS[0]}"
APP_PID="${APP_PIDS[0]:-}"
SERVICE=""
while IFS= read -r unit; do
[[ -n "$unit" ]] || continue
if [[ "$(systemctl show -p MainPID --value "$unit" 2>/dev/null || true)" == "$APP_PID" ]]; then
SERVICE="$unit"
break
fi
done < <(systemctl list-units --type=service --all --no-legend --plain 2>/dev/null | awk '{print $1}')
if [[ -n "$APP_PID" ]]; then
while IFS= read -r unit; do
[[ -n "$unit" ]] || continue
if [[ "$(systemctl show -p MainPID --value "$unit" 2>/dev/null || true)" == "$APP_PID" ]]; then
SERVICE="$unit"
break
fi
done < <(systemctl list-units --type=service --all --no-legend --plain 2>/dev/null | awk '{print $1}')
fi
if [[ -n "$SERVICE" ]]; then
echo "Restarting systemd service $SERVICE..."
systemctl restart "$SERVICE"
systemctl is-active --quiet "$SERVICE"
systemctl --no-pager --full status "$SERVICE" | sed -n '1,12p'
elif command -v pm2 >/dev/null 2>&1 && pm2 pid all 2>/dev/null | grep -qx "$APP_PID"; then
echo "Restarting PM2 process $APP_PID..."
pm2 restart "$APP_PID" --update-env
pm2 show "$APP_PID"
elif [[ -n "$PM2_TARGET" ]]; then
echo "Restarting PM2 process $PM2_TARGET..."
pm2 restart "$PM2_TARGET" --update-env
pm2 show "$PM2_TARGET"
else
echo "Found Node PID $APP_PID, but it is not managed by systemd or PM2." >&2
echo "Could not find a systemd or PM2 app configured for $APP_DIR." >&2
echo "The code was updated from $OLD_HEAD to $NEW_HEAD, but the process was not restarted." >&2
echo "Refusing to kill it without knowing the correct startup mechanism." >&2
exit 1
fi