-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-readme.mjs
66 lines (52 loc) · 1.93 KB
/
patch-readme.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import fs from 'fs';
import path from 'path';
const patchFile = (filePath) => {
const content = fs.readFileSync(filePath, 'utf8');
let newContent = content;
// Insert header for main readme files
if(filePath.endsWith('README.md'))
{
newContent = `<p align="center">
<a href="https://www.intuiface.com">
<img src="https://assets-global.website-files.com/6090f790a8effe00c12b39d0/6090f790a8effef0002b3c56_Intuiface%20logo%20animated.gif" alt="Intuiface logo" width="200" height="86">
</a>
</p>
${newContent}`;
}
// Removes returns part of decorator that are detected as functions
newContent = newContent.replaceAll(/#### returns\n\n`fn`[\w\W\s]+?##### Returns\n\n`(void|any)`/gmi, '');
// Insert help footer
newContent += `\n\n## Help
Found a problem, a bug? Or need some help?
Please do not create an issue in Github! Ask us via our Support page : https://support.intuiface.com/`
fs.writeFileSync(filePath, newContent);
return content !== newContent;
};
const processDirectory = (dirPath) => {
const files = fs.readdirSync(dirPath);
for (const file of files) {
const filePath = path.join(dirPath, file);
if (fs.statSync(filePath).isDirectory()) {
// Recurse into subdirectories
processDirectory(filePath);
} else if (filePath.endsWith('.md')) {
// Process .md files
const patched = patchFile(filePath);
if (patched) {
console.log(`\x1b[32m✔\x1b[0m Patched file ${filePath}`);
}
}
}
};
const args = process.argv.slice(2);
if (args.length !== 1) {
console.error('Usage: node patch-readme.mjs <directory-path>');
process.exit(1);
}
const directoryPath = args[0];
if (!fs.existsSync(directoryPath)) {
console.error('Directory not found.');
process.exit(1);
}
console.log('\nPatching documentation files...');
processDirectory(directoryPath);