@jayrdeaton/scripts 1.1.4 → 1.1.5
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/README.md +13 -0
- package/package.json +1 -1
- package/src/commands/find-overrides.mjs +83 -0
package/README.md
CHANGED
|
@@ -149,6 +149,19 @@ Example: `jrd find-dep react-native expo`
|
|
|
149
149
|
|
|
150
150
|
---
|
|
151
151
|
|
|
152
|
+
### `jrd find-overrides`
|
|
153
|
+
|
|
154
|
+
Find projects in a directory that have an `overrides` field in their `package.json`.
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
jrd find-overrides [options]
|
|
158
|
+
|
|
159
|
+
Options:
|
|
160
|
+
-d, --dir <dir> Root directory to scan (default: ~/Developer)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
152
165
|
### `jrd find-script`
|
|
153
166
|
|
|
154
167
|
Find projects in a directory whose `package.json` scripts contain an exact command value.
|
package/package.json
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import { join, resolve } from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { Color, Program, Spinner } from 'termkit'
|
|
6
|
+
|
|
7
|
+
function findOverrides(pkgPath) {
|
|
8
|
+
let pkg
|
|
9
|
+
try {
|
|
10
|
+
pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
11
|
+
} catch {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const overrides = pkg.overrides ?? {}
|
|
16
|
+
const entries = Object.entries(overrides)
|
|
17
|
+
|
|
18
|
+
return { projectName: pkg.name, entries }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const command = Program.command('find-overrides')
|
|
22
|
+
.description('Find projects in a directory that have overrides in their package.json')
|
|
23
|
+
.option('d', 'dir', '[dir]', 'Root directory to scan (default: ~/Developer)')
|
|
24
|
+
.action(async (options) => {
|
|
25
|
+
const root = resolve(options.dir ?? join(homedir(), 'Developer'))
|
|
26
|
+
|
|
27
|
+
let entries
|
|
28
|
+
try {
|
|
29
|
+
entries = readdirSync(root)
|
|
30
|
+
} catch {
|
|
31
|
+
console.error(Color.red(`Could not read directory: ${root}`))
|
|
32
|
+
process.exit(1)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const spinner = new Spinner({ text: 'Scanning projects...' })
|
|
36
|
+
spinner.start()
|
|
37
|
+
|
|
38
|
+
const results = []
|
|
39
|
+
|
|
40
|
+
for (const name of entries) {
|
|
41
|
+
const dir = join(root, name)
|
|
42
|
+
try {
|
|
43
|
+
if (!statSync(dir).isDirectory()) continue
|
|
44
|
+
} catch {
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
spinner.message(name)
|
|
49
|
+
|
|
50
|
+
const pkgPath = join(dir, 'package.json')
|
|
51
|
+
if (!existsSync(pkgPath)) continue
|
|
52
|
+
|
|
53
|
+
const { projectName, entries: overrideEntries } = findOverrides(pkgPath)
|
|
54
|
+
|
|
55
|
+
if (overrideEntries.length) {
|
|
56
|
+
results.push({ dir: name, projectName, overrideEntries })
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!results.length) {
|
|
61
|
+
spinner.succeed('No projects with overrides found')
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
spinner.stop()
|
|
66
|
+
|
|
67
|
+
console.log(Color.bold(`\n${results.length} project${results.length !== 1 ? 's' : ''} with overrides:\n`))
|
|
68
|
+
|
|
69
|
+
for (const result of results) {
|
|
70
|
+
const label =
|
|
71
|
+
result.projectName && result.projectName !== result.dir
|
|
72
|
+
? `${Color.bold(result.dir)} ${Color.faint(`(${result.projectName})`)}`
|
|
73
|
+
: Color.bold(result.dir)
|
|
74
|
+
|
|
75
|
+
console.log(` ${label}`)
|
|
76
|
+
|
|
77
|
+
for (const [pkg, version] of result.overrideEntries) {
|
|
78
|
+
console.log(` ${Color.cyan(pkg)} ${Color.faint(typeof version === 'string' ? version : JSON.stringify(version))}`)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
console.log()
|
|
83
|
+
})
|