From 425bf6f5de7ead439c82324f2170f26922d256a7 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 23 Feb 2022 18:01:43 +0800 Subject: [PATCH] add postversion script https://github.com/mifi/lossless-cut/pull/987#issuecomment-1014246807 --- package.json | 1 + script/postversion.mjs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 script/postversion.mjs diff --git a/package.json b/package.json index 87b5ce11..15102aae 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "pack-win": "electron-builder --win", "prepack-win": "yarn build", "postinstall": "patch-package && electron-builder install-app-deps", + "version": "node script/postversion.mjs && git add no.mifi.losslesscut.appdata.xml", "pack-linux": "electron-builder --linux", "prepack-linux": "yarn build", "scan-i18n": "i18next-scanner --config i18next-scanner.config.js", diff --git a/script/postversion.mjs b/script/postversion.mjs new file mode 100644 index 00000000..e7b6c3e0 --- /dev/null +++ b/script/postversion.mjs @@ -0,0 +1,19 @@ +import { readFile, writeFile } from 'fs/promises'; +import { XMLParser, XMLBuilder } from 'fast-xml-parser'; +import moment from 'moment'; + +const xmlUrl = new URL('../no.mifi.losslesscut.appdata.xml', import.meta.url); +const xmlData = await readFile(xmlUrl); + +const packageJson = JSON.parse(await readFile(new URL('../package.json', import.meta.url))); + +const parser = new XMLParser({ alwaysCreateTextNode: true, ignoreAttributes: false, ignoreDeclaration: false }); +const xml = parser.parse(xmlData); +// console.log(xml); + +const { version } = packageJson; + +xml.component.releases.release = [{ '@_version': version, '@_date': moment().format('YYYY-MM-DD') }, ...xml.component.releases.release]; + +const builder = new XMLBuilder({ format: true, ignoreAttributes: false, suppressEmptyNode: true }); +await writeFile(xmlUrl, builder.build(xml));