mdat 1.1.0 → 1.2.1

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.
@@ -4,9 +4,6 @@ declare const _default: {
4
4
  content(options: import("type-fest").JsonValue, tree: import("mdast").Root): Promise<string>;
5
5
  order: number;
6
6
  };
7
- tldraw: {
8
- content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
9
- };
10
7
  title: {
11
8
  applicationOrder: number;
12
9
  content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
@@ -57,12 +54,6 @@ declare const _default: {
57
54
  code: {
58
55
  content(options: import("type-fest").JsonValue): Promise<string>;
59
56
  };
60
- 'cli-help': {
61
- content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
62
- };
63
- cli: {
64
- content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
65
- };
66
57
  banner: {
67
58
  content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
68
59
  order: number;
@@ -13,7 +13,7 @@ export type SizeReport = {
13
13
  * Analyzes a file's size and its compressed sizes using Brotli and Gzip
14
14
  * @param filePath - Path to the file to analyze
15
15
  * @returns Promise containing detailed size report
16
- * @throws Error if file cannot be read or compressed
16
+ * @throws {Error} if file cannot be read or compressed
17
17
  */
18
18
  export declare function createSizeReport(filePath: string): Promise<SizeReport>;
19
19
  export {};
@@ -10,6 +10,6 @@ export declare function findReadme(): Promise<string | undefined>;
10
10
  * Searches up for a readme.md file
11
11
  * @see `findReadme()` for more details on the search process.
12
12
  * @returns The path to the readme file
13
- * @throws if no readme is found
13
+ * @throws {Error} if no readme is found
14
14
  */
15
15
  export declare function findReadmeThrows(): Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdat",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "CLI tool and TypeScript library implementing the Markdown Autophagic Template (MDAT) system. MDAT lets you use comments as dynamic content templates in Markdown files, making it easy to generate and update readme boilerplate.",
5
5
  "keywords": [
6
6
  "mdat",
@@ -38,45 +38,44 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@clack/prompts": "^0.11.0",
41
- "@kitschpatrol/tldraw-cli": "^5.0.0",
42
41
  "@types/mdast": "^4.0.4",
43
- "@types/node": "^20.19.17",
42
+ "@types/node": "^22.19.0",
44
43
  "@types/unist": "^3.0.3",
45
- "@types/which": "^3.0.4",
46
- "@types/yargs": "^17.0.33",
44
+ "@types/yargs": "^17.0.34",
47
45
  "cosmiconfig": "^9.0.0",
48
- "cosmiconfig-typescript-loader": "^6.1.0",
49
- "execa": "^9.6.0",
46
+ "cosmiconfig-typescript-loader": "^6.2.0",
50
47
  "globby": "^14.1.0",
51
48
  "read-pkg": "^9.0.1",
52
- "remark-mdat": "^1.1.1",
53
- "type-fest": "^5.0.1",
49
+ "remark-mdat": "^1.1.3",
50
+ "type-fest": "^5.2.0",
54
51
  "unified-engine": "^11.2.2",
55
- "vfile": "^6.0.3",
56
- "which": "^5.0.0"
52
+ "vfile": "^6.0.3"
57
53
  },
58
54
  "devDependencies": {
59
- "@kitschpatrol/shared-config": "^5.7.0",
60
- "bumpp": "^10.2.3",
61
- "chevrotain": "^11.0.3",
55
+ "@kitschpatrol/shared-config": "^5.8.1",
56
+ "bumpp": "^10.3.1",
57
+ "execa": "^9.6.0",
62
58
  "find-up": "^8.0.0",
63
59
  "mdast-util-toc": "^7.1.0",
60
+ "mdat-plugin-cli-help": "^1.0.2",
61
+ "mdat-plugin-example": "^1.0.1",
62
+ "mdat-plugin-tldraw": "^1.0.2",
64
63
  "nanoid": "^5.1.6",
65
64
  "package-directory": "^8.1.0",
66
65
  "package-up": "^5.0.0",
67
66
  "path-type": "^6.0.0",
68
67
  "picocolors": "^1.1.1",
69
- "plur": "^5.1.0",
68
+ "plur": "^6.0.0",
70
69
  "pretty-bytes": "^7.1.0",
71
70
  "pretty-ms": "^9.3.0",
72
71
  "remark": "^15.0.1",
73
72
  "remark-gfm": "^4.0.1",
74
73
  "to-vfile": "^8.0.0",
75
- "tsdown": "^0.15.5",
76
- "typescript": "~5.9.2",
74
+ "tsdown": "^0.16.0",
75
+ "typescript": "~5.9.3",
77
76
  "unplugin-raw": "^0.6.3",
78
77
  "untildify": "^6.0.0",
79
- "vitest": "^3.2.4",
78
+ "vitest": "^4.0.7",
80
79
  "yargs": "^17.7.2",
81
80
  "zod": "^3.25.76"
82
81
  },
@@ -92,7 +91,7 @@
92
91
  "dev": "pnpm run test",
93
92
  "fix": "ksc fix",
94
93
  "lint": "ksc lint",
95
- "release": "bumpp --commit 'Release: %s' && pnpm run build && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
94
+ "release": "bumpp --commit 'Release: %s' && pnpm run build && NPM_AUTH_TOKEN=$(op read 'op://Personal/npm/token') && pnpm publish",
96
95
  "test": "vitest --no-file-parallelism"
97
96
  }
98
97
  }
package/readme.md CHANGED
@@ -34,6 +34,10 @@
34
34
  - [Configuration](#configuration)
35
35
  - [Creating custom rules](#creating-custom-rules)
36
36
  - [The `mdat readme` subcommand](#the-mdat-readme-subcommand)
37
+ - [Plugins](#plugins)
38
+ - [Installing a rule plugin](#installing-a-rule-plugin)
39
+ - [Creating a rule plugin](#creating-a-rule-plugin)
40
+ - [Available rule plugins](#available-rule-plugins)
37
41
  - [Background](#background)
38
42
  - [Motivation](#motivation)
39
43
  - [Similar projects](#similar-projects)
@@ -190,7 +194,7 @@ As [noted below](#similar-projects), there are several similar projects out ther
190
194
  }
191
195
  ```
192
196
 
193
- This scales all the way up to some of the [more](src/lib/readme/rules/table-of-contents.ts) [elaborate](src/lib/readme/rules/cli-help.ts) rules found in the `mdat readme` subcommand.
197
+ This scales all the way up to some of the [more elaborate](src/lib/readme/rules/table-of-contents.ts) rules found in the `mdat readme` subcommand.
194
198
 
195
199
  You can also treat any JSON file as a rule set. MDAT will flatten it to allow any dot-notated key path to become a placeholder comment keyword.
196
200
 
@@ -454,7 +458,7 @@ mdat readme init [options]
454
458
 
455
459
  <!-- /cli-help -->
456
460
 
457
- _Meta note: The entire section above was generated automatically by the [`<!-- cli-help -->`](src/lib/readme/rules/cli-help.ts) mdat expansion rule provided in `mdat readme` subcommand. It dynamically parses the output from `mdat --help` into a Markdown table, recursively calling `--help` on subcommands to build a tidy representation of the help output._
461
+ _Meta note: The entire section above was generated automatically by the [mdat-plugin-cli-help](https://github.com/kitschpatrol/mdat-plugin-cli-help) plugin. It dynamically parses the output from `mdat --help` into a Markdown table, recursively calling `--help` on subcommands to build a tidy representation of the help output._
458
462
 
459
463
  #### Examples
460
464
 
@@ -745,33 +749,11 @@ See the [Examples section](https://github.com/kitschpatrol/remark-mdat#examples)
745
749
 
746
750
  | File | Original | Gzip | Brotli |
747
751
  | ------------ | -------- | ------- | ------ |
748
- | package.json | 2.6 kB | 1.1 kB | 987 B |
749
- | readme.md | 57.5 kB | 11.4 kB | 9.1 kB |
752
+ | package.json | 2.5 kB | 1.1 kB | 974 B |
753
+ | readme.md | 58 kB | 11.4 kB | 9.1 kB |
750
754
 
751
755
  <!-- /size-table -->
752
756
 
753
- - ###### `<!-- cli-help -->`
754
-
755
- Automatically transform a CLI command's `--help` output into nicely formatted Markdown tables. The rule also recursively calls `--help` on any subcommands found for inclusion in the output.
756
-
757
- Currently, the rule can only parse help output in the format provided by [Yargs](https://yargs.js.org)- and [Meow](https://github.com/sindresorhus/meow)-based tools. If parsing fails, the rule will fall back to show the raw help output in a regular code block.
758
-
759
- ([Parsing help output](src/lib/readme/rules/utilities/cli-help/parsers) is a bit tricky. The [jc](https://github.com/kellyjonbrazil/jc) project is a heroic collection of output parsers, but does not currently implement help output parsing. It might be interesting to try to contribute mdat's help parsing implementations to jc.)
760
-
761
- This rule is also aliased under the `<!-- cli -->` keyword.
762
-
763
- - ###### `<!-- tldraw { src: "./sketch.tldr" } -->`
764
-
765
- Allows embedding [tldraw](https://www.tldraw.com) files in your readme. Accepts either a path to a local `.tldr` file, or remote tldraw URLs.
766
-
767
- Automatically generates both "light" and "dark" SVG variations of the sketch, and emits a `<picture>` element per [GitHub's guidelines](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#specifying-the-theme-an-image-is-shown-to) to present the correctly themed image based on the viewer's preferences.
768
-
769
- Generated assets are intelligently hashed to aide in cache busting. For locally referenced files, the image will only be regenerated when the content in the source file changes.
770
-
771
- The implementation is based on [@kitschpatrol/tldraw-cli](https://github.com/kitschpatrol/tldraw-cli), and depends on Puppeteer to generate the assets, so it can be a bit slow. Referencing local files instead of remote URLs is recommended for improved performance.
772
-
773
- This rule is used to embed the diagram at the top of this readme.
774
-
775
757
  ##### Compound
776
758
 
777
759
  Compound rules combine several stand-alone rules under a single keyword, which can help reduce comment clutter in your readme's Markdown.
@@ -812,6 +794,99 @@ The `init` command provides a number of "starter readme" templates incorporating
812
794
 
813
795
  Includes all sections from the [Standard Readme](https://github.com/RichardLitt/standard-readme/blob/main/spec.md) specification. [See an example](https://github.com/RichardLitt/standard-readme/blob/main/example-readmes/maximal-readme.md).
814
796
 
797
+ ## Plugins
798
+
799
+ Rule plugins are packages that export one or more mdat expansion rules.
800
+
801
+ ### Installing a rule plugin
802
+
803
+ Install the plugin package using your package manager of choice. For example, with npm:
804
+
805
+ ```sh
806
+ npm install mdat-plugin-example
807
+ ```
808
+
809
+ To use the rule, just spread the plugin into your `mdat` configuration, for example in your project's `mdat.config.ts` file:
810
+
811
+ ```ts
812
+ import type { Config } from 'mdat'
813
+ import example from 'mdat-plugin-example'
814
+
815
+ export default {
816
+ rules: {
817
+ ...example,
818
+ },
819
+ } satisfies Config
820
+ ```
821
+
822
+ Then, you can use the `example` expansion rule in your Markdown files:
823
+
824
+ For example, in your `readme.md` file you can add:
825
+
826
+ ```md
827
+ <!-- example -->
828
+ ```
829
+
830
+ Then run the `mdat readme` subcommand:
831
+
832
+ ```sh
833
+ mdat readme
834
+ ```
835
+
836
+ Which will expand the `example` rule in your `readme.md` file to:
837
+
838
+ ```md
839
+ <!-- example -->
840
+
841
+ Hello from the [mdat](https://github.com/kitschpatrol/mdat) example plugin!
842
+
843
+ <!-- /example -->
844
+ ```
845
+
846
+ ### Creating a rule plugin
847
+
848
+ A rule plugin is a ESM module or npm package with a default export of or more mdat rules.
849
+
850
+ If you just need a quick one-off rule specific to your project, you can define it directly in your `mdat.config.ts` file. A plugin is only necessary if you want to share the rule or use it across multiple projects.
851
+
852
+ By convention, mdat plugin rule packages should have the name prefix `mdat-plugin-`. The package should take a peer dependency on `mdat`.
853
+
854
+ The most basic rule plugin might look like this:
855
+
856
+ ```ts
857
+ import type { Rules } from 'mdat'
858
+
859
+ export default {
860
+ hello: {
861
+ content() {
862
+ return 'Hello from an mdat plugin!'
863
+ },
864
+ },
865
+ } satisfies Rules
866
+ ```
867
+
868
+ See the [mdat-plugin-example](https://github.com/kitschpatrol/mdat-plugin-example) repository for a complete example.
869
+
870
+ ### Available rule plugins
871
+
872
+ #### [mdat-plugin-tldraw](https://github.com/kitschpatrol/mdat-plugin-tldraw)
873
+
874
+ Allows embedding [tldraw](https://www.tldraw.com) files in your readme.
875
+
876
+ This rule is used to embed the diagram at the top of this readme.
877
+
878
+ Example usage: `<!-- tldraw { src: "./sketch.tldr" } -->`
879
+
880
+ #### [mdat-plugin-cli-help](https://github.com/kitschpatrol/mdat-plugin-cli-help)
881
+
882
+ Automatically transform a CLI command's `--help` output into nicely formatted Markdown tables. The rule also recursively calls `--help` on any subcommands found for inclusion in the output.
883
+
884
+ Currently, the rule can only parse help output in the format provided by [Yargs](https://yargs.js.org)- and [Meow](https://github.com/sindresorhus/meow)-based tools. If parsing fails, the rule will fall back to show the raw help output in a regular code block.
885
+
886
+ Example usage: `<!-- cli-help -->`
887
+
888
+ This rule is also aliased under the `<!-- cli -->` keyword.
889
+
815
890
  ## Background
816
891
 
817
892
  ### Motivation
@@ -1,6 +0,0 @@
1
- declare const _default: {
2
- 'cli-help': {
3
- content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
4
- };
5
- };
6
- export default _default;
@@ -1,9 +0,0 @@
1
- /**
2
- * Simple alias for cli-help
3
- */
4
- declare const _default: {
5
- cli: {
6
- content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
7
- };
8
- };
9
- export default _default;
@@ -1,6 +0,0 @@
1
- declare const _default: {
2
- tldraw: {
3
- content(options?: import("type-fest").JsonValue | undefined): Promise<string>;
4
- };
5
- };
6
- export default _default;
@@ -1,8 +0,0 @@
1
- /**
2
- * Get help output from a CLI command and return it as markdown
3
- */
4
- export declare function getHelpMarkdown(cliCommand: string, helpFlag?: string, depth?: number): Promise<string>;
5
- /**
6
- * Exported for testing
7
- */
8
- export declare function renderHelpMarkdownBasic(rawHelpString: string): string;
@@ -1,6 +0,0 @@
1
- import type { ProgramInfo } from './parsers/index';
2
- /**
3
- * Converts a ProgramInfo object extracted by one of the help parsers into a big
4
- * beautiful Markdown table.
5
- */
6
- export declare function helpObjectToMarkdown(programInfo: ProgramInfo, depthRemaining?: number): string;
@@ -1,10 +0,0 @@
1
- import type { ProgramInfo } from './parsers/index';
2
- /**
3
- * Tries to parse a help string into an object through a process of trial and
4
- * error with the available parsers.
5
- *
6
- * Generally, there's no way to know which framework was used to generate a
7
- * particular CLI tool without inspecting the output for particular formatting
8
- * patterns.
9
- */
10
- export declare function helpStringToObject(helpString: string): ProgramInfo | undefined;
@@ -1,7 +0,0 @@
1
- /**
2
- * Accommodate missing or sloppy cli help command input
3
- * @param cliCommand - Can be nothing, a command name on the path like `git`, or a path to an executable like `./bin/cli.js`
4
- * @returns The path to a verified executable
5
- * @throws If nothing can be inferred or resolved
6
- */
7
- export declare function inferCommand(cliCommand: string | undefined): Promise<string>;
@@ -1,9 +0,0 @@
1
- /**
2
- * This file is vendored with modification from https://github.com/sindresorhus/is-executable
3
- * to work around a "[DEP0176] DeprecationWarning: fs.X_OK is deprecated, use fs.constants.X_OK instead"
4
- * error from Node.
5
- */
6
- /**
7
- * Check if a file is executable (async).
8
- */
9
- export declare function isExecutable(filePath: string): Promise<boolean>;
@@ -1,46 +0,0 @@
1
- import { helpStringToObject as helpStringToObjectMeow } from './meow';
2
- import { helpStringToObject as helpStringToObjectYargs } from './yargs';
3
- export type Command = {
4
- arguments?: string[];
5
- commandName?: string;
6
- default?: boolean;
7
- description?: string;
8
- parentCommandName?: string;
9
- };
10
- export type Positional = {
11
- arguments?: string[];
12
- defaultValue?: string;
13
- description?: string;
14
- required?: boolean;
15
- type?: string;
16
- };
17
- export type Option = {
18
- aliases?: string[];
19
- arguments?: string[];
20
- choices?: string[];
21
- defaultValue?: string;
22
- description?: string;
23
- flags?: string[];
24
- type?: string;
25
- };
26
- export type ProgramInfo = {
27
- arguments?: string[];
28
- commandName: string;
29
- commands?: Command[];
30
- description?: string;
31
- options?: Option[];
32
- positionals?: Positional[];
33
- subcommandName?: string;
34
- };
35
- declare const _default: {
36
- yargs: typeof helpStringToObjectYargs;
37
- meow: typeof helpStringToObjectMeow;
38
- };
39
- export default _default;
40
- /**
41
- * Get the command and subcommand from a command string.
42
- */
43
- export declare function getCommandParts(wholeCommand: string | undefined): {
44
- command: string;
45
- subcommand: string | undefined;
46
- };
@@ -1,7 +0,0 @@
1
- import type { ProgramInfo } from './index';
2
- /**
3
- * Converts am unstructured help string emitted from a CLI tool built with the
4
- * `meow` CLI library and turn it into a structured POJO describing the
5
- * command.
6
- */
7
- export declare function helpStringToObject(helpString: string): ProgramInfo;
@@ -1,7 +0,0 @@
1
- import type { ProgramInfo } from './index';
2
- /**
3
- * Converts am unstructured help string emitted from a CLI tool built with the
4
- * `Yargs` CLI library and turn it into a structured POJO describing the
5
- * command.
6
- */
7
- export declare function helpStringToObject(helpString: string): ProgramInfo;