fix: make the updater dry-run read-only and detect real changes

make-index.mjs rewrites index.json in place, so comparing after the fact
always reported no change. Capture the committed text first and restore it
for --dry-run. Adds the .cmd entry used by the scheduled task.
This commit is contained in:
newbie 2026-11-27 18:26:57 +08:00
parent 1403ddb6ae
commit 3e385eba0a
2 changed files with 12 additions and 2 deletions

5
update-index.cmd Normal file
View File

@ -0,0 +1,5 @@
@echo off
rem Unattended market-index refresh. Registered as the Windows scheduled task
rem "dsh-market-index-update"; logs to update-index.log next to this file.
set NODE=C:\Users\qyh15\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies\node\bin\node.exe
"%NODE%" "%~dp0update-index.mjs"

View File

@ -55,7 +55,10 @@ try {
log('update-index: start')
run('git', ['pull', '--ff-only', '--quiet'])
const before = JSON.parse(readFileSync(INDEX, 'utf8'))
// make-index.mjs overwrites index.json in place, so keep the committed text
// to diff against and to restore for --dry-run.
const beforeText = readFileSync(INDEX, 'utf8')
const before = JSON.parse(beforeText)
run(process.execPath, [join(ROOT, 'make-index.mjs')])
const generated = JSON.parse(readFileSync(INDEX, 'utf8'))
@ -94,13 +97,15 @@ try {
const next = { ...generated, plugins: merged }
const text = `${JSON.stringify(next, null, 2)}\n`
const unchanged = text === readFileSync(INDEX, 'utf8')
const unchanged = text === beforeText
if (unchanged) {
if (readFileSync(INDEX, 'utf8') !== beforeText) writeFileSync(INDEX, beforeText, 'utf8')
log('update-index: nothing to do')
process.exit(0)
}
for (const note of notes) log(` ${note}`)
if (DRY) {
writeFileSync(INDEX, beforeText, 'utf8')
log('update-index: dry run, not writing')
process.exit(0)
}