-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathgenerate_ssr_urls.mjs
88 lines (78 loc) · 1.82 KB
/
generate_ssr_urls.mjs
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { readdir, readFile, writeFile } from "node:fs/promises";
import { parse, latestEcmaVersion } from "espree";
import { traverse, Syntax } from "estraverse";
import { extname, join } from "path";
const folders = [
{
folder: "store.steampowered.com/ssr",
cdn: "https://cdn.fastly.steamstatic.com/store/ssr/",
},
];
const languages = [
"_arabic-",
"_brazilian-",
"_bulgarian-",
"_czech-",
"_danish-",
"_dutch-",
"_finnish-",
"_french-",
"_german-",
"_greek-",
"_hungarian-",
"_indonesian-",
"_italian-",
"_japanese-",
"_korean-",
"_koreana-",
"_latam-",
"_norwegian-",
"_polish-",
"_portuguese-",
"_romanian-",
"_russian-",
"_sc_schinese-",
"_schinese-",
"_spanish-",
"_swedish-",
"_tchinese-",
"_thai-",
"_turkish-",
"_ukrainian-",
"_vietnamese-",
];
const languagePattern = new RegExp(languages.join("|"));
const urls = new Set();
for (const { folder, cdn } of folders) {
const files = (await readdir(folder)).filter((file) => extname(file).toLowerCase() === ".js");
for (const file of files) {
try {
const code = await readFile(join(folder, file));
const ast = parse(code, {
ecmaVersion: latestEcmaVersion,
sourceType: "module",
});
traverse(ast, {
enter: function (node) {
if (
(node.type === Syntax.ImportDeclaration || node.type === Syntax.ImportExpression) &&
node.source.type === Syntax.Literal
) {
const file = node.source.value;
if (!languagePattern.test(file)) {
const url = new URL(cdn);
url.pathname += file;
urls.add(url.toString());
}
}
},
});
} catch (e) {
console.error(`Unable to parse "${file}": ${e}`);
continue;
}
}
}
console.log("Found", urls.size, "SSR urls");
const strings = [...urls.values()].sort().join("\n") + "\n";
await writeFile(".support/urls_from_ssr.txt", strings);