-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathcli.js
executable file
·151 lines (135 loc) · 4.06 KB
/
cli.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env node
import {exit} from 'node:process';
import meow from 'meow';
import githubMarkdownCss from './index.js';
const cli = meow(
`
Usage
github-markdown-css > <filename>
Options
--list List available themes
Set theme:
--light Light theme name from --list values
--dark Dark theme name from --list values
--theme Theme name: 'auto', light', 'dark', or another from --list values.
'auto' means using the media query (prefers-color-scheme)
to switch between the 'light' and 'dark' theme.
Output options:
--preserve-variables Preserve variables in the output. Only applies if light
and dark themes match or if type is not 'auto'
--only-style Only output the styles, forces --preserve-variables on
--only-variables Only output the variables for the specified themes
--no-use-fixture Exclude generated classes that come from GitHub Markdown API rendered fixture.md
--root-selector Specify the root selector when outputting styles, default '.markdown-body'
Examples
$ github-markdown-css --list
light
dark
dark_dimmed
dark_high_contrast
dark_colorblind
light_colorblind
$ github-markdown-css --light=light --dark=dark
[CSS with variable blocks for 'light' and 'dark' themes]
$ github-markdown-css --theme=dark_dimmed --only-variables
[CSS with single variable block for 'dark_dimmed' theme with no element styles]
$ github-markdown-css --only-style
[CSS with only element styles using variables but no variables set.
Use in combination with output from setting --only-variables]
`,
{
importMeta: import.meta,
flags: {
theme: {
type: 'string',
aliases: [
'type',
],
},
light: {
type: 'string',
},
dark: {
type: 'string',
},
list: {
type: 'boolean',
},
onlyStyle: {
type: 'boolean',
},
onlyVariables: {
type: 'boolean',
},
preserveVariables: {
type: 'boolean',
},
rootSelector: {
type: 'string',
},
useFixture: {
type: 'boolean',
default: true,
},
},
},
);
const {
theme,
list,
preserveVariables,
onlyStyle,
onlyVariables,
rootSelector,
useFixture,
} = cli.flags;
let {light, dark} = cli.flags;
/*
| Theme | Light | Dark | Outcome |
| ----- | ----- | ---- | ---------------------------------- |
| ✓ | | | Single mode, use Theme |
| ✓ | ✓ | | Not allowed, can't determine theme |
| ✓ | | ✓ | Not allowed, can't determine theme |
| ✓ | ✓ | ✓ | Not allowed, can't determine theme |
| | | | Auto, default themes |
| | ✓ | | Single mode, use Light |
| | | ✓ | Single mode, use Dark |
| | ✓ | ✓ | Auto, use Light and Dark |
| | ✓ | ✓ | Single mode if Light === Dark |
| auto | | | Auto, default themes |
| auto | ✓ | | Auto, use Light, default dark |
| auto | | ✓ | Auto, use Dark, default light |
| auto | ✓ | ✓ | Auto, use Light and Dark |
| auto | ✓ | ✓ | Single mode if Light === Dark |
*/
// Use "single" mode when type is a theme name other than 'auto'
if (theme && theme !== 'auto') {
if (light || dark) {
console.error('You may not specify light and/or dark unless type/theme is set to "auto"');
exit(1);
}
light = theme;
dark = theme;
}
// If only light or dark was specified set the other to force "single mode"
if (!theme && light && !dark) {
dark = light;
} else if (!theme && !light && dark) {
light = dark;
}
if (rootSelector === '') {
console.error('--rootSelector cannot be an empty string');
exit(1);
}
console.log(
await githubMarkdownCss({
light,
dark,
list,
preserveVariables,
onlyStyles: onlyStyle,
onlyVariables,
rootSelector,
useFixture,
}),
);