Skip to content

Commit bad5eda

Browse files
committed
Cleanup fetch windows permissions script
1 parent c07338c commit bad5eda

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

Diff for: fetchWindowsCapabilites.js

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,57 @@
11
// Fetch list of Windows UWP App capabilites from the Microsoft docs
2-
//
3-
// The names of individual capabilites are in <strong> tag and follow cammelCase
2+
// The names of individual capabilites are in <strong> tag and follow camelCase
43

54
const https = require('https');
5+
const {EOL} = require('os');
66

77
https.get(
88
'https://docs.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations',
99
(res) => {
1010
res.setEncoding('utf8');
11+
1112
let data = '';
13+
14+
res.on('error', ({message}) => {
15+
console.error(message);
16+
process.exit(-1);
17+
});
18+
1219
res.on('data', (chunk) => {
1320
data += chunk;
1421
});
15-
res.on('end', () => {
16-
parsePage(data);
17-
});
18-
res.on('error', (e) => {
19-
console.error(`Got error: ${e.message}`);
20-
process.exit(-1);
21-
});
22+
23+
res.on('end', () => parse(data));
2224
},
2325
);
2426

25-
function parsePage(data) {
27+
function parse(data) {
2628
const names = new Set();
29+
2730
for (const match of data.match(/<strong>[a-z]+[a-zA-Z\.]*<\/strong>/gm)) {
2831
names.add(
2932
match.substr('<strong>'.length, match.length - '<strong>'.length - '</strong>'.length),
3033
);
3134
}
35+
3236
const results = [];
37+
3338
for (const name of names) {
3439
let constName = '';
40+
3541
for (let i = 0; i < name.length; ++i) {
3642
const char = name.charAt(i);
37-
if (char === char.toUpperCase()) constName += '_';
43+
44+
if (char === char.toUpperCase()) {
45+
constName += '_';
46+
}
47+
3848
constName += char.toUpperCase();
3949
}
50+
4051
constName = constName.replace('WI_FI', 'WIFI');
4152
constName = constName.replace('VO_I_P', 'VOIP');
42-
results.push(` ${constName}: 'windows.permission.${name}' as const,`);
53+
results.push(`${constName}: 'windows.permission.${name}',`);
4354
}
44-
const sorted = results.sort();
45-
for (const name of sorted) console.log(name);
55+
56+
console.log(results.sort().join(EOL));
4657
}

0 commit comments

Comments
 (0)