-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathcheck-version-conventions.ts
47 lines (38 loc) · 1.25 KB
/
check-version-conventions.ts
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
/* eslint-disable no-console */
import fs from 'fs';
import path from 'path';
import {isVersioned} from '../src/versioning';
function checkVersionConventions(dir: string): string[] {
let faultyFiles: string[] = [];
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
faultyFiles = faultyFiles.concat(checkVersionConventions(filePath));
} else {
if (isVersioned(filePath)) {
const versionPattern = /^.*__v\d+\.x\.mdx$|^.*__v\d+\.\d+\.\d+\.mdx$/;
const basename = path.basename(filePath);
if (!versionPattern.test(basename)) {
faultyFiles.push(filePath);
}
}
}
}
return faultyFiles;
}
const rootDir = 'docs';
const faultyFiles = checkVersionConventions(rootDir);
if (faultyFiles.length > 0) {
console.error(
'Error: The following files do not follow the correct versioning convention:'
);
faultyFiles.forEach(file => console.error(` ${file}`));
console.error(
'Versioned files should end with __v{MAJOR}.x.mdx or __v{MAJOR}.{MINOR}.{PATCH}.mdx'
);
process.exit(1);
} else {
console.log('✅ All files follow the correct versioning convention.');
}