@zeroheight/adoption-cli 0.2.10 → 0.2.12
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 +32 -0
- package/README.md +4 -2
- package/dist/cli.js +1 -1
- package/package.json +3 -2
- package/dist/ast/html/analyzer.d.ts +0 -3
- package/dist/ast/html/analyzer.js +0 -57
- package/dist/ast/html/parser.d.ts +0 -4
- package/dist/ast/html/parser.js +0 -6
- package/dist/ast/ts-js/analyzer.d.ts +0 -2
- package/dist/ast/ts-js/analyzer.js +0 -73
- package/dist/ast/ts-js/parser.d.ts +0 -6
- package/dist/ast/ts-js/parser.js +0 -14
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Release notes
|
|
2
|
+
|
|
3
|
+
## [0.2.12](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.12) - 24th July 2024
|
|
4
|
+
- Update release notes
|
|
5
|
+
|
|
6
|
+
## [0.2.11](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.11) - 24th July 2024
|
|
7
|
+
- Add accessible release notes
|
|
8
|
+
|
|
9
|
+
## [0.2.10](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.10) - 15th July 2024
|
|
10
|
+
- Add ability to reset authentication credentials
|
|
11
|
+
|
|
12
|
+
## [0.2.9](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.9) - 20th June 2024
|
|
13
|
+
- Update documentation links
|
|
14
|
+
|
|
15
|
+
## [0.2.8](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.8) - 19th June 2024
|
|
16
|
+
- Bug fixes
|
|
17
|
+
|
|
18
|
+
## [0.2.7](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.7) - 19th June 2024
|
|
19
|
+
- Bug fixes
|
|
20
|
+
|
|
21
|
+
## [0.2.6](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.6) - 19th June 2024
|
|
22
|
+
- Bug fixes
|
|
23
|
+
|
|
24
|
+
## [0.2.5](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.5) - 14th June 2024
|
|
25
|
+
- Add more support for TypeScript files
|
|
26
|
+
- Allow `--ignore` to be passed as an option
|
|
27
|
+
|
|
28
|
+
## [0.2.0](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.2.0) - 10th June 2024
|
|
29
|
+
- Add ability to define name of repository being analyzed
|
|
30
|
+
|
|
31
|
+
## [0.1.1](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/0.1.1) - 3rd June 2024
|
|
32
|
+
- Initial package set up
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @zeroheight/adoption-cli
|
|
2
2
|
|
|
3
|
-
CLI for measuring component usage
|
|
3
|
+
CLI for measuring component usage to view in your [zeroheight](https://zeroheight.com/) account.
|
|
4
|
+
|
|
5
|
+
See release notes [here](https://www.npmjs.com/package/@zeroheight/adoption-cli?activeTab=code)
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
@@ -16,7 +18,7 @@ In the repository in which you wish to analyze the component usage, run the foll
|
|
|
16
18
|
zh-adoption analyze
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
To send adoption data to your zeroheight account you will need to authenticate. This can be done as part of the `analyze` flow or separately by running:
|
|
21
|
+
To send adoption data to your [zeroheight](https://zeroheight.com/) account you will need to authenticate. This can be done as part of the `analyze` flow or separately by running:
|
|
20
22
|
|
|
21
23
|
```
|
|
22
24
|
zh-adoption auth
|
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.2.
|
|
13
|
+
.version("0.2.12")
|
|
14
14
|
.addHelpText("before", output)
|
|
15
15
|
.addCommand(analyzeCommand())
|
|
16
16
|
.addCommand(authCommand());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeroheight/adoption-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"test": "vitest"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
|
-
"dist"
|
|
24
|
+
"dist",
|
|
25
|
+
"CHANGELOG.md"
|
|
25
26
|
],
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"acorn": "^8.11.3",
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { visit } from "unist-util-visit";
|
|
2
|
-
import { visit as visitEstree } from "estree-util-visit";
|
|
3
|
-
import { transformVisitorStateToRawUsage, } from "../analyze.js";
|
|
4
|
-
import { parse as parseTSJS } from "../ts-js/parser.js";
|
|
5
|
-
export function analyze(tree) {
|
|
6
|
-
/**
|
|
7
|
-
* TODO: Populating imports means parsing JS files directly and finding:
|
|
8
|
-
* window.customElements.define('my-custom-element', MyCustomElement);
|
|
9
|
-
*/
|
|
10
|
-
const state = {
|
|
11
|
-
components: new Map(),
|
|
12
|
-
imports: new Map(),
|
|
13
|
-
};
|
|
14
|
-
const rawPaths = [];
|
|
15
|
-
visit(tree, (node) => {
|
|
16
|
-
if (node.type !== "element")
|
|
17
|
-
return;
|
|
18
|
-
if (node.tagName === "script") {
|
|
19
|
-
rawPaths.push(...analyzeScript(node));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const isCustomElement = node.tagName.includes("-");
|
|
23
|
-
if (!isCustomElement)
|
|
24
|
-
return;
|
|
25
|
-
state.components.set(node.tagName, (state.components.get(node.tagName) ?? 0) + 1);
|
|
26
|
-
// Dumb way of guessing import name
|
|
27
|
-
rawPaths.forEach((p) => {
|
|
28
|
-
if (p.includes(node.tagName)) {
|
|
29
|
-
state.imports.set(node.tagName, {
|
|
30
|
-
name: node.tagName,
|
|
31
|
-
package: p,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
return transformVisitorStateToRawUsage(state);
|
|
37
|
-
}
|
|
38
|
-
function analyzeScript(node) {
|
|
39
|
-
const importPaths = [];
|
|
40
|
-
const rawCode = node.children
|
|
41
|
-
.filter((child) => child.type === "text")
|
|
42
|
-
.map((child) => child.value)
|
|
43
|
-
.join("\n");
|
|
44
|
-
const tree = parseTSJS(rawCode, {
|
|
45
|
-
type: "ts-js",
|
|
46
|
-
version: "latest",
|
|
47
|
-
});
|
|
48
|
-
visitEstree(tree, (jsNode) => {
|
|
49
|
-
if (jsNode.type !== "ImportDeclaration")
|
|
50
|
-
return;
|
|
51
|
-
const rawPath = jsNode.source.value;
|
|
52
|
-
if (typeof rawPath === "string") {
|
|
53
|
-
importPaths.push(rawPath);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
return importPaths;
|
|
57
|
-
}
|
package/dist/ast/html/parser.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import * as walk from "acorn-walk";
|
|
2
|
-
import { transformVisitorStateToRawUsage } from "../analyze.js";
|
|
3
|
-
export function analyze(ast) {
|
|
4
|
-
const visitorState = {
|
|
5
|
-
components: new Map(),
|
|
6
|
-
imports: new Map(),
|
|
7
|
-
};
|
|
8
|
-
const visitors = {
|
|
9
|
-
JSXElement(node, state, _nodePath) {
|
|
10
|
-
const el = node.openingElement;
|
|
11
|
-
const elName = el.name.name;
|
|
12
|
-
if (!elName)
|
|
13
|
-
return;
|
|
14
|
-
// Ignore html tags e.g. div, h1, span
|
|
15
|
-
if (elName[0] === elName[0]?.toLocaleLowerCase())
|
|
16
|
-
return;
|
|
17
|
-
state.components.set(elName, (state.components.get(elName) ?? 0) + 1);
|
|
18
|
-
},
|
|
19
|
-
ImportDeclaration(node, state, _nodePath) {
|
|
20
|
-
const packageName = node.source.value;
|
|
21
|
-
node.specifiers.forEach((specifier) => {
|
|
22
|
-
// not handling namespace imports as we can't determine the actual name
|
|
23
|
-
// e.g. import * as MyIconLibrary from 'my-icon-library'
|
|
24
|
-
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
let name = specifier.local.name;
|
|
28
|
-
if (specifier.type === "ImportDefaultSpecifier") {
|
|
29
|
-
// handles the following cases:
|
|
30
|
-
// import Icon from 'my-icon-library'
|
|
31
|
-
name = specifier.local.name;
|
|
32
|
-
}
|
|
33
|
-
else if (specifier.type === "ImportSpecifier") {
|
|
34
|
-
// handles the following cases:
|
|
35
|
-
// import { Icon } from 'my-icon-library'
|
|
36
|
-
// import { Icon as MyIcon } from 'my-icon-library'
|
|
37
|
-
name =
|
|
38
|
-
specifier.imported.type === "Literal"
|
|
39
|
-
? specifier.imported.value
|
|
40
|
-
: specifier.imported.name;
|
|
41
|
-
}
|
|
42
|
-
state.imports.set(specifier.local.name, {
|
|
43
|
-
package: packageName,
|
|
44
|
-
name,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
const base = {
|
|
50
|
-
...walk.base,
|
|
51
|
-
TSInterfaceDeclaration() { },
|
|
52
|
-
TSModuleDeclaration() { },
|
|
53
|
-
TSAsExpression() { },
|
|
54
|
-
TSDeclareFunction() { },
|
|
55
|
-
TSTypeAliasDeclaration() { },
|
|
56
|
-
TSNonNullExpression() { },
|
|
57
|
-
TSEnumDeclaration() { },
|
|
58
|
-
TSParameterProperty() { },
|
|
59
|
-
TSImportEqualsDeclaration() { },
|
|
60
|
-
TSInstantiationExpression() { },
|
|
61
|
-
TSDeclareMethod() { },
|
|
62
|
-
};
|
|
63
|
-
try {
|
|
64
|
-
walk.ancestor(ast, visitors, base, visitorState);
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
// We don't want to log the error to the users - maybe could add some actually logging in the future
|
|
68
|
-
// console.log("error", e);
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
return transformVisitorStateToRawUsage(visitorState);
|
|
72
|
-
}
|
|
73
|
-
}
|
package/dist/ast/ts-js/parser.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as acorn from "acorn";
|
|
2
|
-
import { tsPlugin } from "acorn-typescript";
|
|
3
|
-
import * as walk from "acorn-walk";
|
|
4
|
-
import { extend } from "acorn-jsx-walk";
|
|
5
|
-
export function parse(code, options) {
|
|
6
|
-
const typescriptPlugin = tsPlugin();
|
|
7
|
-
extend(walk.base);
|
|
8
|
-
const JSXParser = acorn.Parser.extend(typescriptPlugin);
|
|
9
|
-
return JSXParser.parse(code, {
|
|
10
|
-
ecmaVersion: options?.version ?? "latest",
|
|
11
|
-
sourceType: "module",
|
|
12
|
-
locations: true,
|
|
13
|
-
});
|
|
14
|
-
}
|