@bbc/morty-docs 2.0.0 → 3.0.1
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/README.md +1 -1
- package/build/generate-transform-input.js +47 -8
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,15 +1,54 @@
|
|
|
1
|
-
const readdir = require('recursive-readdir');
|
|
2
1
|
const fs = require('fs');
|
|
3
2
|
const path = require('path');
|
|
4
3
|
const generateTransformInput = dir => {
|
|
5
4
|
dir = path.format(path.parse(dir));
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
raw: fs.readFileSync(file)
|
|
11
|
-
};
|
|
12
|
-
});
|
|
5
|
+
let list = [];
|
|
6
|
+
const files = fs.readdirSync(dir, {
|
|
7
|
+
recursive: true,
|
|
8
|
+
withFileTypes: true
|
|
13
9
|
});
|
|
10
|
+
// recursive option available from node 18+
|
|
11
|
+
// when options.withFileTypes set to true, the returned array will contain <fs.Dirent> objects.
|
|
12
|
+
for (const dirent of files) {
|
|
13
|
+
// Node API for Dirent is unstable
|
|
14
|
+
const dirPath = dirent.path || dirent.parentPath; // path is DEPRECATED! But parentPath does not work in 18.17
|
|
15
|
+
|
|
16
|
+
const fullPath = path.join(dirPath, dirent.name);
|
|
17
|
+
// console.log('fullPath = ', fullPath)
|
|
18
|
+
|
|
19
|
+
if (dirent.isDirectory()) {
|
|
20
|
+
console.log('directory... continue');
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (dirent.isFile()) {
|
|
24
|
+
list.push(makeInputObject(fullPath, dir));
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (dirent.isSymbolicLink) {
|
|
28
|
+
if (fs.existsSync(fullPath)) {
|
|
29
|
+
// fs.exists() is deprecated, but fs.existsSync() is not.
|
|
30
|
+
const stats = fs.statSync(fullPath);
|
|
31
|
+
console.log('Good symlink');
|
|
32
|
+
if (stats.isFile()) {
|
|
33
|
+
// get file details
|
|
34
|
+
list.push(makeInputObject(fullPath, dir)); // symlinks become copies
|
|
35
|
+
} else {
|
|
36
|
+
// recursive call to get all files in the symlinked directory
|
|
37
|
+
const newlist = generateTransformInput(fullPath);
|
|
38
|
+
list = list.concat(newlist);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
console.log(`Broken symlink at: ${fullPath}`);
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return list;
|
|
47
|
+
};
|
|
48
|
+
const makeInputObject = (fullPath, rootPath) => {
|
|
49
|
+
return {
|
|
50
|
+
relativePath: fullPath.replace(`${rootPath}/`, ''),
|
|
51
|
+
raw: fs.readFileSync(fullPath, 'utf-8')
|
|
52
|
+
};
|
|
14
53
|
};
|
|
15
54
|
module.exports = generateTransformInput;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bbc/morty-docs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "To generate a static website from markdown documentation, to allow users to consume content in an easily accessible format",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"markdown"
|
|
32
32
|
],
|
|
33
33
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
34
|
+
"node": ">=18.x",
|
|
35
|
+
"npm": ">=8.x"
|
|
35
36
|
},
|
|
36
37
|
"author": "BBC",
|
|
37
38
|
"license": "Apache-2.0",
|