forked from tabrindle/envinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
envinfo.js
executable file
·178 lines (164 loc) · 5.05 KB
/
envinfo.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env node
'use strict';
var child_process = require('child_process');
var os = require('os');
var osName = require('os-name');
var which = require('which');
function run(cmd) {
return (child_process.execSync(cmd, {
stdio: [0, 'pipe', 'ignore']
}).toString() || '').trim();
}
function getXcodeVersion() {
var xcodeVersion;
var xcodePath = which.sync('xcodebuild');
if (process.platform === 'darwin') {
try {
xcodeVersion = xcodePath && run(xcodePath + ' -version').split('\n').join(' ');
} catch (err) {
xcodeVersion = 'Not Found';
}
} else {
xcodeVersion = 'N/A';
}
return xcodeVersion;
}
function getAndroidStudioVersion() {
var androidStudioVersion = 'Not Found';
if (process.platform === 'darwin') {
try {
androidStudioVersion = run(
[
'/usr/libexec/PlistBuddy',
'-c',
'Print:CFBundleShortVersionString',
'-c',
'Print:CFBundleVersion',
'/Applications/Android\\ Studio.app/Contents/Info.plist'
].join(' ')
)
.split('\n')
.join(' ');
} catch (err) {
androidStudioVersion = 'Not Found';
}
} else if (process.platform === 'linux') {
try {
var linuxBuildNumber = run('cat /opt/android-studio/build.txt');
var linuxVersion = run('cat /opt/android-studio/bin/studio.sh | grep "$Home/.AndroidStudio" | head -1')
.match(/\d\.\d/)[0];
androidStudioVersion = `${linuxVersion} ${linuxBuildNumber}`;
} catch (err) {
androidStudioVersion = 'Not Found';
}
} else if (process.platform.startsWith('win')) {
try {
var windowsVersion = run(
'wmic datafile where name="C:\\\\Program Files\\\\Android\\\\Android Studio\\\\bin\\\\studio.exe" get Version'
)
.replace(/(\r\n|\n|\r)/gm, '');
var windowsBuildNumber = run('type "C:\\\\Program Files\\\\Android\\\\Android Studio\\\\build.txt"')
.replace(/(\r\n|\n|\r)/gm, '');
androidStudioVersion = `${windowsVersion} ${windowsBuildNumber}`;
} catch (err) {
androidStudioVersion = 'Not Found';
}
}
return androidStudioVersion;
}
function getNpmVersion() {
var npmVersion;
try {
npmVersion = run('npm -v');
} catch (error) {
npmVersion = 'Not Found';
}
return npmVersion;
}
function getYarnVersion() {
var yarnVersion;
try {
yarnVersion = run('yarn --version');
} catch (error) {
yarnVersion = 'Not Found';
}
return yarnVersion;
}
function getOperatingSystemInfo() {
var operatingSystemInfo;
try {
var operatingSystemInfo = osName(os.platform(), os.release());
if (process.platform === 'darwin') {
operatingSystemInfo = operatingSystemInfo + ' ' + run('sw_vers -productVersion ');
}
} catch (err) {
operatingSystemInfo = operatingSystemInfo + ' Unknown Version';
}
return operatingSystemInfo;
}
function getNodeVersion() {
var nodeVersion;
try {
nodeVersion = run('node --version').replace('v', '');
} catch (error) {
nodeVersion = 'Not Found';
}
return nodeVersion;
}
function getWatchmanVersion() {
var watchmanVersion;
try {
var watchmanPath = which.sync('watchman');
watchmanVersion = watchmanPath && run(watchmanPath + ' --version');
} catch (error) {
watchmanVersion = 'Not Found';
}
return watchmanVersion;
}
module.exports.print = function(options) {
console.log('');
console.log('\x1b[4mEnvironment:\x1b[0m');
console.log(' OS: ', getOperatingSystemInfo());
console.log(' Node: ', getNodeVersion());
console.log(' Yarn: ', getYarnVersion());
console.log(' npm: ', getNpmVersion());
console.log(' Watchman: ', getWatchmanVersion());
console.log(' Xcode: ', getXcodeVersion());
console.log(' Android Studio: ', getAndroidStudioVersion());
console.log('');
if (options) {
if (options.packages) {
try {
var packageJson = require(process.cwd() + '/package.json');
} catch (err) {
console.log('ERROR: package.json not found!');
console.log('');
return;
}
console.log('\x1b[4mPackages:\x1b[0m (wanted => installed)');
var devDependencies = packageJson.devDependencies || {};
var dependencies = packageJson.dependencies || {};
var allDependencies = Object.assign({}, devDependencies, dependencies);
var logFunction = function(dep) {
if (allDependencies[dep]) {
var wanted = allDependencies[dep];
var installed;
try {
installed = require(process.cwd() + '/node_modules/' + dep + '/package.json').version;
} catch (err) {
installed = 'Not Installed';
}
console.log(' ' + dep + ': ' + wanted + ' => ' + installed);
}
};
if (Array.isArray(options.packages)) {
options.packages.map(logFunction);
} else if (typeof options.packages === 'string') {
options.packages.split(',').map(logFunction);
} else if (typeof options.packages === 'boolean') {
Object.keys(allDependencies).map(logFunction);
}
console.log('');
}
}
};