@apify/docs-theme 1.0.43 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/docs-theme",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -0,0 +1,31 @@
1
+ function updateChangelog(changelog) {
2
+ changelog = addHeader(changelog);
3
+ changelog = pushHeadings(changelog);
4
+ changelog = linkUsers(changelog);
5
+ changelog = linkPRs(changelog);
6
+ return changelog;
7
+ }
8
+
9
+ function addHeader(changelog, header = 'Changelog') {
10
+ return `---
11
+ title: ${header}
12
+ sidebar_label: ${header}
13
+ ---
14
+ ${changelog}`;
15
+ }
16
+
17
+ function pushHeadings(changelog) {
18
+ return changelog.replaceAll(/\n#[^#]/g, '\n## ');
19
+ }
20
+
21
+ function linkUsers(changelog) {
22
+ return changelog.replaceAll(/@([a-zA-Z0-9-]+)/g, '[@$1](https://github.com/$1)');
23
+ }
24
+
25
+ function linkPRs(changelog) {
26
+ return changelog.replaceAll(/(((https?:\/\/)?(www.)?)?github.com\/[^\s]*?\/pull\/([0-9]+))/g, '[#$5]($1)');
27
+ }
28
+
29
+ module.exports = {
30
+ updateChangelog,
31
+ };
package/src/theme.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
  const axios = require('axios');
4
+ const { updateChangelog } = require('./markdown');
4
5
 
5
6
  function findPathInParent(endPath) {
6
7
  let parentPath = __dirname;
@@ -21,17 +22,6 @@ function findPathInParentOrThrow(endPath) {
21
22
  return filePath;
22
23
  }
23
24
 
24
- function updateChangelog(changelogPath) {
25
- const changelog = fs.readFileSync(changelogPath, 'utf-8');
26
- const updated = `---
27
- title: Changelog
28
- sidebar_label: Changelog
29
- ---
30
-
31
- ${changelog.replaceAll(/\n#[^#]/g, '\n## ')}`;
32
- fs.writeFileSync(changelogPath, updated, 'utf-8');
33
- }
34
-
35
25
  async function copyChangelogFromReleases(paths, repo) {
36
26
  const response = await axios.get(`https://api.github.com/repos/${repo}/releases`);
37
27
  const releases = response.data;
@@ -39,16 +29,15 @@ async function copyChangelogFromReleases(paths, repo) {
39
29
  let markdown = '';
40
30
  if (!Array.isArray(releases) || releases.length === 0) return;
41
31
 
42
- releases.forEach((release, i, a) => {
43
- markdown += release.tag_name && a[i + 1]?.tag_name
44
- ? `## [${release.name}](https://github.com/${repo}/compare/${a[i + 1].tag_name}...${release.tag_name})\n`
32
+ releases.forEach((release) => {
33
+ markdown += release.tag_name
34
+ ? `## [${release.name}](https://github.com/${repo}/releases/tag/${release.tag_name})\n`
45
35
  : `## ${release.name}\n`;
46
36
  markdown += `${release.body.replaceAll(/(^##|\n##)/g, '###')}\n`;
47
37
  });
48
38
 
49
39
  paths.forEach((p) => {
50
- fs.writeFileSync(`${p}/changelog.md`, markdown);
51
- updateChangelog(`${p}/changelog.md`);
40
+ fs.writeFileSync(`${p}/changelog.md`, updateChangelog(markdown));
52
41
  });
53
42
  }
54
43
 
@@ -58,8 +47,8 @@ function copyChangelogFromRoot(paths) {
58
47
  for (const docsPath of paths) {
59
48
  if (fs.existsSync(path.join(docsPath, 'changelog.md')) && fs.statSync(
60
49
  path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime) continue;
61
- fs.copyFileSync(changelogPath, path.join(docsPath, 'changelog.md'));
62
- updateChangelog(path.join(docsPath, 'changelog.md'));
50
+ const changelog = fs.readFileSync(changelogPath, 'utf-8');
51
+ fs.writeFileSync(`${docsPath}/changelog.md`, updateChangelog(changelog));
63
52
  }
64
53
  }
65
54