microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.9.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/services/validationService/checker.ts

108lines · modeblame

c7856462Heniker4 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
09f6024fHeniker4 years ago4import * as nls from "vscode-nls";
c7856462Heniker4 years ago5import { OutputChannelLogger } from "../../log/OutputChannelLogger";
6import { getChecks } from "./checks";
7import { ValidationCategoryE, IValidation, ValidationResultT } from "./checks/types";
8import { fromEntries } from "./util";
9
10nls.config({
11messageFormat: nls.MessageFormat.bundle,
12bundleFormat: nls.BundleFormat.standalone,
13})();
14
15const toLocale = nls.loadMessageBundle();
68c29472Heniker4 years ago16const outputChannel = OutputChannelLogger.getMainChannel();
c7856462Heniker4 years ago17
18const evaluteChecks = async (checks: IValidation[]) => {
19const execToEntries = (categ: ValidationCategoryE, toCheck: IValidation[]) =>
20Promise.all(
21toCheck
22.filter(it => it.category === categ)
68c29472Heniker4 years ago23.map(
24async it =>
25[
26it,
27await it.exec().catch(err => {
28outputChannel.warning(`Check ${it.label} failed with error`);
29outputChannel.warning(err);
30
31return {
32status: "failure",
33comment: "Check execution failed",
34} as ValidationResultT;
35}),
36] as const,
37),
c7856462Heniker4 years ago38);
39
40return fromEntries(
41await Promise.all(
42Object.values(ValidationCategoryE).map(
43async it => [it, new Map(await execToEntries(it, checks))] as const,
44),
45),
46);
47};
48
49const statusToSymbol = {
50success: "✓",
51failure: "✖",
52"partial-success": "❔",
53};
54
55export const runChecks = async (
56options_?: Partial<Record<ValidationCategoryE, boolean>>,
57): Promise<void> => {
58const options = Object.assign(
59{
60[ValidationCategoryE.Common]: true,
61[ValidationCategoryE.Android]: true,
62[ValidationCategoryE.iOS]: true,
63},
64options_,
65);
66
67outputChannel.setFocusOnLogChannel();
68outputChannel.info(toLocale("DevEnvVerificationStart", "Starting Environment check..."));
69
70const checks = await evaluteChecks(getChecks().filter(it => options?.[it.category] === true));
71
72let outStr = `<<< ${toLocale(
73"DevEnvVerificationHeader",
74"Dev Environment verification result",
75)} >>>\n`;
76
77Object.entries(checks).forEach(async ([key, val]) => {
78if (val.size === 0) {
79return;
80}
81
82outStr += `\n*** ${key} ***\n`;
83
84val.forEach((execResult, validation) => {
85outStr += ` ${statusToSymbol[execResult.status]} ${validation.label}`;
86
87if (execResult.status !== "success") {
88outStr += ` - ${validation.description}\n`;
09f6024fHeniker4 years ago89outStr += ` ${execResult.comment || ""}`;
c7856462Heniker4 years ago90}
91
92outStr += "\n";
93});
94});
95
96const allPassed = ([] as ValidationResultT[])
97.concat(...Object.entries(checks).map(it => [...it[1].values()]))
98.every(it => it.status === "success");
99
100if (allPassed) {
101outStr += `\n${toLocale(
102"DevEnvVerificationFooter",
103"All checks passed successfully!",
104)}\n\n`;
105}
106
107outputChannel.logStream(outStr);
108};