forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform-environment-requirements.ts
103 lines (89 loc) · 2.81 KB
/
platform-environment-requirements.ts
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
import { TrackActionNames } from "../constants";
import { hook } from "../common/helpers";
import { EOL } from "os";
import {
IPlatformEnvironmentRequirements,
ICheckEnvironmentRequirementsInput,
ICheckEnvironmentRequirementsOutput,
} from "../definitions/platform";
import {
IErrors,
IAnalyticsService,
IDoctorService,
} from "../common/declarations";
import { IInjector } from "../common/definitions/yok";
import { injector } from "../common/yok";
export class PlatformEnvironmentRequirements
implements IPlatformEnvironmentRequirements {
constructor(
private $doctorService: IDoctorService,
private $errors: IErrors,
private $analyticsService: IAnalyticsService,
// @ts-ignore - required by the hook helper!
private $injector: IInjector
) {}
private static MISSING_LOCAL_SETUP_MESSAGE =
"Your environment is not configured properly and you will not be able to execute local builds.";
@hook("checkEnvironment")
public async checkEnvironmentRequirements(
input: ICheckEnvironmentRequirementsInput
): Promise<ICheckEnvironmentRequirementsOutput> {
const { platform, projectDir, runtimeVersion } = input;
const selectedOption: any = null;
if (process.env.NS_SKIP_ENV_CHECK) {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.CheckEnvironmentRequirements,
additionalData: "Skipped: NS_SKIP_ENV_CHECK is set",
});
return {
canExecute: true,
selectedOption,
};
}
const canExecute = await this.$doctorService.canExecuteLocalBuild({
platform,
projectDir,
runtimeVersion,
forceCheck: input.forceCheck,
});
if (!canExecute) {
// if (!isInteractive()) {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.CheckEnvironmentRequirements,
additionalData:
"Non-interactive terminal, unable to execute local builds.",
});
this.fail(this.getNonInteractiveConsoleMessage(platform));
}
return {
canExecute,
selectedOption,
};
}
private fail(message: string): void {
this.$errors.fail({ formatStr: message, printOnStdout: true });
}
private getNonInteractiveConsoleMessage(platform: string) {
return [
PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE,
this.getEnvVerificationMessage(platform),
].join(EOL);
}
private getEnvVerificationMessage(platform: string) {
// map process.platform to OS name used in docs
const os = ({
linux: "linux",
win32: "windows",
darwin: "macos",
} as any)[process.platform];
const anchor = platform ? `/${os}#${platform.toLowerCase()}` : "";
return (
`Verify that your environment is configured according to the system requirements described at\n` +
`https://docs.nativescript.org/setup${anchor}.`
);
}
}
injector.register(
"platformEnvironmentRequirements",
PlatformEnvironmentRequirements
);