forked from privatenumber/cleye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render-flags.ts
104 lines (90 loc) Β· 1.66 KB
/
render-flags.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import type { Flags } from '../types';
import { kebabCase } from '../utils/convert-case';
const tableBreakpoints = {
'> 80': [
{
width: 'content-width',
paddingLeft: 2,
paddingRight: 8,
},
// Flag alias to fill remaining line
{
width: 'auto',
},
],
'> 40': [
{
width: 'auto',
paddingLeft: 2,
paddingRight: 8,
// Remove alias padding on smaller screens
preprocess: (text: string) => text.trim(),
},
// Flag description to be on own line
{
width: '100%',
paddingLeft: 2,
paddingBottom: 1,
},
],
'> 0': {
// Remove responsiveness
stdoutColumns: 1000,
columns: [
{
width: 'content-width',
paddingLeft: 2,
paddingRight: 8,
},
{
width: 'content-width',
},
],
},
};
export type FlagData = {
name: string;
flag: Flags[string];
flagFormatted: string;
aliasesEnabled: boolean;
aliasFormatted: string | undefined;
};
export function renderFlags(flags: Flags) {
let aliasesEnabled = false;
const flagsData = Object.keys(flags)
.sort((a, b) => a.localeCompare(b))
.map((name): FlagData => {
const flag = flags[name];
const hasAlias = ('alias' in flag);
if (hasAlias) {
aliasesEnabled = true;
}
return {
name,
flag,
flagFormatted: `--${kebabCase(name)}`,
aliasesEnabled,
aliasFormatted: hasAlias ? `-${flag.alias}` : undefined,
};
});
const tableData = flagsData.map((flagData) => {
flagData.aliasesEnabled = aliasesEnabled;
return [
{
type: 'flagName',
data: flagData,
},
{
type: 'flagDescription',
data: flagData,
},
];
});
return {
type: 'table',
data: {
tableData,
tableBreakpoints,
},
};
}