-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild-resx.js
71 lines (52 loc) · 2.03 KB
/
build-resx.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
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
67
68
69
70
const fs = require('fs');
const path = require('path');
const {create} = require('xmlbuilder2');
const basePath = 'crowdin';
const outputFilename = 'docs.en.resx';
const filesToProcessExt = '.html.md'
const mappings = {
'adguard-mail.com': 'legal-github-docs-mail',
'adguard.com': 'legal-github-docs-adguard',
'adguard-dns.io': 'legal-github-docs-dns',
'adguard-vpn.com': 'legal-github-docs-vpn',
'adguardpartner.com': 'legal-github-docs-aff',
};
console.log('Starting document processing...');
if (!fs.existsSync(basePath)) {
console.log(`Creating output directory: ${basePath}`);
fs.mkdirSync(basePath);
}
for (const [sourceDir, crowdinDir] of Object.entries(mappings)) {
console.log(`\nProcessing directory: ${sourceDir} -> ${crowdinDir}`);
if (!fs.existsSync(sourceDir)) {
console.log(`Skipping ${sourceDir} - directory does not exist`);
continue;
}
const mdFiles = fs.readdirSync(sourceDir, {recursive: true})
.filter(file => file.endsWith(filesToProcessExt));
console.log(`Found ${mdFiles.length} files to process`);
let xmlBuilder = create({version: '1.0', encoding: 'utf-8'}).ele('root');
for (const filePath of mdFiles) {
console.log(`Processing file: ${filePath}`);
const content = fs.readFileSync(path.join(sourceDir, filePath), 'utf8');
const key = filePath
.replace(filesToProcessExt, '')
.replaceAll('/', '.');
console.log(`Generated key: ${key}`);
xmlBuilder = xmlBuilder.ele('data').att('name', key)
.ele('value').dat(content).up()
.up()
}
const resxContent = xmlBuilder.end({
prettyPrint: true,
indent: ' ',
});
const outputDir = path.join(basePath, crowdinDir);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
const outputPath = path.join(outputDir, outputFilename);
console.log(`Writing output to: ${outputPath}`);
fs.writeFileSync(outputPath, resxContent);
}
console.log('\nProcessing complete!');