@apify/docs-theme 1.0.24 → 1.0.25

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/theme.js +26 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/docs-theme",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
package/src/theme.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
 
4
- function findPathToParent(endPath) {
4
+ function findPathInParent(endPath) {
5
5
  let parentPath = __dirname;
6
6
  while (parentPath !== path.join(parentPath, '..')) {
7
7
  const filePath = path.join(parentPath, endPath);
@@ -11,7 +11,13 @@ function findPathToParent(endPath) {
11
11
  const filePath = path.join(parentPath, endPath);
12
12
  if (fs.existsSync(filePath)) return filePath;
13
13
 
14
- throw new Error('Could not find CHANGELOG.md in any parent directory');
14
+ return false;
15
+ }
16
+
17
+ function findPathInParentOrThrow(endPath) {
18
+ const filePath = findPathInParent(endPath);
19
+ if (!filePath) throw new Error(`Could not find ${endPath} in any parent directory`);
20
+ return filePath;
15
21
  }
16
22
 
17
23
  function updateChangelog(changelogPath) {
@@ -40,13 +46,24 @@ function theme(
40
46
  },
41
47
  async loadContent() {
42
48
  try {
43
- const docsPath = findPathToParent('docs');
44
- const changelogPath = findPathToParent('CHANGELOG.md');
45
- if (fs.existsSync(path.join(docsPath, 'changelog.md') || fs.statSync(
46
- path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime,
47
- )) return;
48
- fs.copyFileSync(changelogPath, path.join(docsPath, 'changelog.md'));
49
- updateChangelog(path.join(docsPath, 'changelog.md'));
49
+ const changelogPath = findPathInParentOrThrow('CHANGELOG.md');
50
+ const versioned = findPathInParent('website/versioned_docs');
51
+
52
+ const pathsToCopyChangelog = [
53
+ findPathInParentOrThrow('docs'),
54
+ ...(versioned
55
+ ? fs.readdirSync(versioned).map((version) => path.join(versioned, version))
56
+ : []
57
+ ),
58
+ ];
59
+
60
+ for (const docsPath of pathsToCopyChangelog) {
61
+ if (fs.existsSync(path.join(docsPath, 'changelog.md')) && fs.statSync(
62
+ path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime) continue;
63
+ fs.copyFileSync(changelogPath, path.join(docsPath, 'changelog.md'));
64
+ console.log(`copied ${changelogPath} to ${path.join(docsPath, 'changelog.md')}`);
65
+ updateChangelog(path.join(docsPath, 'changelog.md'));
66
+ }
50
67
  } catch (e) {
51
68
  console.warn(`Changelog page could not be initialized: ${e.message}`);
52
69
  }