Skip to content

Commit

Permalink
Add generate meta
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed May 9, 2023
1 parent 613d1ce commit 07cfd71
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions docs/generate_meta.mjs
Original file line number Diff line number Diff line change
@@ -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));
}
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 07cfd71

Please sign in to comment.