microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix-ts-error1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/services/validationService/checker.ts

111lines · 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";
8609d701AndreiLobanovich4 years ago5import { PackageVersion } from "../../../common/projectVersionHelper";
c7856462Heniker4 years ago6import { OutputChannelLogger } from "../../log/OutputChannelLogger";
7import { getChecks } from "./checks";
8import { ValidationCategoryE, IValidation, ValidationResultT } from "./checks/types";
9import { fromEntries } from "./util";
10
11nls.config({
12messageFormat: nls.MessageFormat.bundle,
13bundleFormat: nls.BundleFormat.standalone,
14})();
15
16const toLocale = nls.loadMessageBundle();
68c29472Heniker4 years ago17const outputChannel = OutputChannelLogger.getMainChannel();
c7856462Heniker4 years ago18
19const evaluteChecks = async (checks: IValidation[]) => {
20const execToEntries = (categ: ValidationCategoryE, toCheck: IValidation[]) =>
21Promise.all(
22toCheck
23.filter(it => it.category === categ)
68c29472Heniker4 years ago24.map(
25async it =>
26[
27it,
28await it.exec().catch(err => {
29outputChannel.warning(`Check ${it.label} failed with error`);
30outputChannel.warning(err);
31
32return {
33status: "failure",
34comment: "Check execution failed",
35} as ValidationResultT;
36}),
37] as const,
38),
c7856462Heniker4 years ago39);
40
41return fromEntries(
42await Promise.all(
43Object.values(ValidationCategoryE).map(
44async it => [it, new Map(await execToEntries(it, checks))] as const,
45),
46),
47);
48};
49
50const statusToSymbol = {
51success: "✓",
52failure: "✖",
53"partial-success": "❔",
54};
55
56export const runChecks = async (
57options_?: Partial<Record<ValidationCategoryE, boolean>>,
8609d701AndreiLobanovich4 years ago58versions?: PackageVersion[],
c7856462Heniker4 years ago59): Promise<void> => {
60const options = Object.assign(
61{
62[ValidationCategoryE.Common]: true,
63[ValidationCategoryE.Android]: true,
64[ValidationCategoryE.iOS]: true,
65},
66options_,
67);
68
69outputChannel.setFocusOnLogChannel();
70outputChannel.info(toLocale("DevEnvVerificationStart", "Starting Environment check..."));
8609d701AndreiLobanovich4 years ago71const checks = await evaluteChecks(
72getChecks(versions).filter(it => options?.[it.category] === true),
73);
c7856462Heniker4 years ago74
75let outStr = `<<< ${toLocale(
76"DevEnvVerificationHeader",
77"Dev Environment verification result",
78)} >>>\n`;
79
80Object.entries(checks).forEach(async ([key, val]) => {
81if (val.size === 0) {
82return;
83}
84
85outStr += `\n*** ${key} ***\n`;
86
87val.forEach((execResult, validation) => {
88outStr += ` ${statusToSymbol[execResult.status]} ${validation.label}`;
89
90if (execResult.status !== "success") {
91outStr += ` - ${validation.description}\n`;
09f6024fHeniker4 years ago92outStr += ` ${execResult.comment || ""}`;
c7856462Heniker4 years ago93}
94
95outStr += "\n";
96});
97});
98
99const allPassed = ([] as ValidationResultT[])
100.concat(...Object.entries(checks).map(it => [...it[1].values()]))
101.every(it => it.status === "success");
102
103if (allPassed) {
104outStr += `\n${toLocale(
105"DevEnvVerificationFooter",
106"All checks passed successfully!",
107)}\n\n`;
108}
109
110outputChannel.logStream(outStr);
111};