Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Решает проблемы #5456 #5461

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 76 additions & 39 deletions .github/scripts/update-changelog.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
const fs = require("fs");

const addedContent = fs
.readFileSync("added-content.txt")
.toString()
.split("\n");

if (
addedContent.length === 0 ||
(addedContent.length > 0 && addedContent[0] === "")
) {
return;
}

const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const monthNames = [
"Январь",
"Февраль",
"Март",
"Апрель",
"Май",
"Июнь",
"Июль",
"Август",
"Сентябрь",
"Октябрь",
"Ноябрь",
"Декабрь",
];
const currentMonth = monthNames[currentDate.getMonth()];
const header = `## ${currentMonth} ${currentYear}`;

const contentList = addedContent.map((fileName) => {
function extractInfo(fileName) {
if (fs.existsSync(fileName)) {
const url = `https://doka.guide/${fileName.replace("index.md", "")}`;
const date = process.argv[2];
Expand All @@ -50,6 +19,7 @@ const contentList = addedContent.map((fileName) => {
.split("\n")
.slice(1, -1)
.map((s) => s.replace(" - ", ""))
.filter((a) => a !== 'doka-dog')
.map((a) => {
const authorFileName = `./people/${a}/index.md`;
if (fs.existsSync(authorFileName)) {
Expand All @@ -65,23 +35,90 @@ const contentList = addedContent.map((fileName) => {

return `- ${date}, [${title}](${url}), ${authors.join(", ")}`;
}
});
return null;
}

const changelogFileName = "./CHANGELOG.md";

const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const monthNames = [
"Январь",
"Февраль",
"Март",
"Апрель",
"Май",
"Июнь",
"Июль",
"Август",
"Сентябрь",
"Октябрь",
"Ноябрь",
"Декабрь",
];
const currentMonth = monthNames[currentDate.getMonth()];
const header = `## ${currentMonth} ${currentYear}`;

const addedContent = fs
.readFileSync("added-content.txt")
.toString()
.split("\n");

if (
addedContent.length === 0 ||
(addedContent.length > 0 && addedContent[0] === "")
) {
return;
}

const addedContentList = addedContent.map((fileName) => extractInfo(fileName));

if (addedContentList.length > 0) {
if (fs.existsSync(changelogFileName)) {
const changelog = fs.readFileSync(changelogFileName).toString().split("\n");
if (changelog.filter((s) => s.startsWith("## ")).includes(header)) {
const headerPosition = changelog.findIndex((s) => s === header);
changelog.splice(headerPosition + 2, 0, ...addedContentList);
} else {
const headerPosition = 4;
changelog.splice(headerPosition, 0, ...[header, "", ""]);
changelog.splice(headerPosition + 2, 0, ...addedContentList);
}
fs.writeFileSync(changelogFileName, changelog.join("\n"));
console.log("Новые материалы добавлены в CHANGELOG.md");
}
} else {
console.log("Нечего добавлять из списка новых материалов в CHANGELOG.md");
}

const updatedContent = fs
.readFileSync("updated-content.txt")
.toString()
.split("\n");

if (
updatedContent.length === 0 ||
(updatedContent.length > 0 && updatedContent[0] === "")
) {
return;
}

const updatedContentList = updatedContent.map((fileName) => extractInfo(fileName));

if (contentList.length > 0) {
const changelogFileName = "./CHANGELOG.md";
if (updatedContentList.length > 0) {
if (fs.existsSync(changelogFileName)) {
const changelog = fs.readFileSync(changelogFileName).toString().split("\n");
if (changelog.filter((s) => s.startsWith("## ")).includes(header)) {
const headerPosition = changelog.findIndex((s) => s === header);
changelog.splice(headerPosition + 2, 0, ...contentList);
changelog.splice(headerPosition + 2, 0, ...updatedContentList);
} else {
const headerPosition = 4;
changelog.splice(headerPosition, 0, ...[header, "", ""]);
changelog.splice(headerPosition + 2, 0, ...contentList);
changelog.splice(headerPosition + 2, 0, ...updatedContentList);
}
fs.writeFileSync(changelogFileName, changelog.join("\n"));
console.log("Записи добавлены в CHANGELOG.md");
console.log("Бывшие плейсхолдеры добавлены в CHANGELOG.md");
}
} else {
console.log("Нечего добавлять в CHANGELOG.md");
console.log("Нечего добавлять из списка бывших плейсхолдеров в CHANGELOG.md");
}
2 changes: 2 additions & 0 deletions .github/scripts/update-changelog.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
git diff --name-status HEAD^ HEAD | grep '^A' | grep -E '(html|css|js|tools|a11y|recipes)\/.*\/index\.md' | sed 's/^A\t//g' > added-content.txt
git diff -S"placeholder" --name-status HEAD^ HEAD | grep '^M' | grep -E '(html|css|js|tools|a11y|recipes)\/.*\/index\.md' | sed 's/^M\t//g' > updated-content.txt

if [ -s added-content.txt ]; then
MONTH_TO_RUS() {
Expand Down Expand Up @@ -28,6 +29,7 @@ if [ -s added-content.txt ]; then
node .github/scripts/update-changelog.js "$FORMATTED_DATE"

rm -f added-content.txt
rm -f updated-content.txt

if [[ -z $(git status -s) ]]
then
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
## Июль 2024

- 23 июля, [Слайдер](https://doka.guide/recipes/slider/), Анна Бараулина

- 22 июля, [Стилизация чекбоксов и радиокнопок](https://doka.guide/recipes/checkbox-radio-style/), Михаил Кривдин
- 19 июля, [`.isSubsetOf()`](https://doka.guide/js/set-is-subset-of/), Viktar Nezhbart
- 19 июля, [`.intersection()`](https://doka.guide/js/set-intersection/), Viktar Nezhbart
- 19 июля, [`.difference()`](https://doka.guide/js/set-difference/), Viktar Nezhbart
- 16 июля, [`Atomics`](https://doka.guide/js/atomics/), Всеволод Золотов
- 12 июля, [`.union()`](https://doka.guide/js/set-union/), Viktar Nezhbart
- 1 июля, [`.symmetricDifference()`](https://doka.guide/js/set-symmetric-difference/), Viktar Nezhbart

Expand Down
Loading