-
Notifications
You must be signed in to change notification settings - Fork 3
/
buildSyntaxes.js
49 lines (46 loc) · 1.36 KB
/
buildSyntaxes.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
const fs = require('fs');
const https = require('https');
const path = require('path');
const rawdata = fs.readFileSync('syntaxes.json');
const syntaxes = JSON.parse(rawdata);
const languages = [
"interface IGrammarPath {",
" [key: string]: string;",
"}",
"",
"export const grammarPaths: IGrammarPath = {",
];
for (syntax of syntaxes) {
const url = 'https://raw.githubusercontent.com/Microsoft/vscode/master/extensions/' + syntax.path;
const basefile = path.basename(syntax.path);
const id = syntax.id;
console.log(basefile);
languages.push(` \'${id}\': \'${basefile}\',`);
download(url).then(content => {
try {
fs.writeFileSync(path.join('src/syntaxes', basefile), content);
}catch(e){
console.log(e);
}
});
}
languages.push("};")
fs.writeFileSync('src/languages.ts', languages.join("\n"));
function download(url) {
return new Promise((c, e) => {
var content = '';
https.get(url, function (response) {
response.on('data', function (data) {
content += data.toString();
}).on('end', function () {
if (response.statusCode === 403 && response.headers['x-ratelimit-remaining'] === '0') {
e('GitHub API rate exceeded. Set GITHUB_TOKEN environment variable to increase rate limit.');
return;
}
c(content);
});
}).on('error', function (err) {
e(err.message);
});
});
}