igniteui-cli 16.0.0-alpha.2 → 16.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.checkNode = checkNode;
36
+ exports.checkNpm = checkNpm;
37
+ exports.checkGit = checkGit;
38
+ exports.checkDotnet = checkDotnet;
39
+ exports.checkCliVersion = checkCliVersion;
40
+ exports.environmentChecks = environmentChecks;
41
+ const path = __importStar(require("path"));
42
+ const semver = __importStar(require("semver"));
43
+ const util_1 = require("./util");
44
+ const GROUP = "Environment";
45
+ const NODE_MINIMUM = 20;
46
+ const NODE_RECOMMENDED = 24;
47
+ function checkNode(version = process.versions.node) {
48
+ var _a;
49
+ const major = (_a = (0, util_1.majorOf)(version)) !== null && _a !== void 0 ? _a : 0;
50
+ const result = { id: "node", group: GROUP, status: "ok", detail: `Node.js ${version}` };
51
+ if (major < NODE_MINIMUM) {
52
+ result.status = "fail";
53
+ result.fix = `Install Node.js ${NODE_RECOMMENDED} or newer (${NODE_MINIMUM} is the minimum)`;
54
+ }
55
+ else if (major < NODE_RECOMMENDED) {
56
+ result.status = "warn";
57
+ result.fix = `Node.js ${NODE_RECOMMENDED} or newer is recommended`;
58
+ }
59
+ return result;
60
+ }
61
+ function checkNpm() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const version = yield util_1.shell.run("npm --version");
64
+ return version
65
+ ? { id: "npm", group: GROUP, status: "ok", detail: `npm ${version}` }
66
+ : { id: "npm", group: GROUP, status: "fail", detail: "npm not found", fix: "Install npm (it ships with Node.js)" };
67
+ });
68
+ }
69
+ function checkGit() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const version = yield util_1.shell.run("git --version");
72
+ return version
73
+ ? { id: "git", group: GROUP, status: "ok", detail: version }
74
+ : {
75
+ id: "git", group: GROUP, status: "warn", detail: "git not found",
76
+ fix: `Install git, or pass --skip-git to "ig new"`
77
+ };
78
+ });
79
+ }
80
+ function checkDotnet() {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const version = yield util_1.shell.run("dotnet --version");
83
+ return version
84
+ ? { id: "dotnet", group: GROUP, status: "ok", detail: `.NET SDK ${version}` }
85
+ : {
86
+ id: "dotnet", group: GROUP, status: "fail", detail: ".NET SDK not found",
87
+ fix: "Install the .NET SDK from https://dotnet.microsoft.com/download"
88
+ };
89
+ });
90
+ }
91
+ function checkCliVersion(context) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const current = require(path.join(context.cliDir, "package.json")).version;
94
+ const result = { id: "cli-version", group: GROUP, status: "ok", detail: `Ignite UI CLI ${current}` };
95
+ if (context.offline) {
96
+ return Object.assign(Object.assign({}, result), { status: "skip", detail: `${result.detail} (latest version not checked: --offline)` });
97
+ }
98
+ const latest = yield util_1.shell.run("npm view igniteui-cli version", 15000);
99
+ if (!latest || !semver.valid(latest) || !semver.valid(current)) {
100
+ return Object.assign(Object.assign({}, result), { status: "skip", detail: `${result.detail} (could not read the latest version from npm)` });
101
+ }
102
+ if (semver.lt(current, latest)) {
103
+ return Object.assign(Object.assign({}, result), { status: "warn", detail: `${result.detail} (latest is ${latest})`, fix: "Update with: npm install -g igniteui-cli@latest" });
104
+ }
105
+ return Object.assign(Object.assign({}, result), { detail: `${result.detail} (latest)` });
106
+ });
107
+ }
108
+ function environmentChecks(context) {
109
+ return Promise.all([
110
+ checkNode(),
111
+ checkNpm(),
112
+ checkGit(),
113
+ ...(context.framework === "blazor" ? [checkDotnet()] : []),
114
+ checkCliVersion(context)
115
+ ]);
116
+ }
@@ -0,0 +1,2 @@
1
+ import { CheckResult, DoctorContext } from "./types";
2
+ export declare function feedChecks(context: DoctorContext): Promise<CheckResult[]>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.feedChecks = feedChecks;
13
+ const cli_core_1 = require("@igniteui/cli-core");
14
+ const util_1 = require("./util");
15
+ const GROUP = "Licensed feed";
16
+ const NOT_LOGGED_IN = /ENEEDAUTH|E401|E403/;
17
+ const LICENSED_REGISTRY = "https://packages.infragistics.com/npm/js-licensed/";
18
+ function feedChecks(context) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const usesFeed = !!context.packageJson &&
21
+ Object.keys((0, util_1.allDependencies)(context.packageJson)).some(name => name.startsWith("@infragistics/"));
22
+ if (!usesFeed) {
23
+ return [{ id: "feed", group: GROUP, status: "skip", detail: "The project uses no @infragistics packages" }];
24
+ }
25
+ const configured = yield util_1.shell.run("npm config get @infragistics:registry");
26
+ const registry = configured && configured !== "undefined" ? cli_core_1.Util.sanitizeShellArg(configured) : null;
27
+ if (!registry) {
28
+ return [{
29
+ id: "feed-registry", group: GROUP, status: "fail",
30
+ detail: "No registry is configured for the @infragistics scope",
31
+ fix: `Run: npm config set @infragistics:registry ${LICENSED_REGISTRY}`
32
+ }];
33
+ }
34
+ const results = [
35
+ { id: "feed-registry", group: GROUP, status: "ok", detail: `@infragistics packages come from ${registry}` }
36
+ ];
37
+ if (context.offline) {
38
+ results.push({ id: "feed-login", group: GROUP, status: "skip", detail: "Login not checked: --offline" });
39
+ return results;
40
+ }
41
+ const login = yield util_1.shell.attempt(`npm whoami --registry=${registry}`, 15000);
42
+ if (login.ok && login.output) {
43
+ results.push({ id: "feed-login", group: GROUP, status: "ok", detail: `Logged in as ${login.output}` });
44
+ }
45
+ else if (NOT_LOGGED_IN.test(login.output)) {
46
+ results.push({
47
+ id: "feed-login", group: GROUP, status: "fail", detail: `Not logged in to ${registry}`,
48
+ fix: `Run: npm login --registry=${registry} --scope=@infragistics`
49
+ });
50
+ }
51
+ else {
52
+ results.push({
53
+ id: "feed-login", group: GROUP, status: "warn", detail: `Could not check the login to ${registry}`,
54
+ fix: `Check the network connection, or run: npm whoami --registry=${registry}`
55
+ });
56
+ }
57
+ return results;
58
+ });
59
+ }
@@ -0,0 +1,5 @@
1
+ import { CheckResult, DoctorContext } from "./types";
2
+ export * from "./report";
3
+ export * from "./types";
4
+ export declare function createContext(offline: boolean): DoctorContext;
5
+ export declare function runDoctor(offline: boolean): Promise<CheckResult[]>;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.createContext = createContext;
39
+ exports.runDoctor = runDoctor;
40
+ const cli_core_1 = require("@igniteui/cli-core");
41
+ const path = __importStar(require("path"));
42
+ const ai_1 = require("./ai");
43
+ const environment_1 = require("./environment");
44
+ const feed_1 = require("./feed");
45
+ const project_1 = require("./project");
46
+ const util_1 = require("./util");
47
+ __exportStar(require("./report"), exports);
48
+ __exportStar(require("./types"), exports);
49
+ function createContext(offline) {
50
+ const fileSystem = cli_core_1.App.container.get(cli_core_1.FS_TOKEN);
51
+ const context = {
52
+ offline,
53
+ cliDir: path.resolve(__dirname, "..", ".."),
54
+ framework: (0, cli_core_1.detectFramework)(false),
55
+ inProject: false,
56
+ hasPackageJson: fileSystem.fileExists("./package.json"),
57
+ packageJson: null
58
+ };
59
+ if (context.hasPackageJson) {
60
+ try {
61
+ const parsed = JSON.parse(fileSystem.readFile("./package.json"));
62
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
63
+ throw new Error("the content is not a JSON object");
64
+ }
65
+ context.packageJson = parsed;
66
+ }
67
+ catch (error) {
68
+ context.packageJsonError = error.message;
69
+ }
70
+ }
71
+ // a package.json that doesn't parse still counts, so the project checks get to report it
72
+ const usesIgniteUI = context.hasPackageJson && (!context.packageJson
73
+ || Object.keys((0, util_1.allDependencies)(context.packageJson)).some(name => util_1.IGNITEUI_PACKAGE.test(name)));
74
+ context.inProject = usesIgniteUI || cli_core_1.ProjectConfig.hasLocalConfig() || context.framework === "blazor";
75
+ return context;
76
+ }
77
+ function runDoctor(offline) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const context = createContext(offline);
80
+ const groups = yield Promise.all([
81
+ (0, environment_1.environmentChecks)(context),
82
+ (0, project_1.projectChecks)(context),
83
+ (0, feed_1.feedChecks)(context),
84
+ (0, ai_1.aiChecks)(context)
85
+ ]);
86
+ return [].concat(...groups);
87
+ });
88
+ }
@@ -0,0 +1,7 @@
1
+ import { CheckResult, DoctorContext } from "./types";
2
+ export declare function checkConfig(): CheckResult;
3
+ export declare function checkPackageJson(context: DoctorContext): CheckResult;
4
+ export declare function checkInstalledPackages(context: DoctorContext): CheckResult;
5
+ export declare function checkMixedPackages(context: DoctorContext): CheckResult;
6
+ export declare function checkAngularMajor(context: DoctorContext): CheckResult | null;
7
+ export declare function projectChecks(context: DoctorContext): CheckResult[];
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkConfig = checkConfig;
4
+ exports.checkPackageJson = checkPackageJson;
5
+ exports.checkInstalledPackages = checkInstalledPackages;
6
+ exports.checkMixedPackages = checkMixedPackages;
7
+ exports.checkAngularMajor = checkAngularMajor;
8
+ exports.projectChecks = projectChecks;
9
+ const cli_core_1 = require("@igniteui/cli-core");
10
+ const util_1 = require("./util");
11
+ const GROUP = "Project";
12
+ function checkConfig() {
13
+ const id = "cli-config";
14
+ const file = cli_core_1.ProjectConfig.configFile;
15
+ if (!cli_core_1.ProjectConfig.hasLocalConfig()) {
16
+ return { id, group: GROUP, status: "skip", detail: `No ${file}; the framework is detected from the project files` };
17
+ }
18
+ let framework;
19
+ let projectType;
20
+ try {
21
+ const project = cli_core_1.ProjectConfig.localConfig().project;
22
+ framework = project === null || project === void 0 ? void 0 : project.framework;
23
+ projectType = project === null || project === void 0 ? void 0 : project.projectType;
24
+ }
25
+ catch (error) {
26
+ return { id, group: GROUP, status: "fail", detail: error.message, fix: `Fix the JSON in ${file}` };
27
+ }
28
+ if (!framework) {
29
+ return {
30
+ id, group: GROUP, status: "skip",
31
+ detail: `${file} sets no project.framework; the framework is detected from the project files`
32
+ };
33
+ }
34
+ if (typeof framework !== "string") {
35
+ return {
36
+ id, group: GROUP, status: "fail",
37
+ detail: `${file} has a project.framework that is not a string`,
38
+ fix: `Set project.framework to a framework listed by "ig list"`
39
+ };
40
+ }
41
+ const templateManager = cli_core_1.App.container.get(cli_core_1.TEMPLATE_MANAGER);
42
+ const library = templateManager.getProjectLibrary(framework.toLowerCase(), projectType);
43
+ if (!library) {
44
+ return {
45
+ id, group: GROUP, status: "fail",
46
+ detail: `${file} has framework "${framework}" with project type "${projectType}", which the CLI doesn't know`,
47
+ fix: `Set project.framework and project.projectType to a pair listed by "ig list"`
48
+ };
49
+ }
50
+ return { id, group: GROUP, status: "ok", detail: `${file}: ${framework} / ${library.projectType}` };
51
+ }
52
+ function checkPackageJson(context) {
53
+ const id = "package-json";
54
+ if (!context.hasPackageJson) {
55
+ return { id, group: GROUP, status: "skip", detail: "No package.json" };
56
+ }
57
+ if (!context.packageJson) {
58
+ return {
59
+ id, group: GROUP, status: "fail",
60
+ detail: `package.json doesn't parse: ${context.packageJsonError}`, fix: "Fix the JSON in package.json"
61
+ };
62
+ }
63
+ return { id, group: GROUP, status: "ok", detail: "package.json parses" };
64
+ }
65
+ function checkInstalledPackages(context) {
66
+ const id = "packages-installed";
67
+ const declared = Object.entries((0, util_1.allDependencies)(context.packageJson)).filter(([name]) => util_1.IGNITEUI_PACKAGE.test(name));
68
+ if (!declared.length) {
69
+ return { id, group: GROUP, status: "skip", detail: "No Ignite UI packages in package.json" };
70
+ }
71
+ const problems = [];
72
+ for (const [name, range] of declared) {
73
+ const version = (0, util_1.installedVersion)(name);
74
+ if (!version) {
75
+ problems.push(`${name} is not installed`);
76
+ }
77
+ else if ((0, util_1.satisfies)(version, range) === false) {
78
+ problems.push(`${name} ${version} doesn't satisfy ${range}`);
79
+ }
80
+ }
81
+ if (problems.length) {
82
+ return { id, group: GROUP, status: "fail", detail: problems.join("; "), fix: "Run: npm install" };
83
+ }
84
+ return { id, group: GROUP, status: "ok", detail: `${declared.length} Ignite UI package(s) installed` };
85
+ }
86
+ function checkMixedPackages(context) {
87
+ const id = "packages-mixed";
88
+ const dependencies = (0, util_1.allDependencies)(context.packageJson);
89
+ const licensed = Object.keys(dependencies).filter(name => name.startsWith("@infragistics/"));
90
+ const trial = Object.keys(cli_core_1.UPGRADEABLE_PACKAGES).filter(name => dependencies[name]);
91
+ if (licensed.length && trial.length) {
92
+ return {
93
+ id, group: GROUP, status: "warn",
94
+ detail: `Trial packages next to licensed ones: ${trial.join(", ")}`,
95
+ fix: "Run: ig upgrade-packages"
96
+ };
97
+ }
98
+ if (!licensed.length && !trial.length) {
99
+ return { id, group: GROUP, status: "skip", detail: "No packages with a licensed version" };
100
+ }
101
+ return { id, group: GROUP, status: "ok", detail: licensed.length ? "Licensed packages only" : "Trial packages only" };
102
+ }
103
+ function checkAngularMajor(context) {
104
+ const dependencies = (0, util_1.allDependencies)(context.packageJson);
105
+ const igniteui = dependencies[cli_core_1.FEED_ANGULAR] ? cli_core_1.FEED_ANGULAR : cli_core_1.NPM_ANGULAR;
106
+ if (!dependencies[igniteui] || !dependencies["@angular/core"]) {
107
+ return null;
108
+ }
109
+ const major = (name) => { var _a; return (0, util_1.majorOf)((_a = (0, util_1.installedVersion)(name)) !== null && _a !== void 0 ? _a : dependencies[name]); };
110
+ const igniteuiMajor = major(igniteui);
111
+ const angularMajor = major("@angular/core");
112
+ const id = "angular-major";
113
+ if (igniteuiMajor === undefined || angularMajor === undefined) {
114
+ return { id, group: GROUP, status: "skip", detail: `Could not read the ${igniteui} and @angular/core versions` };
115
+ }
116
+ if (igniteuiMajor !== angularMajor) {
117
+ return {
118
+ id, group: GROUP, status: "warn",
119
+ detail: `${igniteui} ${igniteuiMajor} with @angular/core ${angularMajor}`,
120
+ fix: `Use the ${igniteui} major that matches Angular: ng update ${igniteui}`
121
+ };
122
+ }
123
+ return { id, group: GROUP, status: "ok", detail: `${igniteui} and @angular/core are both on ${angularMajor}` };
124
+ }
125
+ function projectChecks(context) {
126
+ if (!context.inProject) {
127
+ return [{ id: "project", group: GROUP, status: "skip", detail: "Not in an Ignite UI project" }];
128
+ }
129
+ const results = [checkConfig(), checkPackageJson(context)];
130
+ if (context.packageJson) {
131
+ results.push(checkInstalledPackages(context), checkMixedPackages(context));
132
+ const angular = context.framework === "angular" ? checkAngularMajor(context) : null;
133
+ if (angular) {
134
+ results.push(angular);
135
+ }
136
+ }
137
+ return results;
138
+ }
@@ -0,0 +1,4 @@
1
+ import { CheckResult, CheckStatus } from "./types";
2
+ export declare function summarize(results: CheckResult[]): Record<CheckStatus, number>;
3
+ export declare function formatText(results: CheckResult[]): string;
4
+ export declare function formatJson(results: CheckResult[]): string;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.summarize = summarize;
4
+ exports.formatText = formatText;
5
+ exports.formatJson = formatJson;
6
+ const cli_core_1 = require("@igniteui/cli-core");
7
+ const STYLES = { ok: "green", warn: "yellow", fail: "red", skip: "dim" };
8
+ function summarize(results) {
9
+ const summary = { ok: 0, warn: 0, fail: 0, skip: 0 };
10
+ for (const result of results) {
11
+ summary[result.status]++;
12
+ }
13
+ return summary;
14
+ }
15
+ function formatText(results) {
16
+ const lines = [];
17
+ let group = "";
18
+ for (const result of results) {
19
+ if (result.group !== group) {
20
+ group = result.group;
21
+ lines.push("", group);
22
+ }
23
+ lines.push(` ${cli_core_1.Util.style(result.status.padEnd(4), STYLES[result.status])} ${result.detail}`);
24
+ if (result.fix) {
25
+ lines.push(` ${result.fix}`);
26
+ }
27
+ }
28
+ const summary = summarize(results);
29
+ lines.push("", `${summary.ok} ok, ${summary.warn} warning(s), ${summary.fail} failed, ${summary.skip} skipped`);
30
+ return lines.join("\n").trimStart();
31
+ }
32
+ function formatJson(results) {
33
+ const summary = summarize(results);
34
+ return JSON.stringify({ ok: summary.fail === 0, summary, checks: results }, null, 2);
35
+ }
@@ -0,0 +1,25 @@
1
+ export type CheckStatus = "ok" | "warn" | "fail" | "skip";
2
+ export interface CheckResult {
3
+ id: string;
4
+ group: string;
5
+ status: CheckStatus;
6
+ detail: string;
7
+ /** One-line hint on how to resolve a `warn` or `fail`. */
8
+ fix?: string;
9
+ }
10
+ export interface ProjectPackageJson {
11
+ dependencies?: Record<string, string>;
12
+ devDependencies?: Record<string, string>;
13
+ }
14
+ export interface DoctorContext {
15
+ /** Skip the checks that need the network. */
16
+ offline: boolean;
17
+ /** Folder of the running CLI package. */
18
+ cliDir: string;
19
+ framework: string | null;
20
+ inProject: boolean;
21
+ hasPackageJson: boolean;
22
+ /** `null` when there is no package.json or it doesn't parse. */
23
+ packageJson: ProjectPackageJson | null;
24
+ packageJsonError?: string;
25
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ import { ProjectPackageJson } from "./types";
2
+ export declare const shell: {
3
+ /** Runs a command; `output` is its stdout on success and its stderr on failure or timeout. */
4
+ attempt(command: string, timeout?: number): Promise<{
5
+ ok: boolean;
6
+ output: string;
7
+ }>;
8
+ /** Runs a command and returns its trimmed output, or `null` when it fails or times out. */
9
+ run(command: string, timeout?: number): Promise<string | null>;
10
+ };
11
+ /** Major of a version or of the lowest version a range allows. */
12
+ export declare function majorOf(text: string): number | undefined;
13
+ /** @returns `null` for what is not a version range (tags, URLs, `file:` and `workspace:` specs), which is not evaluated */
14
+ export declare function satisfies(version: string, range: string): boolean | null;
15
+ export declare const IGNITEUI_PACKAGE: RegExp;
16
+ export declare function allDependencies(packageJson: ProjectPackageJson): Record<string, string>;
17
+ /** Version of a package installed for the current folder, looking through parent `node_modules` as Node does. */
18
+ export declare function installedVersion(name: string): string | null;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.IGNITEUI_PACKAGE = exports.shell = void 0;
36
+ exports.majorOf = majorOf;
37
+ exports.satisfies = satisfies;
38
+ exports.allDependencies = allDependencies;
39
+ exports.installedVersion = installedVersion;
40
+ const cli_core_1 = require("@igniteui/cli-core");
41
+ const child_process_1 = require("child_process");
42
+ const path = __importStar(require("path"));
43
+ const semver = __importStar(require("semver"));
44
+ const WINDOWS = process.platform === "win32";
45
+ function killTree(child) {
46
+ if (!child.pid) {
47
+ child.kill();
48
+ }
49
+ else if (WINDOWS) {
50
+ (0, child_process_1.spawn)("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true })
51
+ .on("error", () => child.kill());
52
+ }
53
+ else {
54
+ try {
55
+ // the shell leads its own process group, so this reaches what it started as well
56
+ process.kill(-child.pid);
57
+ }
58
+ catch (_a) {
59
+ child.kill();
60
+ }
61
+ }
62
+ }
63
+ exports.shell = {
64
+ /** Runs a command; `output` is its stdout on success and its stderr on failure or timeout. */
65
+ attempt(command, timeout = 10000) {
66
+ return new Promise(resolve => {
67
+ let stdout = "";
68
+ let stderr = "";
69
+ const child = (0, child_process_1.spawn)(command, {
70
+ shell: true, windowsHide: true, detached: !WINDOWS, stdio: ["ignore", "pipe", "pipe"]
71
+ });
72
+ child.stdout.setEncoding("utf8").on("data", chunk => stdout += chunk);
73
+ child.stderr.setEncoding("utf8").on("data", chunk => stderr += chunk);
74
+ const done = (ok) => {
75
+ clearTimeout(timer);
76
+ resolve(ok ? { ok: true, output: stdout.trim() } : { ok: false, output: stderr });
77
+ };
78
+ child.on("error", () => done(false));
79
+ child.on("close", code => done(code === 0));
80
+ // killing only the shell would leave what it started running and holding the output pipes
81
+ const timer = setTimeout(() => {
82
+ killTree(child);
83
+ resolve({ ok: false, output: "" });
84
+ }, timeout);
85
+ });
86
+ },
87
+ /** Runs a command and returns its trimmed output, or `null` when it fails or times out. */
88
+ run(command_1) {
89
+ return __awaiter(this, arguments, void 0, function* (command, timeout = 10000) {
90
+ const result = yield exports.shell.attempt(command, timeout);
91
+ return result.ok ? result.output : null;
92
+ });
93
+ }
94
+ };
95
+ /** Major of a version or of the lowest version a range allows. */
96
+ function majorOf(text) {
97
+ var _a;
98
+ return (_a = semver.coerce(text)) === null || _a === void 0 ? void 0 : _a.major;
99
+ }
100
+ /** @returns `null` for what is not a version range (tags, URLs, `file:` and `workspace:` specs), which is not evaluated */
101
+ function satisfies(version, range) {
102
+ if (!semver.valid(version) || semver.validRange(range) === null) {
103
+ return null;
104
+ }
105
+ return semver.satisfies(version, range);
106
+ }
107
+ exports.IGNITEUI_PACKAGE = /^(@infragistics\/|@igniteui\/|igniteui-|ignite-ui(-|$))/;
108
+ function allDependencies(packageJson) {
109
+ return Object.assign(Object.assign({}, packageJson.devDependencies), packageJson.dependencies);
110
+ }
111
+ /** Version of a package installed for the current folder, looking through parent `node_modules` as Node does. */
112
+ function installedVersion(name) {
113
+ var _a;
114
+ const fileSystem = cli_core_1.App.container.get(cli_core_1.FS_TOKEN);
115
+ let dir = process.cwd();
116
+ for (;;) {
117
+ const manifest = path.join(dir, "node_modules", name, "package.json");
118
+ if (fileSystem.fileExists(manifest)) {
119
+ try {
120
+ return (_a = JSON.parse(fileSystem.readFile(manifest)).version) !== null && _a !== void 0 ? _a : null;
121
+ }
122
+ catch (_b) {
123
+ return null;
124
+ }
125
+ }
126
+ const parent = path.dirname(dir);
127
+ if (parent === dir) {
128
+ return null;
129
+ }
130
+ dir = parent;
131
+ }
132
+ }