Skip to content

Commit 22796de

Browse files
committed
docs: enhanced cli usage and overral readme documentation
1 parent aec359c commit 22796de

File tree

2 files changed

+57
-23
lines changed

2 files changed

+57
-23
lines changed

README.md

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,62 @@ Given a few options you can gets details about how your library is being importe
2323
```js
2424
import { getPackagesUsages } from 'pkg-usage';
2525

26-
const usages = getPackagesUsages({
26+
const usages: PackageUsage[] = getPackagesUsages({
2727
packages: ['react'],
2828
fileGlobs: `**/**.ts`,
2929
});
3030

3131
console.log(usages);
3232
```
3333

34-
Output
35-
36-
```json
37-
[
38-
{
39-
count: 1,
40-
files: [
41-
{
42-
defaultImport: undefined,
43-
name: `${fileName}.ts`,
44-
namedImports: imports,
45-
},
46-
],
47-
name: pkg,
48-
version,
49-
}
50-
]
34+
Package Usage types
35+
36+
```ts
37+
export type FileUsage = {
38+
name: string;
39+
filePath: string;
40+
defaultImport: string | undefined;
41+
namedImports: string[];
42+
};
43+
44+
export type PackageUsage = {
45+
name: string;
46+
count: number;
47+
files?: FileUsage[];
48+
version?: string;
49+
};
5150
```
5251

53-
## Current features:
52+
## CLI usage
5453

55-
- The package version
56-
- How many files are importing your `package`
57-
- What are the default and named imports by file
54+
| Options | Description | Example |
55+
| ------------------------ | ------------------------------------ | ---------------------------------------------- |
56+
| -p, --packages | Packages to analyze | -p vue,vuex or --packages="react,redux" |
57+
| -f, --file-globs | Files to analyze based on file globs | -f "_.(ts\|tsx)" or --file-globs="_.(js\|jsx)" |
58+
| -cwd, --package-json-CWD | Directory to start from | -cwd "/path/to/start/from" |
59+
60+
### npx
61+
62+
[`npx`](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) is a package runner tool
63+
64+
```bash
65+
npx pkg-usage -p "react,redux" --f "**/*.(ts|tsx)"
66+
```
67+
68+
Or
69+
70+
```bash
71+
npx pkg-usage --packages="vue,vuex" --file-globs="**/*.(js|jsx)"
72+
```
73+
74+
If you use npm 5.1 or earlier, you can't use npx. Instead, install it globally:
75+
76+
```bash
77+
npm install -g pkg-usage
78+
```
79+
80+
Now you can run:
81+
82+
```bash
83+
pkg-usage -p "react,redux" --f "**/*.(ts|tsx)"
84+
```

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pkg-usage",
3-
"version": "0.2.1-pre",
3+
"version": "0.2.1",
44
"description": "Npm package usage metrics",
55
"main": "dist/src/index.js",
66
"files": [
@@ -9,6 +9,13 @@
99
"example",
1010
"scripts"
1111
],
12+
"keywords": [
13+
"node",
14+
"npm",
15+
"package",
16+
"usage",
17+
"resources"
18+
],
1219
"bin": {
1320
"pkg-usage": "./scripts/pkg-usage.js"
1421
},

0 commit comments

Comments
 (0)