Skip to content

Commit

Permalink
chore(docs): improves docs release script
Browse files Browse the repository at this point in the history
  • Loading branch information
Stun3R committed Aug 23, 2023
1 parent 761781a commit 7899eac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
26 changes: 7 additions & 19 deletions scripts/beforeRelease.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
#!/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+",
});

execSync(`git add ${RELEASES_PATH}`);

console.log("Successfully generated the releases page.");
console.log("Successfully generated the releases page.");
} catch (error) {
console.error(error);
}
Expand Down

0 comments on commit 7899eac

Please sign in to comment.