-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
platforms.js
70 lines (59 loc) · 1.37 KB
/
platforms.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module.exports = {
platforms: {
win32: {
platform: "win32",
arch : "ia32"
},
win64: {
platform: "win32",
arch : "x64"
},
osx64: {
platform: "darwin",
arch : "x64"
},
linux32: {
platform: "linux",
arch : "ia32"
},
linux64: {
platform: "linux",
arch : "x64"
}
},
getList() {
const list = Object.keys( this.platforms ).join( ":" );
return `Supported platforms: all:${list}`;
},
getPlatform() {
for ( let [ name, { platform, arch } ] of Object.entries( this.platforms ) ) {
if ( platform === process.platform && arch === process.arch ) {
return name;
}
}
throw new Error( `Unsupported platform: ${process.platform} (${process.arch})` );
},
getPlatforms( ...args ) {
if ( !args.length ) {
return [ this.getPlatform() ];
}
const { platforms } = this;
const { hasOwnProperty } = {};
const arr = [];
for ( let platform of args ) {
if ( platform === "all" ) {
arr.push( ...Object.keys( platforms ) );
} else if ( hasOwnProperty.call( platforms, platform ) ) {
arr.push( platform );
} else {
throw new Error( `Invalid platform: ${platform}` );
}
}
return Array.from( new Set( arr ) );
},
getDebugTargets( targets ) {
return targets.length && targets[ targets.length - 1 ] === "debug"
? [ true, targets.slice( 0, -1 ) ]
: [ false, targets.slice() ];
}
};