|
1 | 1 | // 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 |
4 | 3 |
|
5 | 4 | const https = require('https');
|
| 5 | +const {EOL} = require('os'); |
6 | 6 |
|
7 | 7 | https.get(
|
8 | 8 | 'https://docs.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations',
|
9 | 9 | (res) => {
|
10 | 10 | res.setEncoding('utf8');
|
| 11 | + |
11 | 12 | let data = '';
|
| 13 | + |
| 14 | + res.on('error', ({message}) => { |
| 15 | + console.error(message); |
| 16 | + process.exit(-1); |
| 17 | + }); |
| 18 | + |
12 | 19 | res.on('data', (chunk) => {
|
13 | 20 | data += chunk;
|
14 | 21 | });
|
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)); |
22 | 24 | },
|
23 | 25 | );
|
24 | 26 |
|
25 |
| -function parsePage(data) { |
| 27 | +function parse(data) { |
26 | 28 | const names = new Set();
|
| 29 | + |
27 | 30 | for (const match of data.match(/<strong>[a-z]+[a-zA-Z\.]*<\/strong>/gm)) {
|
28 | 31 | names.add(
|
29 | 32 | match.substr('<strong>'.length, match.length - '<strong>'.length - '</strong>'.length),
|
30 | 33 | );
|
31 | 34 | }
|
| 35 | + |
32 | 36 | const results = [];
|
| 37 | + |
33 | 38 | for (const name of names) {
|
34 | 39 | let constName = '';
|
| 40 | + |
35 | 41 | for (let i = 0; i < name.length; ++i) {
|
36 | 42 | const char = name.charAt(i);
|
37 |
| - if (char === char.toUpperCase()) constName += '_'; |
| 43 | + |
| 44 | + if (char === char.toUpperCase()) { |
| 45 | + constName += '_'; |
| 46 | + } |
| 47 | + |
38 | 48 | constName += char.toUpperCase();
|
39 | 49 | }
|
| 50 | + |
40 | 51 | constName = constName.replace('WI_FI', 'WIFI');
|
41 | 52 | constName = constName.replace('VO_I_P', 'VOIP');
|
42 |
| - results.push(` ${constName}: 'windows.permission.${name}' as const,`); |
| 53 | + results.push(`${constName}: 'windows.permission.${name}',`); |
43 | 54 | }
|
44 |
| - const sorted = results.sort(); |
45 |
| - for (const name of sorted) console.log(name); |
| 55 | + |
| 56 | + console.log(results.sort().join(EOL)); |
46 | 57 | }
|
0 commit comments