@deplens/cli 0.1.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.
Files changed (2) hide show
  1. package/package.json +19 -0
  2. package/src/cli.mjs +135 -0
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@deplens/cli",
3
+ "version": "0.1.0",
4
+ "description": "Inspect exports and types of installed npm packages",
5
+ "type": "module",
6
+ "bin": {
7
+ "deplens": "./src/cli.mjs"
8
+ },
9
+ "dependencies": {
10
+ "@deplens/core": "0.1.0"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "license": "MIT"
19
+ }
package/src/cli.mjs ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env node
2
+ import { runInspect } from "@deplens/core"
3
+
4
+ function parseCliArgs(argv) {
5
+ const target = argv[0]
6
+ let filter = argv[1] && !argv[1].startsWith("--") ? argv[1].toLowerCase() : null
7
+ const showTypes = argv.includes("--types")
8
+
9
+ let jsdoc = null
10
+ const jsdocIndex = argv.indexOf("--jsdoc")
11
+ if (jsdocIndex !== -1 && argv[jsdocIndex + 1]) {
12
+ jsdoc = argv[jsdocIndex + 1].toLowerCase()
13
+ }
14
+
15
+ let jsdocOutput = null
16
+ const jsdocOutputIndex = argv.indexOf("--jsdoc-output")
17
+ if (jsdocOutputIndex !== -1 && argv[jsdocOutputIndex + 1]) {
18
+ jsdocOutput = argv[jsdocOutputIndex + 1].toLowerCase()
19
+ }
20
+
21
+ let jsdocSymbols = null
22
+ const jsdocSymbolIndex = argv.indexOf("--jsdoc-symbol")
23
+ if (jsdocSymbolIndex !== -1 && argv[jsdocSymbolIndex + 1]) {
24
+ jsdocSymbols = argv[jsdocSymbolIndex + 1]
25
+ }
26
+
27
+ let jsdocSections = null
28
+ const jsdocSectionsIndex = argv.indexOf("--jsdoc-sections")
29
+ if (jsdocSectionsIndex !== -1 && argv[jsdocSectionsIndex + 1]) {
30
+ jsdocSections = argv[jsdocSectionsIndex + 1]
31
+ }
32
+
33
+ let jsdocTagsInclude = null
34
+ const jsdocTagsIndex = argv.indexOf("--jsdoc-tags")
35
+ if (jsdocTagsIndex !== -1 && argv[jsdocTagsIndex + 1]) {
36
+ jsdocTagsInclude = argv[jsdocTagsIndex + 1]
37
+ }
38
+
39
+ let jsdocTagsExclude = null
40
+ const jsdocTagsExcludeIndex = argv.indexOf("--jsdoc-tags-exclude")
41
+ if (jsdocTagsExcludeIndex !== -1 && argv[jsdocTagsExcludeIndex + 1]) {
42
+ jsdocTagsExclude = argv[jsdocTagsExcludeIndex + 1]
43
+ }
44
+
45
+ let jsdocTruncate = null
46
+ const jsdocTruncateIndex = argv.indexOf("--jsdoc-truncate")
47
+ if (jsdocTruncateIndex !== -1 && argv[jsdocTruncateIndex + 1]) {
48
+ jsdocTruncate = argv[jsdocTruncateIndex + 1].toLowerCase()
49
+ }
50
+
51
+ let jsdocMaxLen = null
52
+ const jsdocMaxLenIndex = argv.indexOf("--jsdoc-max-len")
53
+ if (jsdocMaxLenIndex !== -1 && argv[jsdocMaxLenIndex + 1]) {
54
+ const parsed = parseInt(argv[jsdocMaxLenIndex + 1], 10)
55
+ if (!isNaN(parsed) && parsed >= 0) jsdocMaxLen = parsed
56
+ }
57
+
58
+ const filterIndex = argv.indexOf("--filter")
59
+ if (filterIndex !== -1 && argv[filterIndex + 1]) {
60
+ filter = argv[filterIndex + 1].toLowerCase()
61
+ }
62
+
63
+ let resolveFrom = null
64
+ const resolveFromIndex = argv.indexOf("--resolve-from")
65
+ if (resolveFromIndex !== -1 && argv[resolveFromIndex + 1]) {
66
+ resolveFrom = argv[resolveFromIndex + 1]
67
+ }
68
+
69
+ let kindFilter = null
70
+ const kindIndex = argv.indexOf("--kind")
71
+ if (kindIndex !== -1 && argv[kindIndex + 1]) {
72
+ kindFilter = argv[kindIndex + 1].split(",").map((k) => k.trim().toLowerCase())
73
+ }
74
+
75
+ let depth = 1
76
+ const depthIndex = argv.indexOf("--depth")
77
+ if (depthIndex !== -1 && argv[depthIndex + 1]) {
78
+ depth = parseInt(argv[depthIndex + 1], 10)
79
+ if (isNaN(depth) || depth < 0 || depth > 5) {
80
+ depth = 1
81
+ }
82
+ }
83
+
84
+ let jsdocQuery = null
85
+ if (
86
+ jsdocSymbols ||
87
+ jsdocSections ||
88
+ jsdocTagsInclude ||
89
+ jsdocTagsExclude ||
90
+ jsdocTruncate ||
91
+ jsdocMaxLen !== null
92
+ ) {
93
+ const symbols = jsdocSymbols ? jsdocSymbols.split(",").map((s) => s.trim()).filter(Boolean) : undefined
94
+ const sections = jsdocSections ? jsdocSections.split(",").map((s) => s.trim()).filter(Boolean) : undefined
95
+ const tagsInclude = jsdocTagsInclude ? jsdocTagsInclude.split(",").map((s) => s.trim()).filter(Boolean) : undefined
96
+ const tagsExclude = jsdocTagsExclude ? jsdocTagsExclude.split(",").map((s) => s.trim()).filter(Boolean) : undefined
97
+ jsdocQuery = {
98
+ symbols: symbols && symbols.length === 1 ? symbols[0] : symbols,
99
+ sections,
100
+ tags: tagsInclude || tagsExclude ? { include: tagsInclude, exclude: tagsExclude } : undefined,
101
+ mode: jsdoc === "compact" || jsdoc === "full" ? jsdoc : undefined,
102
+ maxLen: jsdocMaxLen ?? undefined,
103
+ truncate: jsdocTruncate ?? undefined,
104
+ }
105
+ }
106
+
107
+ return { target, filter, showTypes, kindFilter, depth, resolveFrom, jsdoc, jsdocOutput, jsdocQuery }
108
+ }
109
+
110
+ function usage() {
111
+ console.error(
112
+ "Uso: deplens <pacote> [filtro] [--filter VALUE] [--types] [--jsdoc off|compact|full] [--jsdoc-output off|section|inline|only] [--jsdoc-symbol NAME|glob|/re/] [--jsdoc-sections summary,params,returns,tags] [--jsdoc-tags t1,t2] [--jsdoc-tags-exclude t1,t2] [--jsdoc-truncate none|sentence|word] [--jsdoc-max-len N] [--kind function,class,...] [--depth N] [--resolve-from DIR]"
113
+ )
114
+ }
115
+
116
+ const parsed = parseCliArgs(process.argv.slice(2))
117
+ if (!parsed.target) {
118
+ usage()
119
+ process.exit(1)
120
+ }
121
+
122
+ runInspect({
123
+ target: parsed.target,
124
+ filter: parsed.filter,
125
+ showTypes: parsed.showTypes,
126
+ jsdoc: parsed.jsdoc,
127
+ jsdocOutput: parsed.jsdocOutput,
128
+ jsdocQuery: parsed.jsdocQuery,
129
+ kind: parsed.kindFilter,
130
+ depth: parsed.depth,
131
+ resolveFrom: parsed.resolveFrom,
132
+ cwd: process.cwd(),
133
+ write: console.log,
134
+ writeError: console.error,
135
+ })