From 7899eac40ba7b12c58e72529f444b9cb4e4c5bc7 Mon Sep 17 00:00:00 2001 From: Thibaut DAVID Date: Wed, 23 Aug 2023 14:18:59 +0200 Subject: [PATCH] chore(docs): improves docs release script --- package.json | 2 +- scripts/beforeRelease.js | 26 +++++++------------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 2850f14..5a2c755 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "test": "run-s build lint test:unit", "test:unit": "jest", "commit": "git-cz", - "docs:release": "dotenv node ./scripts/beforeRelease.js", + "docs:release": "node ./scripts/beforeRelease.js", "release": "dotenv release-it --", "prepare": "rollup -c" }, diff --git a/scripts/beforeRelease.js b/scripts/beforeRelease.js index c933370..b9a36ce 100644 --- a/scripts/beforeRelease.js +++ b/scripts/beforeRelease.js @@ -1,31 +1,19 @@ #!/usr/bin/node -const axios = require("axios"); -const { writeFileSync } = require("fs"); +const { writeFileSync, readFileSync } = require("fs"); const { join } = require("path"); const { execSync } = require("child_process"); +const CHANGELOG_PATH = join(__dirname, "..", "CHANGELOG.md"); const RELEASES_PATH = join(__dirname, "..", "docs", "content", "4.releases.md"); +const VERSION_REGEX = /\[(.*?)\]\(.*?\) \(.*?\)/g; + async function main() { try { - const response = await axios.request( - `https://api.github.com/repos/Stun3R/strapi-sdk-js/releases`, - { - headers: { - Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, - }, - } - ); - - const releases = response.data.reduce((acc, cur) => { - const name = `## ${cur.name}`; - const body = cur.body.replace(/###/g, "####"); - - acc += `${name}\r\n\r\n${body}\r\n\r\n`; + const file = readFileSync(CHANGELOG_PATH, "utf-8"); - return acc; - }, ""); + releases = file.replace(VERSION_REGEX, "v$1").replace(/###/g, "####"); writeFileSync(RELEASES_PATH, `# Releases\r\n\r\n${releases}`, { flag: "w+", @@ -33,7 +21,7 @@ async function main() { execSync(`git add ${RELEASES_PATH}`); - console.log("Successfully generated the releases page."); + console.log("✨ Successfully generated the releases page."); } catch (error) { console.error(error); }