@zeroheight/adoption-cli 3.0.2 → 3.1.1-rc.1

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/cli.d.ts +8 -5
  3. package/dist/cli.js +12924 -35
  4. package/package.json +11 -6
  5. package/dist/ast/analyze.d.ts +0 -50
  6. package/dist/ast/analyze.js +0 -247
  7. package/dist/ast/parser.d.ts +0 -13
  8. package/dist/ast/parser.js +0 -14
  9. package/dist/commands/analyze.d.ts +0 -16
  10. package/dist/commands/analyze.js +0 -53
  11. package/dist/commands/analyze.utils.d.ts +0 -27
  12. package/dist/commands/analyze.utils.js +0 -204
  13. package/dist/commands/auth.d.ts +0 -9
  14. package/dist/commands/auth.js +0 -28
  15. package/dist/commands/monitor-repo.d.ts +0 -10
  16. package/dist/commands/monitor-repo.js +0 -42
  17. package/dist/commands/monitor-repo.utils.d.ts +0 -31
  18. package/dist/commands/monitor-repo.utils.js +0 -81
  19. package/dist/commands/track-package.d.ts +0 -9
  20. package/dist/commands/track-package.js +0 -41
  21. package/dist/commands/track-package.utils.d.ts +0 -25
  22. package/dist/commands/track-package.utils.js +0 -82
  23. package/dist/common/api.d.ts +0 -113
  24. package/dist/common/api.js +0 -174
  25. package/dist/common/config.d.ts +0 -14
  26. package/dist/common/config.js +0 -41
  27. package/dist/common/errors.d.ts +0 -15
  28. package/dist/common/errors.js +0 -26
  29. package/dist/common/logging.d.ts +0 -4
  30. package/dist/common/logging.js +0 -26
  31. package/dist/common/types/package-file.d.ts +0 -13
  32. package/dist/common/types/package-file.js +0 -1
  33. package/dist/components/analyze/analyze.d.ts +0 -14
  34. package/dist/components/analyze/analyze.js +0 -428
  35. package/dist/components/analyze/non-interactive-analyze.d.ts +0 -16
  36. package/dist/components/analyze/non-interactive-analyze.js +0 -164
  37. package/dist/components/auth/auth.d.ts +0 -7
  38. package/dist/components/auth/auth.js +0 -119
  39. package/dist/components/auth/credentials-already-exists.d.ts +0 -13
  40. package/dist/components/auth/credentials-already-exists.js +0 -16
  41. package/dist/components/auth/credentials-preview.d.ts +0 -10
  42. package/dist/components/auth/credentials-preview.js +0 -20
  43. package/dist/components/auth/no-credentials-onboarding.d.ts +0 -8
  44. package/dist/components/auth/no-credentials-onboarding.js +0 -62
  45. package/dist/components/color-usage-table.d.ts +0 -7
  46. package/dist/components/color-usage-table.js +0 -38
  47. package/dist/components/help-info.d.ts +0 -5
  48. package/dist/components/help-info.js +0 -24
  49. package/dist/components/latest-version-info.d.ts +0 -9
  50. package/dist/components/latest-version-info.js +0 -27
  51. package/dist/components/monitor-repo/monitor-repo.d.ts +0 -2
  52. package/dist/components/monitor-repo/monitor-repo.js +0 -9
  53. package/dist/components/monitor-repo/non-interactive-monitor-repo.d.ts +0 -7
  54. package/dist/components/monitor-repo/non-interactive-monitor-repo.js +0 -127
  55. package/dist/components/repo-name-prompt.d.ts +0 -8
  56. package/dist/components/repo-name-prompt.js +0 -97
  57. package/dist/components/track-package/non-interactive-track-package.d.ts +0 -5
  58. package/dist/components/track-package/non-interactive-track-package.js +0 -117
  59. package/dist/components/track-package/track-package.d.ts +0 -2
  60. package/dist/components/track-package/track-package.js +0 -206
  61. package/dist/components/ui/confirm-input.d.ts +0 -10
  62. package/dist/components/ui/confirm-input.js +0 -10
  63. package/dist/components/ui/continue-prompt.d.ts +0 -6
  64. package/dist/components/ui/continue-prompt.js +0 -16
  65. package/dist/components/usage-table.d.ts +0 -7
  66. package/dist/components/usage-table.js +0 -14
  67. package/dist/lockfile-parsers/lock-parser.d.ts +0 -9
  68. package/dist/lockfile-parsers/lock-parser.js +0 -5
  69. package/dist/lockfile-parsers/npm-lock-parser.d.ts +0 -6
  70. package/dist/lockfile-parsers/npm-lock-parser.js +0 -54
  71. package/dist/lockfile-parsers/pnpm-lock-parser.d.ts +0 -6
  72. package/dist/lockfile-parsers/pnpm-lock-parser.js +0 -51
  73. package/dist/lockfile-parsers/yarn-lock-parser.d.ts +0 -6
  74. package/dist/lockfile-parsers/yarn-lock-parser.js +0 -70
@@ -1,428 +0,0 @@
1
- import React from "react";
2
- import Spinner from "ink-spinner";
3
- import { Box, Newline, Text, useApp } from "ink";
4
- import Link from "ink-link";
5
- import ConfirmInput from "../ui/confirm-input.js";
6
- import ContinuePrompt from "../ui/continue-prompt.js";
7
- import NoCredentialsOnboarding from "../auth/no-credentials-onboarding.js";
8
- import RepoNamePrompt from "../repo-name-prompt.js";
9
- import UsageTable from "../usage-table.js";
10
- import { configPath, writeConfig, readConfig, } from "../../common/config.js";
11
- import { ResponseStatus, getAuthDetails, getZeroheightURL, submitComponentUsageData, submitTokenLiteralUsageData, } from "../../common/api.js";
12
- import { calculateNumberOfColors, calculateNumberOfComponents, } from "../../commands/analyze.utils.js";
13
- import { ApiError } from "../../common/errors.js";
14
- import ColorUsageTable from "../color-usage-table.js";
15
- var AnalyzeStage;
16
- (function (AnalyzeStage) {
17
- AnalyzeStage[AnalyzeStage["initial"] = 0] = "initial";
18
- AnalyzeStage[AnalyzeStage["finished"] = 1] = "finished";
19
- AnalyzeStage[AnalyzeStage["fetchCredentials"] = 2] = "fetchCredentials";
20
- AnalyzeStage[AnalyzeStage["fetchRepoNames"] = 3] = "fetchRepoNames";
21
- AnalyzeStage[AnalyzeStage["cuScanningFiles"] = 4] = "cuScanningFiles";
22
- AnalyzeStage[AnalyzeStage["cuScanComplete"] = 5] = "cuScanComplete";
23
- AnalyzeStage[AnalyzeStage["cuShowMoreDetails"] = 6] = "cuShowMoreDetails";
24
- AnalyzeStage[AnalyzeStage["cuSendDataCheck"] = 7] = "cuSendDataCheck";
25
- AnalyzeStage[AnalyzeStage["cuAuthSetUp"] = 8] = "cuAuthSetUp";
26
- AnalyzeStage[AnalyzeStage["cuRepoSelection"] = 9] = "cuRepoSelection";
27
- AnalyzeStage[AnalyzeStage["cuSendingData"] = 10] = "cuSendingData";
28
- AnalyzeStage[AnalyzeStage["cuSendSuccess"] = 11] = "cuSendSuccess";
29
- AnalyzeStage[AnalyzeStage["tuConfirmRun"] = 12] = "tuConfirmRun";
30
- AnalyzeStage[AnalyzeStage["tuScanningFiles"] = 13] = "tuScanningFiles";
31
- AnalyzeStage[AnalyzeStage["tuScanComplete"] = 14] = "tuScanComplete";
32
- AnalyzeStage[AnalyzeStage["tuShowMoreDetails"] = 15] = "tuShowMoreDetails";
33
- AnalyzeStage[AnalyzeStage["tuSendDataCheck"] = 16] = "tuSendDataCheck";
34
- AnalyzeStage[AnalyzeStage["tuAuthSetUp"] = 17] = "tuAuthSetUp";
35
- AnalyzeStage[AnalyzeStage["tuRepoSelection"] = 18] = "tuRepoSelection";
36
- AnalyzeStage[AnalyzeStage["tuSendingData"] = 19] = "tuSendingData";
37
- AnalyzeStage[AnalyzeStage["tuSendSuccess"] = 20] = "tuSendSuccess";
38
- })(AnalyzeStage || (AnalyzeStage = {}));
39
- export default function Analyze({ onAnalyzeFiles, onAnalyzeColorUsage, repoName, }) {
40
- const { exit } = useApp();
41
- const [currentStage, setCurrentStage] = React.useState(AnalyzeStage.initial);
42
- // Result states
43
- const [componentUsageResult, setComponentUsageResult] = React.useState(new Map());
44
- const [colorUsageResult, setColorUsageResult] = React.useState(new Map());
45
- const [errorList, setErrorList] = React.useState([]);
46
- const [errorFileLocation, setErrorFileLocation] = React.useState(null);
47
- // Set up states
48
- const [credentials, setCredentials] = React.useState(null);
49
- const [resourceURL, setResourceURL] = React.useState(getZeroheightURL());
50
- const [repo, setRepo] = React.useState(repoName);
51
- // Text input states
52
- const [continueToTokenUsage, setContinueToTokenUsage] = React.useState("");
53
- const [runComponentUsage, setRunComponentUsage] = React.useState("");
54
- const [runTokenUsage, setRunTokenUsage] = React.useState("");
55
- const [showMoreResults, setShowMoreResults] = React.useState("");
56
- // Component usage
57
- function handleStartComponentUsage(shouldScan) {
58
- if (shouldScan) {
59
- setCurrentStage(AnalyzeStage.cuScanningFiles);
60
- analyzeComponentUsage();
61
- }
62
- else {
63
- setCurrentStage(AnalyzeStage.tuConfirmRun);
64
- }
65
- }
66
- async function analyzeComponentUsage() {
67
- try {
68
- const { errorFile, usage } = await onAnalyzeFiles();
69
- setErrorFileLocation(errorFile);
70
- setComponentUsageResult(usage);
71
- setCurrentStage(AnalyzeStage.cuScanComplete);
72
- }
73
- catch (e) {
74
- setErrorList((s) => [...s, e]);
75
- }
76
- }
77
- function handleShowMore(showMore) {
78
- if (showMore) {
79
- setCurrentStage(AnalyzeStage.cuShowMoreDetails);
80
- }
81
- else {
82
- setCurrentStage(AnalyzeStage.cuSendDataCheck);
83
- }
84
- }
85
- async function handleSendCuData(shouldSend) {
86
- if (shouldSend) {
87
- const creds = await fetchCredentials();
88
- if (!creds) {
89
- setCurrentStage(AnalyzeStage.cuAuthSetUp);
90
- return;
91
- }
92
- if (!repo) {
93
- setCurrentStage(AnalyzeStage.cuRepoSelection);
94
- return;
95
- }
96
- setCurrentStage(AnalyzeStage.cuSendingData);
97
- sendCuData(componentUsageResult, repo, creds);
98
- }
99
- else {
100
- setCurrentStage(AnalyzeStage.tuConfirmRun);
101
- }
102
- }
103
- async function fetchCredentials() {
104
- try {
105
- const config = await readConfig();
106
- if (config) {
107
- setCredentials({ token: config.token, client: config.client });
108
- return { token: config.token, client: config.client };
109
- }
110
- return null;
111
- }
112
- catch (e) {
113
- setErrorList((s) => [...s, "Failed to load credentials"]);
114
- return null;
115
- }
116
- }
117
- async function sendCuData(result, repoName, credentials) {
118
- try {
119
- await submitComponentUsageData(result, repoName, credentials);
120
- const authDetailsResponse = await getAuthDetails(credentials);
121
- if (authDetailsResponse.status !== ResponseStatus.Success) {
122
- throw new Error("Failed to get credentials");
123
- }
124
- const projectId = authDetailsResponse.data.project?.id;
125
- const resourceURL = getZeroheightURL();
126
- resourceURL.pathname = projectId
127
- ? `/project/${projectId}/adoption/`
128
- : "/adoption/";
129
- setResourceURL(resourceURL);
130
- setCurrentStage(AnalyzeStage.cuSendSuccess);
131
- }
132
- catch (e) {
133
- let errorMessage = "Failed to send data to zeroheight";
134
- if (e instanceof ApiError) {
135
- errorMessage = e.message;
136
- }
137
- setErrorList((s) => [...s, errorMessage]);
138
- }
139
- }
140
- function handleOnRepoNameSelected(repoName) {
141
- setRepo(repoName);
142
- writeConfig({
143
- repoNames: {
144
- [process.cwd()]: repoName,
145
- },
146
- });
147
- if (currentStage === AnalyzeStage.cuRepoSelection) {
148
- handleSendCuData(true);
149
- setCurrentStage(AnalyzeStage.cuSendingData);
150
- }
151
- else {
152
- handleSendTuData(true);
153
- setCurrentStage(AnalyzeStage.tuSendingData);
154
- }
155
- }
156
- async function handleCheckCredentials(newClient, newToken) {
157
- try {
158
- await getAuthDetails({ token: newToken, client: newClient });
159
- }
160
- catch {
161
- setErrorList(["Auth credentials are not valid"]);
162
- return exit();
163
- }
164
- }
165
- // Token usage
166
- function startTokenUsageFlow(shouldContinue) {
167
- if (shouldContinue) {
168
- setCurrentStage(AnalyzeStage.tuConfirmRun);
169
- }
170
- else {
171
- setCurrentStage(AnalyzeStage.finished);
172
- }
173
- }
174
- function handleStartTokenUsage(shouldScan) {
175
- if (shouldScan) {
176
- setCurrentStage(AnalyzeStage.tuScanningFiles);
177
- analyzeTokenUsage();
178
- }
179
- else {
180
- setCurrentStage(AnalyzeStage.finished);
181
- }
182
- }
183
- async function analyzeTokenUsage() {
184
- try {
185
- const { errorFile, usage } = await onAnalyzeColorUsage();
186
- setErrorFileLocation(errorFile);
187
- setColorUsageResult(usage);
188
- setCurrentStage(AnalyzeStage.tuScanComplete);
189
- }
190
- catch (e) {
191
- setErrorList((s) => [...s, e]);
192
- }
193
- }
194
- function handleShowMoreTU(showMore) {
195
- if (showMore) {
196
- setCurrentStage(AnalyzeStage.tuShowMoreDetails);
197
- }
198
- else {
199
- setCurrentStage(AnalyzeStage.tuSendDataCheck);
200
- }
201
- }
202
- async function handleSendTuData(shouldSend) {
203
- if (shouldSend) {
204
- const creds = await fetchCredentials();
205
- if (!creds) {
206
- setCurrentStage(AnalyzeStage.tuAuthSetUp);
207
- return;
208
- }
209
- if (!repo) {
210
- setCurrentStage(AnalyzeStage.tuRepoSelection);
211
- return;
212
- }
213
- setCurrentStage(AnalyzeStage.tuSendingData);
214
- sendTuData(colorUsageResult, repo, creds);
215
- }
216
- else {
217
- setCurrentStage(AnalyzeStage.finished);
218
- exit();
219
- }
220
- }
221
- async function sendTuData(result, repoName, credentials) {
222
- try {
223
- await submitTokenLiteralUsageData(result, repoName, credentials);
224
- const authDetailsResponse = await getAuthDetails(credentials);
225
- if (authDetailsResponse.status !== ResponseStatus.Success) {
226
- throw new Error("Failed to get credentials");
227
- }
228
- const projectId = authDetailsResponse.data.project?.id;
229
- const resourceURL = getZeroheightURL();
230
- resourceURL.pathname = projectId
231
- ? `/project/${projectId}/adoption/`
232
- : "/adoption/";
233
- setResourceURL(resourceURL);
234
- setCurrentStage(AnalyzeStage.tuSendSuccess);
235
- }
236
- catch (e) {
237
- let errorMessage = "Failed to send data to zeroheight";
238
- if (e instanceof ApiError) {
239
- errorMessage = e.message;
240
- }
241
- setErrorList((s) => [...s, errorMessage]);
242
- }
243
- }
244
- // UI flow
245
- if (errorList.length > 0) {
246
- return (React.createElement(Box, { flexDirection: "column" },
247
- React.createElement(Text, { color: "red" }, "Error:"),
248
- React.createElement(Box, { flexDirection: "column", marginLeft: 1 }, errorList.map((e) => (React.createElement(React.Fragment, null,
249
- React.createElement(Text, { key: e }, e),
250
- React.createElement(Newline, null)))))));
251
- }
252
- if (currentStage === AnalyzeStage.initial) {
253
- return (React.createElement(Box, { flexDirection: "column" },
254
- React.createElement(Text, null,
255
- "\uD83D\uDC4B Welcome to the ",
256
- React.createElement(Text, { color: "#f63e7c" }, "zeroheight"),
257
- " analyze tool"),
258
- React.createElement(Newline, null),
259
- React.createElement(Box, { flexDirection: "column" },
260
- React.createElement(Text, null,
261
- "\u2753 Would you like to us to scan the files in this project to understand how components are being used (React only)?",
262
- " ",
263
- React.createElement(Text, { dimColor: true }, "(Y/n)")),
264
- React.createElement(ConfirmInput, { isChecked: true, value: runComponentUsage, onChange: setRunComponentUsage, onSubmit: handleStartComponentUsage }))));
265
- }
266
- if (currentStage === AnalyzeStage.cuScanningFiles) {
267
- return (React.createElement(Text, null,
268
- React.createElement(Text, { color: "green" },
269
- React.createElement(Spinner, { type: "dots" })),
270
- " Scanning files for component usage..."));
271
- }
272
- if (currentStage === AnalyzeStage.cuScanComplete) {
273
- if (componentUsageResult?.size > 0) {
274
- return (React.createElement(Box, { flexDirection: "column" },
275
- React.createElement(Text, { color: "green" },
276
- calculateNumberOfComponents(componentUsageResult),
277
- " components found"),
278
- errorFileLocation && (React.createElement(React.Fragment, null,
279
- React.createElement(Newline, null),
280
- React.createElement(Box, null,
281
- React.createElement(Text, { color: "red" }, "Error:"),
282
- React.createElement(Text, null,
283
- " ",
284
- "Some files could not be parsed. Errors can be found at",
285
- " ",
286
- React.createElement(Link, { url: errorFileLocation }, errorFileLocation))))),
287
- React.createElement(Box, null,
288
- React.createElement(Text, null,
289
- "Show more details? ",
290
- React.createElement(Text, { dimColor: true }, "(y/N)")),
291
- React.createElement(ConfirmInput, { isChecked: false, value: showMoreResults, onChange: setShowMoreResults, onSubmit: handleShowMore }))));
292
- }
293
- else {
294
- return (React.createElement(Box, { flexDirection: "column" },
295
- React.createElement(Box, null,
296
- React.createElement(Text, null, "No files found, try a different directory or change the file extensions you want to include.")),
297
- React.createElement(Box, null,
298
- React.createElement(Text, null,
299
- "Continue to token usage analysis? ",
300
- React.createElement(Text, { dimColor: true }, "(Y/n)")),
301
- React.createElement(ConfirmInput, { isChecked: true, value: continueToTokenUsage, onChange: setContinueToTokenUsage, onSubmit: startTokenUsageFlow }))));
302
- }
303
- }
304
- if (currentStage === AnalyzeStage.cuShowMoreDetails) {
305
- return (React.createElement(Box, { flexDirection: "column" },
306
- React.createElement(UsageTable, { usage: componentUsageResult }),
307
- React.createElement(Newline, null),
308
- React.createElement(ContinuePrompt, { onContinue: handleSendCuData })));
309
- }
310
- if (currentStage === AnalyzeStage.cuSendDataCheck) {
311
- return React.createElement(ContinuePrompt, { onContinue: handleSendCuData });
312
- }
313
- if (currentStage === AnalyzeStage.cuAuthSetUp ||
314
- currentStage === AnalyzeStage.tuAuthSetUp) {
315
- return (React.createElement(NoCredentialsOnboarding, { configPath: configPath(), onCheckCredentials: handleCheckCredentials, onSaveCredentials: async (persist, newClient, newToken) => {
316
- const newCredentials = { token: newToken, client: newClient };
317
- setCredentials(newCredentials);
318
- if (persist) {
319
- await writeConfig({
320
- client: newClient,
321
- token: newToken,
322
- });
323
- }
324
- if (currentStage === AnalyzeStage.cuAuthSetUp) {
325
- handleSendCuData(true);
326
- setCurrentStage(AnalyzeStage.cuSendingData);
327
- }
328
- else {
329
- handleSendTuData(true);
330
- setCurrentStage(AnalyzeStage.tuSendingData);
331
- }
332
- } }));
333
- }
334
- if (currentStage === AnalyzeStage.cuRepoSelection ||
335
- currentStage === AnalyzeStage.tuRepoSelection) {
336
- return (React.createElement(RepoNamePrompt, { credentials: credentials, onRepoNameSelected: handleOnRepoNameSelected }));
337
- }
338
- if (currentStage === AnalyzeStage.cuSendingData ||
339
- currentStage === AnalyzeStage.tuSendingData) {
340
- return (React.createElement(Text, null,
341
- React.createElement(Text, { color: "green" },
342
- React.createElement(Spinner, { type: "dots" })),
343
- " ",
344
- "Sending usage data to ",
345
- React.createElement(Text, { color: "#f63e7c" }, "zeroheight"),
346
- "..."));
347
- }
348
- if (currentStage === AnalyzeStage.cuSendSuccess) {
349
- return (React.createElement(Box, { flexDirection: "column" },
350
- React.createElement(Text, null,
351
- React.createElement(Text, { color: "green" }, "Successfully sent:"),
352
- " View your",
353
- " ",
354
- React.createElement(Link, { url: resourceURL.toString() },
355
- React.createElement(Text, { underline: true, color: "#f63e7c" }, "usage data on zeroheight"))),
356
- React.createElement(Newline, null),
357
- React.createElement(Box, null,
358
- React.createElement(Text, null,
359
- "\u2753 Would you like to us to scan the files in this project to understand how colors are being used? ",
360
- React.createElement(Text, { dimColor: true }, "(Y/n)")),
361
- React.createElement(ConfirmInput, { isChecked: true, value: runTokenUsage, onChange: setRunTokenUsage, onSubmit: handleStartTokenUsage }))));
362
- }
363
- if (currentStage === AnalyzeStage.tuConfirmRun) {
364
- return (React.createElement(Box, { flexDirection: "column" },
365
- React.createElement(Box, null,
366
- React.createElement(Text, null,
367
- "\u2753 Would you like to us to scan the files in this project to understand how colors are being used? ",
368
- React.createElement(Text, { dimColor: true }, "(Y/n)")),
369
- React.createElement(ConfirmInput, { isChecked: true, value: runTokenUsage, onChange: setRunTokenUsage, onSubmit: handleStartTokenUsage }))));
370
- }
371
- if (currentStage === AnalyzeStage.tuScanningFiles) {
372
- return (React.createElement(Text, null,
373
- React.createElement(Text, { color: "green" },
374
- React.createElement(Spinner, { type: "dots" })),
375
- " Scanning files for color usage..."));
376
- }
377
- if (currentStage === AnalyzeStage.tuScanComplete) {
378
- if (colorUsageResult?.size > 0) {
379
- return (React.createElement(Box, { flexDirection: "column" },
380
- React.createElement(Text, { color: "green" },
381
- calculateNumberOfColors(colorUsageResult),
382
- " instatances of raw color usage found"),
383
- errorFileLocation && (React.createElement(React.Fragment, null,
384
- React.createElement(Newline, null),
385
- React.createElement(Box, null,
386
- React.createElement(Text, { color: "red" }, "Error:"),
387
- React.createElement(Text, null,
388
- " ",
389
- "Some files could not be parsed. Errors can be found at",
390
- " ",
391
- React.createElement(Link, { url: errorFileLocation }, errorFileLocation))))),
392
- React.createElement(Box, null,
393
- React.createElement(Text, null,
394
- "Show more details? ",
395
- React.createElement(Text, { dimColor: true }, "(y/N)")),
396
- React.createElement(ConfirmInput, { isChecked: false, value: showMoreResults, onChange: setShowMoreResults, onSubmit: handleShowMoreTU }))));
397
- }
398
- else {
399
- return (React.createElement(Box, { flexDirection: "column" },
400
- React.createElement(Text, null, "No files found, try a different directory or change the file extensions you want to include.")));
401
- }
402
- }
403
- if (currentStage === AnalyzeStage.tuShowMoreDetails) {
404
- return (React.createElement(Box, { flexDirection: "column" },
405
- React.createElement(ColorUsageTable, { usage: colorUsageResult }),
406
- React.createElement(Newline, null),
407
- React.createElement(ContinuePrompt, { onContinue: handleSendTuData })));
408
- }
409
- if (currentStage === AnalyzeStage.tuSendDataCheck) {
410
- return React.createElement(ContinuePrompt, { onContinue: handleSendTuData });
411
- }
412
- if (currentStage === AnalyzeStage.tuSendSuccess) {
413
- return (React.createElement(Box, { flexDirection: "column" },
414
- React.createElement(Text, null,
415
- React.createElement(Text, { color: "green" }, "Successfully sent:"),
416
- " View your",
417
- " ",
418
- React.createElement(Link, { url: resourceURL.toString() },
419
- React.createElement(Text, { underline: true, color: "#f63e7c" }, "usage data on zeroheight"))),
420
- React.createElement(Newline, null),
421
- React.createElement(Text, null, "\uD83D\uDC4B See you next time!")));
422
- }
423
- if (currentStage === AnalyzeStage.finished) {
424
- return (React.createElement(Box, { flexDirection: "column" },
425
- React.createElement(Text, null, "\uD83D\uDC4B See you next time!")));
426
- }
427
- return React.createElement(Text, null, "Analzye complete");
428
- }
@@ -1,16 +0,0 @@
1
- import React from "react";
2
- import { RawColorUsageMap, RawComponentUsageMap } from "../../commands/analyze.js";
3
- export interface NonInteractiveAnalyzeProps {
4
- onAnalyzeFiles: () => Promise<{
5
- errorFile: string | null;
6
- usage: RawComponentUsageMap;
7
- }>;
8
- onAnalyzeColorUsage: () => Promise<{
9
- errorFile: string | null;
10
- usage: RawColorUsageMap;
11
- }>;
12
- repoName?: string;
13
- shouldAnalyzeComponentUsage: boolean;
14
- shouldAnalyzeTokenUsage: boolean;
15
- }
16
- export default function NonInteractiveAnalyze({ repoName, onAnalyzeFiles, onAnalyzeColorUsage, shouldAnalyzeComponentUsage, shouldAnalyzeTokenUsage, }: NonInteractiveAnalyzeProps): React.JSX.Element;
@@ -1,164 +0,0 @@
1
- import React from "react";
2
- import { Box, Newline, Text } from "ink";
3
- import Spinner from "ink-spinner";
4
- import Link from "ink-link";
5
- import { calculateNumberOfColors, calculateNumberOfComponents, } from "../../commands/analyze.utils.js";
6
- import { readConfig } from "../../common/config.js";
7
- import { submitComponentUsageData, submitTokenLiteralUsageData, } from "../../common/api.js";
8
- import { ApiError } from "../../common/errors.js";
9
- export default function NonInteractiveAnalyze({ repoName, onAnalyzeFiles, onAnalyzeColorUsage, shouldAnalyzeComponentUsage, shouldAnalyzeTokenUsage, }) {
10
- const [isSendingData, setIsSendingData] = React.useState(false);
11
- const [isAnalyzingFiles, setIsAnalyzingFiles] = React.useState(false);
12
- const [isFetchingCredentials, setIsFetchingCredentials] = React.useState(false);
13
- const [errorFileLocation, setErrorFileLocation] = React.useState(null);
14
- const [errorList, setErrorList] = React.useState([]);
15
- const [credentials, setCredentials] = React.useState(null);
16
- const [componentUsage, setComponentUsage] = React.useState(null);
17
- const [colorUsage, setColorUsage] = React.useState(null);
18
- async function loadCredentials() {
19
- setIsFetchingCredentials(true);
20
- try {
21
- const config = await readConfig();
22
- if (config) {
23
- setCredentials({ token: config.token, client: config.client });
24
- }
25
- return config;
26
- }
27
- catch (e) {
28
- setErrorList((s) => [...s, "Failed to load credentials"]);
29
- }
30
- finally {
31
- setIsFetchingCredentials(false);
32
- }
33
- return null;
34
- }
35
- async function sendComponentUsageData(result, repoName, credentials) {
36
- setIsSendingData(true);
37
- try {
38
- await submitComponentUsageData(result, repoName, credentials);
39
- }
40
- catch (e) {
41
- let errorMessage = "Failed to send component usage data to zeroheight";
42
- if (e instanceof ApiError) {
43
- errorMessage = e.message;
44
- }
45
- setErrorList((s) => [...s, errorMessage]);
46
- }
47
- finally {
48
- setIsSendingData(false);
49
- }
50
- }
51
- async function sendTokenUsageData(result, repoName, credentials) {
52
- setIsSendingData(true);
53
- try {
54
- await submitTokenLiteralUsageData(result, repoName, credentials);
55
- }
56
- catch (e) {
57
- let errorMessage = "Failed to send color usage data to zeroheight";
58
- if (e instanceof ApiError) {
59
- errorMessage = e.message;
60
- }
61
- setErrorList((s) => [...s, errorMessage]);
62
- }
63
- finally {
64
- setIsSendingData(false);
65
- }
66
- }
67
- async function analyzeComponentUsage() {
68
- setIsAnalyzingFiles(true);
69
- const { errorFile, usage } = await onAnalyzeFiles();
70
- setComponentUsage(usage);
71
- if (errorFile) {
72
- setErrorFileLocation(errorFile);
73
- }
74
- setIsAnalyzingFiles(false);
75
- return usage;
76
- }
77
- async function analyzeTokenUsage() {
78
- setIsAnalyzingFiles(true);
79
- const { errorFile, usage } = await onAnalyzeColorUsage();
80
- setColorUsage(usage);
81
- if (errorFile) {
82
- setErrorFileLocation(errorFile);
83
- }
84
- setIsAnalyzingFiles(false);
85
- return usage;
86
- }
87
- React.useEffect(() => {
88
- (async () => {
89
- const credentials = await loadCredentials();
90
- if (!credentials)
91
- return;
92
- if (!repoName)
93
- return;
94
- if (shouldAnalyzeComponentUsage) {
95
- const componentUsageMap = await analyzeComponentUsage();
96
- await sendComponentUsageData(componentUsageMap, repoName, credentials);
97
- }
98
- if (shouldAnalyzeTokenUsage) {
99
- const colorUsageMap = await analyzeTokenUsage();
100
- await sendTokenUsageData(colorUsageMap, repoName, credentials);
101
- }
102
- })();
103
- }, []);
104
- if (isAnalyzingFiles || isFetchingCredentials || isSendingData) {
105
- return (React.createElement(Text, null,
106
- React.createElement(Spinner, { type: "dots" }),
107
- " ",
108
- isAnalyzingFiles && React.createElement(Text, null, "Analyzing files"),
109
- isFetchingCredentials && React.createElement(Text, null, "Loading credentials"),
110
- isSendingData && React.createElement(Text, null, "Sending data to zeroheight")));
111
- }
112
- if (errorList.length > 0) {
113
- return (React.createElement(Box, { flexDirection: "column" },
114
- React.createElement(Text, { color: "red" }, "Error:"),
115
- React.createElement(Box, { flexDirection: "column", marginLeft: 1 }, errorList.map((e) => (React.createElement(Text, { key: e },
116
- "- ",
117
- e))))));
118
- }
119
- if (errorFileLocation) {
120
- return (React.createElement(React.Fragment, null,
121
- React.createElement(Newline, null),
122
- React.createElement(Box, null,
123
- React.createElement(Text, { color: "red" }, "Error:"),
124
- React.createElement(Text, null,
125
- " ",
126
- "Some files could not be parsed. Errors can be found at",
127
- " ",
128
- React.createElement(Link, { url: errorFileLocation }, errorFileLocation)))));
129
- }
130
- if (!repoName) {
131
- return (React.createElement(Text, null,
132
- React.createElement(Text, { bold: true }, "Repo name"),
133
- " not found, run the ",
134
- React.createElement(Text, { bold: true }, "analyze"),
135
- " ",
136
- "command in interactive mode or provide the",
137
- " ",
138
- React.createElement(Text, { italic: true },
139
- "--repo-name ",
140
- "<my repo name>"),
141
- " option"));
142
- }
143
- if (!credentials) {
144
- return (React.createElement(Text, null,
145
- "Credentials not found, please ensure they are set before running the",
146
- " ",
147
- React.createElement(Text, { bold: true }, "analyze"),
148
- " command with",
149
- " ",
150
- React.createElement(Text, { italic: true }, "--interactive false")));
151
- }
152
- if (!componentUsage && !colorUsage) {
153
- return React.createElement(Text, null, "No usage could be found.");
154
- }
155
- return (React.createElement(React.Fragment, null,
156
- componentUsage && (React.createElement(Text, { color: "green" },
157
- calculateNumberOfComponents(componentUsage),
158
- " components found and sent to ",
159
- React.createElement(Text, { color: "#f63e7c" }, "zeroheight"))),
160
- colorUsage && (React.createElement(Text, { color: "green" },
161
- calculateNumberOfColors(colorUsage),
162
- " usages of raw colors found and sent to ",
163
- React.createElement(Text, { color: "#f63e7c" }, "zeroheight")))));
164
- }
@@ -1,7 +0,0 @@
1
- import React from "react";
2
- interface AuthProps {
3
- token?: string;
4
- client?: string;
5
- }
6
- export default function Auth({ token, client }: AuthProps): React.JSX.Element;
7
- export {};