@chromamark/cli 0.2.1 → 0.3.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.
- package/README.md +12 -3
- package/package.json +5 -4
- package/src/cli.js +56 -6
- package/src/index.d.ts +3 -0
- package/src/index.js +6 -1
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Compile [ChromaMark](https://github.com/cjfravel-dev/ChromaMark) (`.cm`) files
|
|
4
4
|
into **self-contained HTML** — the theme is inlined, so there's no CDN or build
|
|
5
|
-
step to deploy —
|
|
6
|
-
in CI.
|
|
5
|
+
step to deploy — transpile them to **GitHub-native GFM**, render them straight
|
|
6
|
+
to a **color terminal**, or **lint** them in CI.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -27,6 +27,10 @@ chromamark render report.cm # render to the terminal (ANSI)
|
|
|
27
27
|
cat report.cm | chromamark render # render piped stdin
|
|
28
28
|
chromamark render report.cm --no-color # plain, icon-annotated text
|
|
29
29
|
|
|
30
|
+
chromamark github report.cm # GitHub-native GFM on stdout
|
|
31
|
+
chromamark github report.cm -o report.md # write GitHub-native GFM
|
|
32
|
+
cat report.cm | chromamark github # render piped stdin
|
|
33
|
+
|
|
30
34
|
chromamark lint report.cm # check for common mistakes (CI)
|
|
31
35
|
chromamark lint report.cm --disable CM001 # suppress a rule
|
|
32
36
|
```
|
|
@@ -43,6 +47,10 @@ icon chips (`[✓ PASS]`), blocks into a colored left bar, and meters into a
|
|
|
43
47
|
unicode bar. Color is automatic on a TTY and can be forced with `--color`; it
|
|
44
48
|
also honors the [`NO_COLOR`](https://no-color.org) convention.
|
|
45
49
|
|
|
50
|
+
The `github` command maps callouts to GitHub Alerts, details and tables to native
|
|
51
|
+
GitHub structures, and pills to tone-aware `<kbd>` badges. See the complete
|
|
52
|
+
[mapping contract](../../docs/github-export.md).
|
|
53
|
+
|
|
46
54
|
The `lint` command flags mistakes that otherwise degrade silently — a construct
|
|
47
55
|
wrapped in backticks (`CM001`), an unknown tone (`CM002`), an unknown block kind
|
|
48
56
|
(`CM003`), a bad meter value (`CM004`), or an unclosed container (`CM005`) — and
|
|
@@ -51,12 +59,13 @@ exits non-zero when any are found. Suppress rules with `--disable CM001,CM003`.
|
|
|
51
59
|
## Programmatic
|
|
52
60
|
|
|
53
61
|
```js
|
|
54
|
-
import { compile, render, renderAnsi, lint } from '@chromamark/cli';
|
|
62
|
+
import { compile, render, renderAnsi, renderGitHub, lint } from '@chromamark/cli';
|
|
55
63
|
|
|
56
64
|
const page = compile('::: success\nAll good [!pass]\n:::', { title: 'Report' });
|
|
57
65
|
// → complete <!DOCTYPE html> document with the theme inlined
|
|
58
66
|
const fragment = render('[!pass]'); // just the HTML fragment
|
|
59
67
|
const ansi = renderAnsi('[!pass]', { color: 'always' }); // terminal-styled text
|
|
68
|
+
const github = renderGitHub('[!pass]'); // ✅ <kbd>PASS</kbd>
|
|
60
69
|
const problems = lint('Use `[!pass]` here'); // [{ line, column, rule, ... }]
|
|
61
70
|
```
|
|
62
71
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chromamark/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "ChromaMark command-line tool — compile .cm to
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "ChromaMark command-line tool — compile .cm to HTML or GitHub GFM, render to a color terminal, or lint.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "cjfravel-dev",
|
|
7
7
|
"homepage": "https://github.com/cjfravel-dev/ChromaMark#readme",
|
|
@@ -43,9 +43,10 @@
|
|
|
43
43
|
"markdown",
|
|
44
44
|
"cli",
|
|
45
45
|
"static-site",
|
|
46
|
-
"html"
|
|
46
|
+
"html",
|
|
47
|
+
"github"
|
|
47
48
|
],
|
|
48
49
|
"dependencies": {
|
|
49
|
-
"@chromamark/renderer": "^0.
|
|
50
|
+
"@chromamark/renderer": "^0.4.0"
|
|
50
51
|
}
|
|
51
52
|
}
|
package/src/cli.js
CHANGED
|
@@ -8,21 +8,25 @@ import {
|
|
|
8
8
|
} from 'node:fs';
|
|
9
9
|
import { join, basename, extname, dirname, relative } from 'node:path';
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
compile, renderAnsi, renderGitHub, lint,
|
|
13
|
+
} from './index.js';
|
|
12
14
|
|
|
13
|
-
const HELP = `chromamark — compile ChromaMark (.cm) to HTML,
|
|
15
|
+
const HELP = `chromamark — compile ChromaMark (.cm) to HTML, GitHub GFM, ANSI, or lint it
|
|
14
16
|
|
|
15
17
|
Usage:
|
|
16
18
|
chromamark [build] <input.cm> [-o <output.html>] compile one file to HTML
|
|
17
19
|
chromamark [build] <dir> -o <outdir> compile every .cm in a tree
|
|
18
20
|
chromamark render <input.cm> render to ANSI on stdout
|
|
21
|
+
chromamark github <input.cm> [-o <output.md>] render to GitHub-native GFM
|
|
19
22
|
chromamark lint <input.cm> check for common mistakes
|
|
20
23
|
cat file.cm | chromamark render render stdin to ANSI
|
|
24
|
+
cat file.cm | chromamark github render stdin to GitHub GFM
|
|
21
25
|
chromamark <input.cm> --stdout write HTML to stdout
|
|
22
26
|
cat file.cm | chromamark - read HTML from stdin
|
|
23
27
|
|
|
24
28
|
Options:
|
|
25
|
-
-o, --output <path> output file or directory (build)
|
|
29
|
+
-o, --output <path> output file or directory (build/github)
|
|
26
30
|
--stdout write HTML to stdout instead of a file
|
|
27
31
|
--title <text> page title (default: derived from the file name)
|
|
28
32
|
--color <when> colorize render output: auto (default), always, never
|
|
@@ -33,7 +37,7 @@ Options:
|
|
|
33
37
|
-v, --version print the version
|
|
34
38
|
`;
|
|
35
39
|
|
|
36
|
-
const COMMANDS = new Set(['build', 'render', 'lint']);
|
|
40
|
+
const COMMANDS = new Set(['build', 'render', 'github', 'lint']);
|
|
37
41
|
|
|
38
42
|
/**
|
|
39
43
|
* Read all of stdin synchronously. Unlike readFileSync(0), this tolerates a
|
|
@@ -66,7 +70,8 @@ function version() {
|
|
|
66
70
|
|
|
67
71
|
function parseArgs(argv) {
|
|
68
72
|
const opts = {
|
|
69
|
-
command: 'build', input: null, output: null, stdout: false, title: null, watch: false,
|
|
73
|
+
command: 'build', input: null, output: null, stdout: false, title: null, watch: false,
|
|
74
|
+
color: 'auto', colorSpecified: false, disable: [],
|
|
70
75
|
};
|
|
71
76
|
let rest = argv;
|
|
72
77
|
if (argv.length && COMMANDS.has(argv[0])) {
|
|
@@ -87,11 +92,15 @@ function parseArgs(argv) {
|
|
|
87
92
|
else if (a === '-v' || a === '--version') opts.version = true;
|
|
88
93
|
else if (a === '--stdout') opts.stdout = true;
|
|
89
94
|
else if (a === '--watch') opts.watch = true;
|
|
90
|
-
else if (a === '--no-color')
|
|
95
|
+
else if (a === '--no-color') {
|
|
96
|
+
opts.color = 'never';
|
|
97
|
+
opts.colorSpecified = true;
|
|
98
|
+
}
|
|
91
99
|
else if (a === '--color') {
|
|
92
100
|
const v = takeValue(a);
|
|
93
101
|
if (!['auto', 'always', 'never'].includes(v)) throw new Error('--color must be auto, always, or never');
|
|
94
102
|
opts.color = v;
|
|
103
|
+
opts.colorSpecified = true;
|
|
95
104
|
} else if (a === '--disable') {
|
|
96
105
|
opts.disable = opts.disable.concat(takeValue(a).split(',').map((s) => s.trim()).filter(Boolean));
|
|
97
106
|
} else if (a === '-o' || a === '--output') opts.output = takeValue(a);
|
|
@@ -138,6 +147,44 @@ function runRender(opts) {
|
|
|
138
147
|
return 0;
|
|
139
148
|
}
|
|
140
149
|
|
|
150
|
+
/** Render ChromaMark to GitHub-native GFM, from a file, `-`, or piped stdin. */
|
|
151
|
+
function runGitHub(opts) {
|
|
152
|
+
const unsupported = [];
|
|
153
|
+
if (opts.watch) unsupported.push('--watch');
|
|
154
|
+
if (opts.title !== null) unsupported.push('--title');
|
|
155
|
+
if (opts.colorSpecified) unsupported.push('--color');
|
|
156
|
+
if (opts.disable.length) unsupported.push('--disable');
|
|
157
|
+
if (unsupported.length) {
|
|
158
|
+
process.stderr.write(`error: ${unsupported.join(', ')} not supported by the github command\n`);
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let input;
|
|
163
|
+
try {
|
|
164
|
+
input = readInput(opts);
|
|
165
|
+
} catch (err) {
|
|
166
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
if (!input || input.empty) {
|
|
170
|
+
process.stderr.write(`error: github needs an input file or piped stdin\n\n${HELP}`);
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
173
|
+
const output = renderGitHub(input.src);
|
|
174
|
+
try {
|
|
175
|
+
if (opts.output && !opts.stdout) {
|
|
176
|
+
mkdirSync(dirname(opts.output), { recursive: true });
|
|
177
|
+
writeFileSync(opts.output, output);
|
|
178
|
+
} else {
|
|
179
|
+
process.stdout.write(output);
|
|
180
|
+
}
|
|
181
|
+
} catch (err) {
|
|
182
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
|
|
141
188
|
/** Lint ChromaMark and print diagnostics; exit non-zero when any are found. */
|
|
142
189
|
function runLint(opts) {
|
|
143
190
|
let input;
|
|
@@ -213,6 +260,9 @@ export function run(argv = process.argv.slice(2)) {
|
|
|
213
260
|
if (opts.command === 'render') {
|
|
214
261
|
return runRender(opts);
|
|
215
262
|
}
|
|
263
|
+
if (opts.command === 'github') {
|
|
264
|
+
return runGitHub(opts);
|
|
265
|
+
}
|
|
216
266
|
if (opts.command === 'lint') {
|
|
217
267
|
return runLint(opts);
|
|
218
268
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
LintOptions,
|
|
4
4
|
RendererOptions,
|
|
5
5
|
RenderAnsiOptions,
|
|
6
|
+
RenderGitHubOptions,
|
|
6
7
|
} from '@chromamark/renderer';
|
|
7
8
|
|
|
8
9
|
export interface CompileOptions {
|
|
@@ -13,6 +14,7 @@ export interface CompileOptions {
|
|
|
13
14
|
|
|
14
15
|
export function render(source: unknown, options?: RendererOptions): string;
|
|
15
16
|
export function renderAnsi(source: unknown, options?: RenderAnsiOptions): string;
|
|
17
|
+
export function renderGitHub(source: unknown, options?: RenderGitHubOptions): string;
|
|
16
18
|
export function lint(source: unknown, options?: LintOptions): LintDiagnostic[];
|
|
17
19
|
export function theme(): string;
|
|
18
20
|
export function compile(source: unknown, options?: CompileOptions): string;
|
|
@@ -22,4 +24,5 @@ export type {
|
|
|
22
24
|
LintOptions,
|
|
23
25
|
RendererOptions,
|
|
24
26
|
RenderAnsiOptions,
|
|
27
|
+
RenderGitHubOptions,
|
|
25
28
|
};
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import { readFileSync } from 'node:fs';
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
render as renderFragment, renderAnsi, renderGitHub, lint,
|
|
10
|
+
} from '@chromamark/renderer';
|
|
9
11
|
|
|
10
12
|
const require = createRequire(import.meta.url);
|
|
11
13
|
|
|
@@ -15,6 +17,9 @@ export const render = renderFragment;
|
|
|
15
17
|
/** Render ChromaMark to ANSI-styled text for a terminal. */
|
|
16
18
|
export { renderAnsi };
|
|
17
19
|
|
|
20
|
+
/** Render ChromaMark to GitHub-native GFM. */
|
|
21
|
+
export { renderGitHub };
|
|
22
|
+
|
|
18
23
|
/** Lint ChromaMark source, returning an array of diagnostics. */
|
|
19
24
|
export { lint };
|
|
20
25
|
|