docs: show latest version in docs + update automatically (#9753)

This commit is contained in:
Shahed Nasser
2024-10-24 14:03:34 +03:00
committed by GitHub
parent 669adbcdc9
commit 04cec64fa1
14 changed files with 232 additions and 1 deletions

View File

@@ -0,0 +1,81 @@
#!/usr/bin/env node
import { Octokit } from "@octokit/core"
import fs from "fs"
import path from "path"
import { fileURLToPath } from "url"
const octokit = new Octokit({
auth: process.env.GH_TOKEN,
})
type DocsConfig = {
version: {
number: string
releaseUrl: string
}
}
function getConfigPath() {
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
return path.join(
__dirname,
"..",
"..",
"..",
"..",
"packages",
"docs-ui",
"src",
"global-config.ts"
)
}
const configFilePrefix = `/* eslint-disable comma-dangle */
/* eslint-disable prettier/prettier */
import { DocsConfig } from "types"
export const globalConfig: Pick<DocsConfig, "version"> = `
async function main() {
//retrieve the latest release
const response = await octokit.request(
"GET /repos/{owner}/{repo}/releases/latest",
{
owner: "medusajs",
repo: "medusa",
sha: "develop",
}
)
const version = response.data.tag_name.replace(/\.0$/, "").replace(/^v/, "")
// get the existing version
const configPath = getConfigPath()
const configContent = fs
.readFileSync(configPath, "utf-8")
.replace(configFilePrefix, "")
const oldConfig: DocsConfig = JSON.parse(configContent)
if (oldConfig.version.number === version) {
return
}
//add new announcement
const config: DocsConfig = {
version: {
number: version,
releaseUrl: response.data.html_url,
},
}
//write new config file
fs.writeFileSync(
configPath,
`${configFilePrefix}${JSON.stringify(config, undefined, 2)}`
)
console.log(`Version in config has been updated.`)
}
void main()

View File

@@ -7,11 +7,13 @@
},
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"check:freshness": "node ./dist/freshness-check.js",
"generate:message": "node ./dist/get-generate-diff-message.js",
"check:release-commit": "node ./dist/check-release-commit.js",
"generate:changeset": "node ./dist/run-changeset.js",
"check:pr-files-count": "node ./dist/check-pr-files-count.js"
"check:pr-files-count": "node ./dist/check-pr-files-count.js",
"update:config-version": "node ./dist/change-config-version.js"
},
"version": "0.0.0",
"type": "module",