From 07cfd71fd9e04eba7ad79bb390aff28b5936492c Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Tue, 9 May 2023 12:42:45 +0200 Subject: [PATCH] Add generate meta --- docs/generate_meta.mjs | 55 ++++++++++++++++++++++++++++++++++++++++++ docs/package.json | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 docs/generate_meta.mjs diff --git a/docs/generate_meta.mjs b/docs/generate_meta.mjs new file mode 100644 index 0000000..ec0212e --- /dev/null +++ b/docs/generate_meta.mjs @@ -0,0 +1,55 @@ +import fetch from 'node-fetch'; +import fs from 'fs'; + +// Fetch version value fromy yaml file https://raw.githubusercontent.com/LinwoodDev/Qeck/nightly/app/pubspec.yaml +const nightlyUrl = 'https://raw.githubusercontent.com/LinwoodDev/Qeck/nightly/app/pubspec.yaml'; +const nightlyVersion = await fetch(nightlyUrl).then(res => res.text()).then(text => { + const regex = /^version:\s(.+)\+(.+)$/gm; + const match = regex.exec(text); + return match[1]; +} +); + +// stable +const stableUrl = 'https://raw.githubusercontent.com/LinwoodDev/Qeck/stable/app/pubspec.yaml'; +const stableVersion = await fetch(stableUrl).then(res => res.text()).then(text => { + const regex = /^version:\s(.+)\+(.+)$/gm; + const match = regex.exec(text); + return match[1]; +} +); + +// develop +const developUrl = 'https://raw.githubusercontent.com/LinwoodDev/Qeck/develop/app/pubspec.yaml'; +const developVersion = await fetch(developUrl).then(res => res.text()).then(text => { + const regex = /^version:\s(.+)\+(.+)$/gm; + const match = regex.exec(text); + return match[1]; +} +); + +// main +const mainUrl = 'https://raw.githubusercontent.com/LinwoodDev/Qeck/main/app/pubspec.yaml'; +const mainVersion = await fetch(mainUrl).then(res => res.text()).then(text => { + const regex = /^version:\s(.+)\+(.+)$/gm; + const match = regex.exec(text); + return match[1]; +} +); + +// Write nightly and stable version to meta.json +const meta = { + version: { + nightly: nightlyVersion, + stable: stableVersion, + develop: developVersion, + main: mainVersion, + } +}; + +// Write to static/meta.json +const metaPath = 'static/meta.json'; +// Create meta.json if it doesn't exist +if (!fs.existsSync(metaPath)) { + fs.writeFileSync(metaPath, JSON.stringify(meta)); +} \ No newline at end of file diff --git a/docs/package.json b/docs/package.json index 45c64af..1fd81cd 100644 --- a/docs/package.json +++ b/docs/package.json @@ -7,7 +7,7 @@ "start": "docusaurus start", "build:meta": "node ./generate_meta.mjs", "build:docs": "docusaurus build", - "build": "yarn build:meta && yarn build:docs", + "build": "yarn build:docs", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "clear": "docusaurus clear",