reactive-md 0.3.0 → 0.4.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/CHANGELOG-ch.md +96 -0
- package/CHANGELOG.md +96 -40
- package/CONTRIBUTING-ch.md +62 -0
- package/CONTRIBUTING.md +64 -61
- package/README-ch.md +122 -0
- package/README-en.md +146 -0
- package/README.md +146 -88
- package/SECURITY-ch.md +80 -0
- package/SECURITY.md +80 -68
- package/THIRD_PARTY_NOTICES.md +85 -1
- package/bin/reactive-md.mjs +40 -0
- package/cli/args.mjs +181 -0
- package/cli/assets.mjs +390 -0
- package/cli/build.mjs +268 -0
- package/cli/document.mjs +130 -0
- package/cli/errors.mjs +61 -0
- package/cli/fs-utils.mjs +133 -0
- package/cli/glob.mjs +203 -0
- package/cli/help.mjs +138 -0
- package/cli/lint.mjs +177 -0
- package/cli/main.mjs +55 -0
- package/cli/migrate.mjs +368 -0
- package/cli/package.mjs +209 -0
- package/dist-library/reactive-md-react.js +3603 -1690
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +1798 -4
- package/dist-library/runtime-DtjdPXxJ.js +15410 -0
- package/dist-library/types/index.d.ts +1 -0
- package/dist-library/types/local/LocalDocumentView.d.ts +66 -3
- package/dist-library/types/local/authoring.d.ts +63 -0
- package/dist-library/types/local/collection-functions.d.ts +4 -0
- package/dist-library/types/local/colors.d.ts +2 -0
- package/dist-library/types/local/compiler.d.ts +3 -3
- package/dist-library/types/local/computations.d.ts +53 -0
- package/dist-library/types/local/data-functions.d.ts +22 -0
- package/dist-library/types/local/data-table.d.ts +65 -0
- package/dist-library/types/local/dates.d.ts +2 -0
- package/dist-library/types/local/dependencies.d.ts +31 -0
- package/dist-library/types/local/diagnostics.d.ts +1450 -0
- package/dist-library/types/local/expression.d.ts +13 -3
- package/dist-library/types/local/formatting.d.ts +41 -0
- package/dist-library/types/local/heading-anchors.d.ts +17 -0
- package/dist-library/types/local/i18n.d.ts +18 -0
- package/dist-library/types/local/index.d.ts +18 -1
- package/dist-library/types/local/limits.d.ts +33 -1
- package/dist-library/types/local/locale.d.ts +1 -0
- package/dist-library/types/local/math.d.ts +6 -1
- package/dist-library/types/local/parser.d.ts +10 -4
- package/dist-library/types/local/render-types.d.ts +5 -1
- package/dist-library/types/local/retention.d.ts +23 -0
- package/dist-library/types/local/schema.d.ts +25 -3
- package/dist-library/types/local/source-migration.d.ts +35 -0
- package/dist-library/types/local/state.d.ts +80 -0
- package/dist-library/types/local/text-length.d.ts +13 -0
- package/dist-library/types/local/theme.d.ts +30 -0
- package/dist-library/types/local/types.d.ts +120 -4
- package/dist-library/types/local/validation.d.ts +32 -0
- package/dist-library/types/local/version.d.ts +1 -1
- package/dist-library/types/local/worker.d.ts +82 -0
- package/dist-library/types/react/index.d.ts +4 -1
- package/dist-library/types/shareable.d.ts +64 -0
- package/dist-standalone/reactive-md-standalone.css +2 -0
- package/dist-standalone/reactive-md-standalone.js +57 -0
- package/docs/author-tools-ch.md +56 -0
- package/docs/author-tools-en.md +56 -0
- package/docs/compatibility-ch.md +103 -0
- package/docs/compatibility-en.md +103 -0
- package/docs/component-development-ch.md +210 -0
- package/docs/component-development-en.md +210 -0
- package/docs/component-protocol-ch.md +710 -0
- package/docs/component-protocol-en.md +710 -0
- package/docs/computations-formatting-ch.md +87 -0
- package/docs/computations-formatting-en.md +87 -0
- package/docs/constraints-collections-ch.md +84 -0
- package/docs/constraints-collections-en.md +84 -0
- package/docs/diagnostics-counting-ch.md +84 -0
- package/docs/diagnostics-counting-en.md +84 -0
- package/docs/local-components-v2-ch.md +138 -0
- package/docs/local-components-v2-en.md +104 -0
- package/docs/{local-guide.md → local-guide-ch.md} +961 -936
- package/docs/local-guide-en.md +961 -0
- package/docs/local-integration-ch.md +363 -0
- package/docs/local-integration-en.md +363 -0
- package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +485 -437
- package/docs/local-interaction-syntax-en.md +483 -0
- package/docs/performance-ch.md +76 -0
- package/docs/performance-en.md +76 -0
- package/docs/release-0.4.0-ch.md +89 -0
- package/docs/release-0.4.0-en.md +89 -0
- package/docs/releasing-ch.md +101 -0
- package/docs/releasing-en.md +101 -0
- package/docs/shareable-export-ch.md +205 -0
- package/docs/shareable-export-en.md +207 -0
- package/docs/source-versioning-ch.md +159 -0
- package/docs/source-versioning-en.md +159 -0
- package/docs/theme-protocol-ch.md +107 -0
- package/docs/theme-protocol-en.md +107 -0
- package/examples/conformance/README.md +53 -11
- package/examples/conformance/component-protocol-1.json +482 -0
- package/examples/conformance/component-protocol-1.schema.json +76 -0
- package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
- package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
- package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
- package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
- package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
- package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
- package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
- package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
- package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
- package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
- package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
- package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
- package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
- package/examples/conformance/history/v0.3.1/provenance.json +72 -0
- package/examples/conformance/local-draft-1.json +50 -49
- package/examples/conformance/local-draft-2.json +212 -0
- package/examples/integration/README.md +45 -29
- package/examples/integration/core/index.mjs +32 -19
- package/examples/integration/react/index.html +1 -1
- package/examples/integration/react/main.jsx +5 -5
- package/examples/integration/worker/index.html +19 -0
- package/examples/integration/worker/main.js +61 -0
- package/examples/integration/worker/package.json +13 -0
- package/examples/integration/worker/worker.js +3 -0
- package/examples/local/README.md +72 -66
- package/examples/local/catalog.reactive.md +14 -14
- package/examples/local/charts.reactive.md +73 -73
- package/examples/local/checklist.reactive.md +19 -19
- package/examples/local/comparison.reactive.md +23 -23
- package/examples/local/components.reactive.md +20 -20
- package/examples/local/counter.reactive.md +4 -4
- package/examples/local/diagnostics.reactive.md +25 -25
- package/examples/local/diagram.reactive.md +20 -20
- package/examples/local/gallery.reactive.md +31 -31
- package/examples/local/parameters.reactive.md +19 -19
- package/examples/local/planning.reactive.md +15 -15
- package/examples/local/pricing.reactive.md +10 -10
- package/examples/local/recipes/invoice-zh.reactive.md +36 -0
- package/examples/local/recipes/invoice.reactive.md +36 -0
- package/examples/local/recipes/workshop-zh.reactive.md +33 -0
- package/examples/local/recipes/workshop.reactive.md +33 -0
- package/examples/local/showcase/README.md +25 -0
- package/examples/local/showcase/explore.reactive.md +102 -0
- package/examples/local/showcase/flow.reactive.md +86 -0
- package/examples/local/showcase/forms.reactive.md +126 -0
- package/examples/local/showcase/functions.reactive.md +119 -0
- package/examples/local/showcase/layout.reactive.md +100 -0
- package/examples/local/showcase/statistics.reactive.md +108 -0
- package/examples/local/showcase/tasks.reactive.md +89 -0
- package/examples/local/showcase/zh/explore.reactive.md +102 -0
- package/examples/local/showcase/zh/flow.reactive.md +86 -0
- package/examples/local/showcase/zh/forms.reactive.md +126 -0
- package/examples/local/showcase/zh/functions.reactive.md +119 -0
- package/examples/local/showcase/zh/layout.reactive.md +100 -0
- package/examples/local/showcase/zh/statistics.reactive.md +108 -0
- package/examples/local/showcase/zh/tasks.reactive.md +89 -0
- package/examples/local/zh/catalog.reactive.md +20 -0
- package/examples/local/zh/charts.reactive.md +73 -0
- package/examples/local/zh/checklist.reactive.md +32 -0
- package/examples/local/zh/comparison.reactive.md +47 -0
- package/examples/local/zh/components.reactive.md +44 -0
- package/examples/local/zh/counter.reactive.md +7 -0
- package/examples/local/zh/diagnostics.reactive.md +54 -0
- package/examples/local/zh/diagram.reactive.md +44 -0
- package/examples/local/zh/gallery.reactive.md +61 -0
- package/examples/local/zh/parameters.reactive.md +36 -0
- package/examples/local/zh/planning.reactive.md +24 -0
- package/examples/local/zh/pricing.reactive.md +20 -0
- package/package.json +90 -75
- package/README.en.md +0 -75
- package/dist-library/runtime-D4phFXOr.js +0 -10937
- package/docs/compatibility.md +0 -67
- package/docs/local-integration.md +0 -193
- package/docs/performance.md +0 -30
- package/docs/releasing.md +0 -92
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Third-party notices
|
|
2
2
|
|
|
3
|
-
Reactive MD bundles its Markdown dependencies. This file preserves license texts for
|
|
3
|
+
Reactive MD bundles its Markdown dependencies. The standalone HTML runtime also bundles React, React DOM and scheduler. This file preserves license texts for those installed dependency trees, including supporting type packages. The library React entry uses host-provided React and React DOM peers.
|
|
4
4
|
|
|
5
5
|
Regenerate after dependency updates with `node scripts/generate-notices.mjs`.
|
|
6
6
|
|
|
@@ -1623,6 +1623,62 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
1623
1623
|
SOFTWARE.
|
|
1624
1624
|
```
|
|
1625
1625
|
|
|
1626
|
+
## react-dom@19.3.1
|
|
1627
|
+
|
|
1628
|
+
Declared license: MIT
|
|
1629
|
+
|
|
1630
|
+
```text
|
|
1631
|
+
MIT License
|
|
1632
|
+
|
|
1633
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1634
|
+
|
|
1635
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1636
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
1637
|
+
in the Software without restriction, including without limitation the rights
|
|
1638
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1639
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
1640
|
+
furnished to do so, subject to the following conditions:
|
|
1641
|
+
|
|
1642
|
+
The above copyright notice and this permission notice shall be included in all
|
|
1643
|
+
copies or substantial portions of the Software.
|
|
1644
|
+
|
|
1645
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1646
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1647
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1648
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1649
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1650
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1651
|
+
SOFTWARE.
|
|
1652
|
+
```
|
|
1653
|
+
|
|
1654
|
+
## react@19.3.1
|
|
1655
|
+
|
|
1656
|
+
Declared license: MIT
|
|
1657
|
+
|
|
1658
|
+
```text
|
|
1659
|
+
MIT License
|
|
1660
|
+
|
|
1661
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1662
|
+
|
|
1663
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1664
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
1665
|
+
in the Software without restriction, including without limitation the rights
|
|
1666
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1667
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
1668
|
+
furnished to do so, subject to the following conditions:
|
|
1669
|
+
|
|
1670
|
+
The above copyright notice and this permission notice shall be included in all
|
|
1671
|
+
copies or substantial portions of the Software.
|
|
1672
|
+
|
|
1673
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1674
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1675
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1676
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1677
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1678
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1679
|
+
SOFTWARE.
|
|
1680
|
+
```
|
|
1681
|
+
|
|
1626
1682
|
## remark-gfm@4.0.1
|
|
1627
1683
|
|
|
1628
1684
|
Declared license: MIT
|
|
@@ -1708,6 +1764,34 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
1708
1764
|
THE SOFTWARE.
|
|
1709
1765
|
```
|
|
1710
1766
|
|
|
1767
|
+
## scheduler@0.28.0
|
|
1768
|
+
|
|
1769
|
+
Declared license: MIT
|
|
1770
|
+
|
|
1771
|
+
```text
|
|
1772
|
+
MIT License
|
|
1773
|
+
|
|
1774
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1775
|
+
|
|
1776
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1777
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
1778
|
+
in the Software without restriction, including without limitation the rights
|
|
1779
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1780
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
1781
|
+
furnished to do so, subject to the following conditions:
|
|
1782
|
+
|
|
1783
|
+
The above copyright notice and this permission notice shall be included in all
|
|
1784
|
+
copies or substantial portions of the Software.
|
|
1785
|
+
|
|
1786
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1787
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1788
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1789
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1790
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1791
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1792
|
+
SOFTWARE.
|
|
1793
|
+
```
|
|
1794
|
+
|
|
1711
1795
|
## trough@2.2.0
|
|
1712
1796
|
|
|
1713
1797
|
Declared license: MIT
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* reactive-md command-line interface.
|
|
4
|
+
*
|
|
5
|
+
* Exit codes:
|
|
6
|
+
* 0 success
|
|
7
|
+
* 2 usage or argument error
|
|
8
|
+
* 3 document compile, render, React or build-artifact error
|
|
9
|
+
* 4 input or output file I/O error
|
|
10
|
+
* 5 asset or security policy error
|
|
11
|
+
*
|
|
12
|
+
* Build artifacts and the package metadata are located relative to this file's
|
|
13
|
+
* installed package root (bin/..), never the current working directory.
|
|
14
|
+
*/
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { CliError, EXIT } from '../cli/errors.mjs';
|
|
18
|
+
import { runCli } from '../cli/main.mjs';
|
|
19
|
+
|
|
20
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
21
|
+
const context = {
|
|
22
|
+
packageRoot,
|
|
23
|
+
stdout: process.stdout,
|
|
24
|
+
stderr: process.stderr,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
process.exitCode = await runCli(process.argv.slice(2), context);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error instanceof CliError) {
|
|
31
|
+
if (!error.reported) {
|
|
32
|
+
context.stderr.write(`reactive-md: ${error.message}\n`);
|
|
33
|
+
}
|
|
34
|
+
process.exitCode = error.exitCode;
|
|
35
|
+
} else {
|
|
36
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
37
|
+
context.stderr.write(`reactive-md: unexpected error: ${message}\n`);
|
|
38
|
+
process.exitCode = EXIT.DOCUMENT;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/cli/args.mjs
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { usageError } from './errors.mjs';
|
|
2
|
+
|
|
3
|
+
/** A local asset root may be a Windows drive path; it must never be a URL. */
|
|
4
|
+
function isUrlLike(value) {
|
|
5
|
+
const match = /^([a-z][a-z0-9+.-]*):/i.exec(value);
|
|
6
|
+
if (!match) return false;
|
|
7
|
+
// C:\docs and C:/docs are local drive paths, not URL schemes.
|
|
8
|
+
if (match[1].length === 1 && /^[a-z]:[\\/]/i.test(value)) return false;
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string[]} argv
|
|
14
|
+
* @param {Map<string, {key: string, boolean?: boolean}>} spec
|
|
15
|
+
* @returns {{positionals: string[], options: Record<string, string | boolean>}}
|
|
16
|
+
*/
|
|
17
|
+
function parseOptions(argv, spec) {
|
|
18
|
+
const positionals = [];
|
|
19
|
+
const options = {};
|
|
20
|
+
let literal = false;
|
|
21
|
+
|
|
22
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
23
|
+
const token = argv[index];
|
|
24
|
+
if (literal) {
|
|
25
|
+
positionals.push(token);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (token === '--') {
|
|
29
|
+
literal = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (token === '-' || !token.startsWith('-')) {
|
|
33
|
+
positionals.push(token);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let name = token;
|
|
38
|
+
let inlineValue;
|
|
39
|
+
if (token.startsWith('--')) {
|
|
40
|
+
const equals = token.indexOf('=');
|
|
41
|
+
if (equals > 2) {
|
|
42
|
+
name = token.slice(0, equals);
|
|
43
|
+
inlineValue = token.slice(equals + 1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const entry = spec.get(name);
|
|
47
|
+
if (!entry) {
|
|
48
|
+
throw usageError(`Unknown option "${name}". Run "reactive-md build --help" or "reactive-md lint --help" for usage.`);
|
|
49
|
+
}
|
|
50
|
+
if (entry.boolean) {
|
|
51
|
+
if (inlineValue !== undefined) throw usageError(`Option "${name}" does not take a value.`);
|
|
52
|
+
options[entry.key] = true;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
let value = inlineValue;
|
|
56
|
+
if (value === undefined) {
|
|
57
|
+
if (index + 1 >= argv.length) throw usageError(`Option "${name}" requires a value.`);
|
|
58
|
+
value = argv[index + 1];
|
|
59
|
+
index += 1;
|
|
60
|
+
}
|
|
61
|
+
options[entry.key] = value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { positionals, options };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {unknown} value */
|
|
68
|
+
function requireText(value, option) {
|
|
69
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
70
|
+
throw usageError(`Option "${option}" requires a non-empty value.`);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @param {unknown} value @param {string} option @param {readonly string[]} choices */
|
|
76
|
+
function choice(value, option, choices) {
|
|
77
|
+
const normalized = String(value).toLowerCase();
|
|
78
|
+
if (!choices.includes(normalized)) {
|
|
79
|
+
throw usageError(`Invalid value for "${option}": "${value}". Expected ${choices.join(' or ')}.`);
|
|
80
|
+
}
|
|
81
|
+
return normalized;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const BUILD_SPEC = new Map([
|
|
85
|
+
['-o', { key: 'output' }],
|
|
86
|
+
['--output', { key: 'output' }],
|
|
87
|
+
['--mode', { key: 'mode' }],
|
|
88
|
+
['--state-file', { key: 'stateFile' }],
|
|
89
|
+
['--assets', { key: 'assets' }],
|
|
90
|
+
['--asset-root', { key: 'assetRoot' }],
|
|
91
|
+
['--locale', { key: 'locale' }],
|
|
92
|
+
['--color-scheme', { key: 'colorScheme' }],
|
|
93
|
+
['--title', { key: 'title' }],
|
|
94
|
+
['--strict', { key: 'strict', boolean: true }],
|
|
95
|
+
['-h', { key: 'help', boolean: true }],
|
|
96
|
+
['--help', { key: 'help', boolean: true }],
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
const LINT_SPEC = new Map([
|
|
100
|
+
['--json', { key: 'json', boolean: true }],
|
|
101
|
+
['--strict', { key: 'strict', boolean: true }],
|
|
102
|
+
['-h', { key: 'help', boolean: true }],
|
|
103
|
+
['--help', { key: 'help', boolean: true }],
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {string[]} argv
|
|
108
|
+
* @returns {{
|
|
109
|
+
* help: boolean, input?: string, output?: string, mode?: 'interactive'|'static',
|
|
110
|
+
* stateFile?: string, assets?: 'inline'|'omit', assetRoot?: string,
|
|
111
|
+
* locale?: 'en'|'zh', colorScheme?: 'auto'|'light'|'dark', title?: string,
|
|
112
|
+
* strict?: boolean
|
|
113
|
+
* }}
|
|
114
|
+
*/
|
|
115
|
+
export function parseBuildArgs(argv) {
|
|
116
|
+
const { positionals, options } = parseOptions(argv, BUILD_SPEC);
|
|
117
|
+
if (options.help) return { help: true };
|
|
118
|
+
|
|
119
|
+
if (positionals.length === 0) {
|
|
120
|
+
throw usageError('Missing input document. Usage: reactive-md build <doc.reactive.md> -o <doc.html>.');
|
|
121
|
+
}
|
|
122
|
+
if (positionals.length > 1) {
|
|
123
|
+
throw usageError(`Expected one input document, received ${positionals.length}: ${positionals.join(', ')}.`);
|
|
124
|
+
}
|
|
125
|
+
const input = requireText(positionals[0], 'input');
|
|
126
|
+
if (options.output === undefined) {
|
|
127
|
+
throw usageError('Missing required option "--output" (-o). Usage: reactive-md build <doc.reactive.md> -o <doc.html>.');
|
|
128
|
+
}
|
|
129
|
+
const output = requireText(options.output, '--output');
|
|
130
|
+
const mode = options.mode === undefined ? 'interactive' : choice(options.mode, '--mode', ['interactive', 'static']);
|
|
131
|
+
const assets = options.assets === undefined ? 'inline' : choice(options.assets, '--assets', ['inline', 'omit']);
|
|
132
|
+
const locale = options.locale === undefined ? 'en' : choice(options.locale, '--locale', ['en', 'zh']);
|
|
133
|
+
const colorScheme = options.colorScheme === undefined
|
|
134
|
+
? 'auto'
|
|
135
|
+
: choice(options.colorScheme, '--color-scheme', ['auto', 'light', 'dark']);
|
|
136
|
+
|
|
137
|
+
let stateFile;
|
|
138
|
+
if (options.stateFile !== undefined) stateFile = requireText(options.stateFile, '--state-file');
|
|
139
|
+
let assetRoot;
|
|
140
|
+
if (options.assetRoot !== undefined) {
|
|
141
|
+
assetRoot = requireText(options.assetRoot, '--asset-root');
|
|
142
|
+
if (isUrlLike(assetRoot)) {
|
|
143
|
+
throw usageError('Option "--asset-root" must be a local directory path; URLs are not supported.');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
help: false,
|
|
149
|
+
input,
|
|
150
|
+
output,
|
|
151
|
+
mode,
|
|
152
|
+
stateFile,
|
|
153
|
+
assets,
|
|
154
|
+
assetRoot,
|
|
155
|
+
locale,
|
|
156
|
+
colorScheme,
|
|
157
|
+
title: typeof options.title === 'string' ? options.title : undefined,
|
|
158
|
+
strict: options.strict === true,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {string[]} argv
|
|
164
|
+
* @returns {{help: boolean, inputs?: string[], json?: boolean, strict?: boolean}}
|
|
165
|
+
*/
|
|
166
|
+
export function parseLintArgs(argv) {
|
|
167
|
+
const { positionals, options } = parseOptions(argv, LINT_SPEC);
|
|
168
|
+
if (options.help) return { help: true };
|
|
169
|
+
if (positionals.length === 0) {
|
|
170
|
+
throw usageError('Missing lint inputs. Usage: reactive-md lint <files-or-dirs-or-globs...>.');
|
|
171
|
+
}
|
|
172
|
+
if (positionals.some((input) => input.trim() === '')) {
|
|
173
|
+
throw usageError('Lint input paths must not be empty.');
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
help: false,
|
|
177
|
+
inputs: positionals,
|
|
178
|
+
json: options.json === true,
|
|
179
|
+
strict: options.strict === true,
|
|
180
|
+
};
|
|
181
|
+
}
|