-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathinfo.ts
More file actions
75 lines (61 loc) · 1.96 KB
/
info.ts
File metadata and controls
75 lines (61 loc) · 1.96 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
import * as Debug from 'debug';
import * as os from 'os';
const debug = Debug('ionic:utils-terminal:info');
/**
* These environment variables work for: GitHub Actions, Travis CI, CircleCI,
* Gitlab CI, AppVeyor, CodeShip, Jenkins, TeamCity, Bitbucket Pipelines, AWS
* CodeBuild
*/
export const CI_ENVIRONMENT_VARIABLES: readonly string[] = ['CI', 'BUILD_ID', 'BUILD_NUMBER', 'BITBUCKET_COMMIT', 'CODEBUILD_BUILD_ARN', 'GITHUB_ACTIONS'];
export const CI_ENVIRONMENT_VARIABLES_DETECTED = CI_ENVIRONMENT_VARIABLES.filter(v => !!process.env[v]);
function getShell(): string {
try {
const { shell } = os.userInfo();
if (shell) {
return shell;
}
} catch {
// userInfo can throw a SystemError exception as described here:
// https://nodejs.org/api/os.html#osuserinfooptions
}
if (process.env.SHELL) {
return process.env.SHELL;
}
if (process.platform === 'darwin') {
return '/bin/bash';
}
if (process.platform === 'win32') {
return process.env.COMSPEC ? process.env.COMSPEC : 'cmd.exe';
}
return '/bin/sh';
}
if (CI_ENVIRONMENT_VARIABLES_DETECTED.length > 0) {
debug(`Environment variables for CI detected: ${CI_ENVIRONMENT_VARIABLES_DETECTED.join(', ')}`);
}
export interface TerminalInfo {
/**
* Whether this is in CI or not.
*/
readonly ci: boolean;
/**
* Path to the user's shell program.
*/
readonly shell: string;
/**
* Whether the terminal is an interactive TTY or not.
*/
readonly tty: boolean;
/**
* Whether this is a Windows shell or not.
*/
readonly windows: boolean;
}
export const TERMINAL_INFO: TerminalInfo = Object.freeze({
ci: CI_ENVIRONMENT_VARIABLES_DETECTED.length > 0,
shell: getShell(),
tty: Boolean(process.stdin.isTTY && process.stdout.isTTY && process.stderr.isTTY),
windows: process.platform === 'win32' || !!(
process.env.OSTYPE && /^(msys|cygwin)$/.test(process.env.OSTYPE) ||
process.env.MSYSTEM && /^MINGW(32|64)$/.test(process.env.MSYSTEM)
),
});