/
flat.js
42 lines (37 loc) · 908 Bytes
/
flat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {EOL} from "os"
import {handler as depcountHandler} from "./depcount"
import * as symbols from "../symbols"
export let command = "flat"
export let describe = "exit badly if the tree cannot be flat"
export let builder = yargs => {
yargs
.options("origami", {
type: "boolean"
})
.options("pattern", {
alias: ["r"],
type: "array",
describe: "only count packages whose name match one of these patterns",
coerce: pattern => new RegExp(pattern)
})
.options("production", {
alias: ["prod", "p"],
type: "boolean",
default: "false",
describe: "only count the production (non-dev) tree"
})
}
export async function handler (argv) {
let options = argv.origami
? {
production: true,
pattern: /@financial-times\/o-.*/
}
: argv
let counts = await depcountHandler({
...options,
min: 2,
[symbols.internal]: true
})
process.exit(counts.length && 4)
}