-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclean-translations.js
41 lines (34 loc) · 1.28 KB
/
clean-translations.js
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
import { translations, exclusionRegex } from './translations.js';
import { exec } from 'child_process';
import * as fs from 'fs';
function getModifiedFiles() {
return new Promise((resolve, reject) => {
exec('git ls-files -m', (error, stdout, stderr) => {
if (error) {
reject(error);
} else {
const modifiedFiles = stdout
.trim()
.split('\n')
.filter(line => !exclusionRegex.test(line))
.filter(line => line.startsWith('docs/'))
.filter(line => line.endsWith('.md') || line.endsWith('.yml'));
resolve(modifiedFiles);
}
});
});
}
getModifiedFiles().then(modifiedFiles => {
const availableTranslations = Object.values(translations);
for (const modifiedFile of modifiedFiles) {
for (const translationKey of availableTranslations) {
const traslationPath = modifiedFile.replace("docs/", `docs/${translationKey}/`);
if (fs.existsSync(traslationPath)) {
console.log(`Removing ${traslationPath}`);
fs.unlinkSync(traslationPath);
}
}
}
}).catch(error => {
console.error('Error: ', error);
});