-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (39 loc) · 1.11 KB
/
index.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
const core = require('@actions/core');
const fs = require('fs');
const recursive = require('recursive-readdir');
try {
const localisationFolder = core.getInput('localisation_folder');
console.log(`Fixing locs in: ${localisationFolder}`);
recursive(localisationFolder, ['!*.yml'], (err, files) => {
if (err) {
throw err;
}
console.log(files);
for (const file of files) {
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
throw err;
}
const language = file.replace('.yml', ':').slice(file.indexOf('l_'));
console.log(language);
let content;
if (file.endsWith('_l_english.yml')) {
content = data.replace('\ufeff', '');
} else {
content = data
.replace('l_english:', '')
.replace('---', language)
.replace('\ufeff', '');
}
fs.writeFile(file, `\ufeff${content}`, 'utf8', (err) => {
if (err) {
throw err;
}
console.log(`Fixed ${file}`);
});
});
}
});
} catch (error) {
core.setFailed(error.message);
}