diff --git a/update-index.cmd b/update-index.cmd new file mode 100644 index 0000000..7bf881e --- /dev/null +++ b/update-index.cmd @@ -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" \ No newline at end of file diff --git a/update-index.mjs b/update-index.mjs index 3067b21..52745ff 100644 --- a/update-index.mjs +++ b/update-index.mjs @@ -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) }