@zeroheight/adoption-cli 0.3.0 → 0.3.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Release notes
|
|
2
2
|
|
|
3
|
+
## [0.3.1](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.3.1) - 30th July 2024
|
|
4
|
+
|
|
5
|
+
- Condense analyze output to be easier to parse
|
|
6
|
+
- Output parsing errors into log file
|
|
7
|
+
|
|
3
8
|
## [0.3.0](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.3.0) - 29th July 2024
|
|
4
9
|
|
|
5
10
|
- Replace acorn parser with oxc-parser
|
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ const { output, cleanup } = render(React.createElement(HelpInfo, null));
|
|
|
10
10
|
program
|
|
11
11
|
.name("zh-adoption")
|
|
12
12
|
.description("CLI for measuring design system usage usage in your products")
|
|
13
|
-
.version("0.
|
|
13
|
+
.version("0.3.1")
|
|
14
14
|
.addHelpText("before", output)
|
|
15
15
|
.addCommand(analyzeCommand())
|
|
16
16
|
.addCommand(authCommand());
|
|
@@ -15,6 +15,6 @@ export interface ComponentUsageRecord {
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function findFiles(base: string, extensions: string, ignorePattern: string): Promise<string[]>;
|
|
17
17
|
export declare function analyzeFiles(extensions: string, ignorePattern: string): Promise<{
|
|
18
|
-
|
|
18
|
+
errorFile: string | null;
|
|
19
19
|
usage: RawUsageMap;
|
|
20
20
|
}>;
|
|
@@ -51,6 +51,7 @@ export async function analyzeFiles(extensions, ignorePattern) {
|
|
|
51
51
|
if (files.length === 0) {
|
|
52
52
|
throw new Error("Can't find any relevant files");
|
|
53
53
|
}
|
|
54
|
+
const parseErrors = [];
|
|
54
55
|
const usageMap = new Map();
|
|
55
56
|
for (const file of files) {
|
|
56
57
|
try {
|
|
@@ -62,7 +63,15 @@ export async function analyzeFiles(extensions, ignorePattern) {
|
|
|
62
63
|
usageMap.set(relativePath, usage);
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
|
-
catch {
|
|
66
|
+
catch {
|
|
67
|
+
parseErrors.push(`Can't parse file ${file}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const errorFile = `/tmp/zh-adoption-analyze-errors-${Date.now()}`;
|
|
71
|
+
if (parseErrors.length > 0) {
|
|
72
|
+
const file = fs.createWriteStream(errorFile);
|
|
73
|
+
parseErrors.forEach((err) => { file.write(err + '\n'); });
|
|
74
|
+
file.end();
|
|
66
75
|
}
|
|
67
|
-
return {
|
|
76
|
+
return { errorFile: parseErrors.length > 0 ? errorFile : null, usage: usageMap };
|
|
68
77
|
}
|
|
@@ -8,19 +8,23 @@ import Link from "ink-link";
|
|
|
8
8
|
import NoCredentialsOnboarding from "../auth/no-credentials-onboarding.js";
|
|
9
9
|
import { getZeroheightURL, submitUsageData } from "../../common/api.js";
|
|
10
10
|
import RepoNamePrompt from "../repo-name-prompt.js";
|
|
11
|
+
import ConfirmInput from "../ui/confirm-input.js";
|
|
11
12
|
export default function Analyze({ onAnalyzeFiles, dryRun, repoName, }) {
|
|
12
13
|
const { exit } = useApp();
|
|
13
14
|
const [usageResult, setUsageResult] = React.useState(null);
|
|
14
15
|
const [isSendingData, setIsSendingData] = React.useState(false);
|
|
15
16
|
const [errorList, setErrorList] = React.useState([]);
|
|
17
|
+
const [errorFileLocation, setErrorFileLocation] = React.useState(null);
|
|
16
18
|
const [credentials, setCredentials] = React.useState(null);
|
|
17
19
|
const [resourceURL, setResourceURL] = React.useState(null);
|
|
18
20
|
const [repo, setRepo] = React.useState(repoName);
|
|
19
21
|
const [promptRepo, setPromptRepo] = React.useState(repoName === undefined);
|
|
22
|
+
const [showContinue, setShowContinue] = React.useState(false);
|
|
23
|
+
const [showMoreResults, setShowMoreResults] = React.useState("");
|
|
20
24
|
React.useEffect(() => {
|
|
21
25
|
onAnalyzeFiles()
|
|
22
|
-
.then(({
|
|
23
|
-
|
|
26
|
+
.then(({ errorFile, usage }) => {
|
|
27
|
+
setErrorFileLocation(errorFile);
|
|
24
28
|
setUsageResult(usage);
|
|
25
29
|
})
|
|
26
30
|
.catch((e) => setErrorList((s) => [...s, e]));
|
|
@@ -70,6 +74,24 @@ export default function Analyze({ onAnalyzeFiles, dryRun, repoName, }) {
|
|
|
70
74
|
});
|
|
71
75
|
setPromptRepo(false);
|
|
72
76
|
}
|
|
77
|
+
function handleShowMore(showMore) {
|
|
78
|
+
if (showMore) {
|
|
79
|
+
setShowMoreResults('true');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
setShowContinue(true);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function calculateNumberOfComponents() {
|
|
86
|
+
if (usageResult) {
|
|
87
|
+
const components = Array.from(usageResult.entries()).flatMap((comps) => comps[1]);
|
|
88
|
+
const componentCount = components.reduce((prev, next) => {
|
|
89
|
+
return prev + next.count;
|
|
90
|
+
}, 0);
|
|
91
|
+
return componentCount;
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
73
95
|
if (errorList.length > 0) {
|
|
74
96
|
return (React.createElement(Box, { flexDirection: "column" },
|
|
75
97
|
React.createElement(Text, { color: "red" }, "Error:"),
|
|
@@ -117,7 +139,27 @@ export default function Analyze({ onAnalyzeFiles, dryRun, repoName, }) {
|
|
|
117
139
|
" ",
|
|
118
140
|
React.createElement(Link, { url: resourceURL.toString() }, "usage data on zeroheight"))));
|
|
119
141
|
}
|
|
120
|
-
if (usageResult && !promptRepo) {
|
|
142
|
+
if (usageResult && !promptRepo && !(showMoreResults === 'true' || showContinue)) {
|
|
143
|
+
return (React.createElement(Box, { flexDirection: "column" },
|
|
144
|
+
React.createElement(Text, { color: "green" },
|
|
145
|
+
calculateNumberOfComponents(),
|
|
146
|
+
" components found"),
|
|
147
|
+
errorFileLocation && (React.createElement(React.Fragment, null,
|
|
148
|
+
React.createElement(Newline, null),
|
|
149
|
+
React.createElement(Box, null,
|
|
150
|
+
React.createElement(Text, { color: "red" }, "Error:"),
|
|
151
|
+
React.createElement(Text, null,
|
|
152
|
+
' ',
|
|
153
|
+
"Some files could not be parsed. Errors can be found at ",
|
|
154
|
+
React.createElement(Link, { url: errorFileLocation }, errorFileLocation))))),
|
|
155
|
+
React.createElement(Box, null,
|
|
156
|
+
React.createElement(Text, null,
|
|
157
|
+
"Show more details?",
|
|
158
|
+
" ",
|
|
159
|
+
React.createElement(Text, { dimColor: true }, "(y/N)")),
|
|
160
|
+
React.createElement(ConfirmInput, { isChecked: false, value: showMoreResults, onChange: setShowMoreResults, onSubmit: handleShowMore }))));
|
|
161
|
+
}
|
|
162
|
+
if (usageResult && !promptRepo && showMoreResults === 'true') {
|
|
121
163
|
return (React.createElement(Box, { flexDirection: "column" },
|
|
122
164
|
React.createElement(UsageTable, { usage: usageResult }),
|
|
123
165
|
dryRun && (React.createElement(React.Fragment, null,
|
|
@@ -129,6 +171,17 @@ export default function Analyze({ onAnalyzeFiles, dryRun, repoName, }) {
|
|
|
129
171
|
React.createElement(Newline, null))),
|
|
130
172
|
!dryRun && React.createElement(ContinuePrompt, { onContinue: handleContinue })));
|
|
131
173
|
}
|
|
174
|
+
if (usageResult && !promptRepo && showContinue) {
|
|
175
|
+
return (React.createElement(Box, { flexDirection: "column" },
|
|
176
|
+
dryRun && (React.createElement(React.Fragment, null,
|
|
177
|
+
React.createElement(Newline, null),
|
|
178
|
+
React.createElement(Text, null,
|
|
179
|
+
"Nothing sent to zeroheight, if you want to track component usage data then remove the ",
|
|
180
|
+
React.createElement(Text, { italic: true }, "--dry-run"),
|
|
181
|
+
" option."),
|
|
182
|
+
React.createElement(Newline, null))),
|
|
183
|
+
!dryRun && React.createElement(ContinuePrompt, { onContinue: handleContinue })));
|
|
184
|
+
}
|
|
132
185
|
if (promptRepo) {
|
|
133
186
|
return (React.createElement(RepoNamePrompt, { credentials: credentials, onRepoNameSelected: handleOnRepoNameSelected }));
|
|
134
187
|
}
|