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 · modecode

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