-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
109 lines (103 loc) · 3.7 KB
/
Copy pathindex.js
File metadata and controls
109 lines (103 loc) · 3.7 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// file should be a string
function parseFilename(file, version) {
const info = {
id: file,
files: [file],
};
// to whoever reads this in the future: I'm sorry
//
// this code is basically a bunch of if statements that parse certain
// parts of the `files` property on each release in
// nodejs.org/dist/index.json and then builds out an object from that
// so we can have more useful information about each release. It's a bit
// messy, but it _seemingly_ works, at least at time of writing.
//
// Over time, there's historically been additions, so this will likely
// drift apart from the reality of what's in there. Feel free to either
// ping me or submit a PR to update it when that happens.
if (info.files[0].includes('-pkg')) {
// macOS filenames.
info.files[0] = `node-v${version}.pkg`;
} else if (info.files[0].includes('osx-')) {
// macOS filenames, but with architectures. Different than the above.
const basemacOSString = `node-v${version}-darwin-`;
if (info.files[0].includes('arm64')) {
info.files[0] = basemacOSString.concat('arm64.tar.gz');
}
if (info.files[0].includes('x64')) {
info.files[0] = basemacOSString.concat('x64.tar.gz');
}
} else if (info.files[0].includes('-7z')) {
// windows filenames
info.files[0] = `node-v${version}-${info.files[0].replace('-7z', '.7z')}`;
} else if (info.files[0].includes('-zip')) {
info.files[0] = `node-v${version}-${info.files[0].replace('-zip', '.zip')}`;
} else if (info.files[0].includes('-msi')) {
info.files[0] = `node-v${version}-${info.files[0]
.replace('-msi', '.msi')
.replace('win-', '')}`;
} else if (info.files[0].includes('-exe')) {
info.files[0] = 'win-x64/node.exe';
info.files.push('win-x64/node.lib');
info.files.push('win-x64/node_pdb.7z');
info.files.push('win-x64/node_pdb.zip');
info.files.push('win-x86/node.exe');
info.files.push('win-x86/node.lib');
info.files.push('win-x86/node_pdb.7z');
info.files.push('win-x86/node_pdb.zip');
} else if (info.files[0] === 'src') {
// source filenames.
info.files[0] = `node-v${version}.tar.gz`;
info.files[0] = `node-v${version}.tar.xz`;
} else if (
info.files[0].includes('linux-') ||
info.files[0] === 'headers' ||
info.files[0] === 'aix-ppc64' ||
info.files[0].includes('sunos')
) {
// linux, headers, and aix
info.files[0] = `node-v${version}-${info.files[0]}.tar.gz`;
info.files.push(info.files[0].replace('.tar.gz', '.tar.xz'));
}
// handle the types appropriately.
if (file.includes('osx-')) {
info.type = 'macos';
} else if (file.includes('linux-')) {
info.type = 'linux';
} else if (file.includes('win-')) {
info.type = 'windows';
} else if (file.includes('headers')) {
info.type = 'headers';
} else if (file.includes('src')) {
info.type = 'source';
} else if (file.includes('aix-ppc64')) {
info.type = 'aix';
} else if (file.includes('sunos-x64') || file.includes('sunos-x86')) {
info.type = 'sunos';
}
// some of this is probably wrong but also I'm not familiar enough with
// architectures and their names to know what's right/wrong.
//
// fixes are welcome. I just ask that you keep it relatively nice looking...
// ugly names are bad dx.
if (info.id.includes('x86')) {
info.architecture = 'x86';
} else if (info.id.includes('x64')) {
info.architecture = 'x64';
} else if (info.id.includes('arm64')) {
info.architecture = 'arm64';
} else if (info.id.includes('armv7l')) {
info.architecture = 'armv7l';
} else if (info.id.includes('armv6l')) {
info.architecture = 'armv6l';
} else if (
info.id.includes('aix-ppc64') ||
info.files[0].includes('ppc64le')
) {
info.architecture = 'power';
} else if (info.id.includes('s390x')) {
info.architecture = 'z';
}
return info;
}
module.exports = parseFilename;