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:
parent
1403ddb6ae
commit
3e385eba0a
|
|
@ -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"
|
||||||
|
|
@ -55,7 +55,10 @@ try {
|
||||||
log('update-index: start')
|
log('update-index: start')
|
||||||
run('git', ['pull', '--ff-only', '--quiet'])
|
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')])
|
run(process.execPath, [join(ROOT, 'make-index.mjs')])
|
||||||
const generated = JSON.parse(readFileSync(INDEX, 'utf8'))
|
const generated = JSON.parse(readFileSync(INDEX, 'utf8'))
|
||||||
|
|
||||||
|
|
@ -94,13 +97,15 @@ try {
|
||||||
|
|
||||||
const next = { ...generated, plugins: merged }
|
const next = { ...generated, plugins: merged }
|
||||||
const text = `${JSON.stringify(next, null, 2)}\n`
|
const text = `${JSON.stringify(next, null, 2)}\n`
|
||||||
const unchanged = text === readFileSync(INDEX, 'utf8')
|
const unchanged = text === beforeText
|
||||||
if (unchanged) {
|
if (unchanged) {
|
||||||
|
if (readFileSync(INDEX, 'utf8') !== beforeText) writeFileSync(INDEX, beforeText, 'utf8')
|
||||||
log('update-index: nothing to do')
|
log('update-index: nothing to do')
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
for (const note of notes) log(` ${note}`)
|
for (const note of notes) log(` ${note}`)
|
||||||
if (DRY) {
|
if (DRY) {
|
||||||
|
writeFileSync(INDEX, beforeText, 'utf8')
|
||||||
log('update-index: dry run, not writing')
|
log('update-index: dry run, not writing')
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue