mdat 2.0.1 → 2.1.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/dist/bin/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import picocolors from "picocolors";
3
3
  import prettyMilliseconds from "pretty-ms";
4
- import { getMdatReports, getSoleRule, mdatClean, mdatExpand, mdatSplit, reporterMdat, rulesSchema, setLogger } from "remark-mdat";
4
+ import { getMdatReports, getSoleRule, mdatCollapse, mdatExpand, mdatSplit, mdatStrip, reporterMdat, rulesSchema, setLogger } from "remark-mdat";
5
5
  import { cosmiconfig, defaultLoaders } from "cosmiconfig";
6
6
  import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
7
7
  import fs from "node:fs/promises";
@@ -42,7 +42,7 @@ function deepMergeDefined(...objects) {
42
42
  //#endregion
43
43
  //#region package.json
44
44
  var name = "mdat";
45
- var version = "2.0.1";
45
+ var version = "2.1.0";
46
46
 
47
47
  //#endregion
48
48
  //#region src/lib/log.ts
@@ -740,17 +740,26 @@ function getExpandProcessor(config, ambientRemarkConfig) {
740
740
  emphasis: "_"
741
741
  } }).use(remarkGfm).use(ambientRemarkConfig).use(() => async function(tree, file) {
742
742
  mdatSplit(tree, file);
743
- mdatClean(tree, file);
743
+ mdatCollapse(tree, file);
744
744
  await mdatExpand(tree, file, config);
745
745
  });
746
746
  }
747
- function getCleanProcessor(_config, ambientRemarkConfig) {
747
+ function getCollapseProcessor(_config, ambientRemarkConfig) {
748
748
  return remark().use({ settings: {
749
749
  bullet: "-",
750
750
  emphasis: "_"
751
751
  } }).use(remarkGfm).use(ambientRemarkConfig).use(() => function(tree, file) {
752
752
  mdatSplit(tree, file);
753
- mdatClean(tree, file);
753
+ mdatCollapse(tree, file);
754
+ });
755
+ }
756
+ function getStripProcessor(_config, ambientRemarkConfig) {
757
+ return remark().use({ settings: {
758
+ bullet: "-",
759
+ emphasis: "_"
760
+ } }).use(remarkGfm).use(ambientRemarkConfig).use(() => function(tree, file) {
761
+ mdatSplit(tree, file);
762
+ mdatStrip(tree, file);
754
763
  });
755
764
  }
756
765
 
@@ -889,10 +898,11 @@ function getTemplateOptions() {
889
898
  //#endregion
890
899
  //#region src/lib/api.ts
891
900
  /**
892
- * Expand MDAT comments in one or more Markdown files.
893
- * If no files are provided, auto-finds the closest readme.md.
894
- * Writing is the responsibility of the caller (e.g. via `await write(result)`)
895
- * @returns an array of VFiles
901
+ * Expand MDAT comments in one or more Markdown files. If no files are provided,
902
+ * auto-finds the closest readme.md. Writing is the responsibility of the caller
903
+ * (e.g. via `await write(result)`)
904
+ *
905
+ * @returns An array of VFiles
896
906
  */
897
907
  async function expand(files, name, output, config, options) {
898
908
  files ??= await findReadmeThrows();
@@ -901,21 +911,37 @@ async function expand(files, name, output, config, options) {
901
911
  return results;
902
912
  }
903
913
  /**
904
- * Collapse MDAT comments in one or more Markdown files.
905
- * If no files are provided, auto-finds the closest readme.md.
906
- * Writing is the responsibility of the caller (e.g. via `await write(result)`)
907
- * @returns an array of VFiles
914
+ * Collapse MDAT comments in one or more Markdown files. If no files are
915
+ * provided, auto-finds the closest readme.md. Writing is the responsibility of
916
+ * the caller (e.g. via `await write(result)`)
917
+ *
918
+ * @returns An array of VFiles
908
919
  */
909
920
  async function collapse(files, name, output, config, options) {
910
921
  files ??= await findReadmeThrows();
911
- const results = await processFiles(files, loadConfig, getCleanProcessor, name, output, config);
922
+ const results = await processFiles(files, loadConfig, getCollapseProcessor, name, output, config);
923
+ if (options?.format) await formatResults(results);
924
+ return results;
925
+ }
926
+ /**
927
+ * Strips MDAT comments in one or more Markdown files without touching other
928
+ * content. Does _not_ automatically expand Mdat content before stripping the
929
+ * tags. If no files are provided, auto-finds the closest readme.md. Writing is
930
+ * the responsibility of the caller (e.g. via `await write(result)`)
931
+ *
932
+ * @returns An array of VFiles
933
+ */
934
+ async function strip(files, name, output, config, options) {
935
+ files ??= await findReadmeThrows();
936
+ const results = await processFiles(files, loadConfig, getStripProcessor, name, output, config);
912
937
  if (options?.format) await formatResults(results);
913
938
  return results;
914
939
  }
915
940
  /**
916
- * Dry-run expand and compare with file on disk.
917
- * If no files are provided, auto-finds the closest readme.md.
918
- * @returns per-file sync status and expanded VFiles
941
+ * Dry-run expand and compare with file on disk. If no files are provided,
942
+ * auto-finds the closest readme.md.
943
+ *
944
+ * @returns Per-file sync status and expanded VFiles
919
945
  */
920
946
  async function check(files, config, options) {
921
947
  files ??= await findReadmeThrows();
@@ -1041,6 +1067,18 @@ try {
1041
1067
  reporterMdat(results);
1042
1068
  log.debug(`Collapsed comments in ${prettyMilliseconds(performance.now() - startTime)}.`);
1043
1069
  process.exitCode = getExitCode(results);
1070
+ }).command("strip [files..] [options]", "Strip MDAT comments while preserving expanded content. If no files are provided, the closest readme.md is stripped.", (yargs) => yargs.positional(...filesPositional).option(outputOption).option(nameOption).option(printOption).option(formatOption), async ({ files, format, name, output, print }) => {
1071
+ logConflicts({
1072
+ name,
1073
+ output,
1074
+ print
1075
+ });
1076
+ const results = await strip(files, name, output, void 0, { format });
1077
+ for (const file of results) if (print) process.stdout.write(file.toString());
1078
+ else await write(file);
1079
+ reporterMdat(results);
1080
+ log.debug(`Stripped comments in ${prettyMilliseconds(performance.now() - startTime)}.`);
1081
+ process.exitCode = getExitCode(results);
1044
1082
  }).command("check [files..] [options]", "Check if MDAT placeholder comments are up to date. Exits with code 1 if any files have stale or unexpanded content.", (yargs) => yargs.positional(...filesPositional).option(configOption).option(formatOption), async ({ config, files, format }) => {
1045
1083
  const results = await check(files, collectConfig(config), { format });
1046
1084
  let allInSync = true;
@@ -67,10 +67,11 @@ declare function createReadme(options?: Partial<MdatReadmeCreateOptions>): Promi
67
67
  //#endregion
68
68
  //#region src/lib/api.d.ts
69
69
  /**
70
- * Expand MDAT comments in one or more Markdown files.
71
- * If no files are provided, auto-finds the closest readme.md.
72
- * Writing is the responsibility of the caller (e.g. via `await write(result)`)
73
- * @returns an array of VFiles
70
+ * Expand MDAT comments in one or more Markdown files. If no files are provided,
71
+ * auto-finds the closest readme.md. Writing is the responsibility of the caller
72
+ * (e.g. via `await write(result)`)
73
+ *
74
+ * @returns An array of VFiles
74
75
  */
75
76
  declare function expand(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, options?: {
76
77
  format?: boolean;
@@ -82,10 +83,11 @@ declare function expandString(markdown: string, config?: ConfigToLoad, options?:
82
83
  format?: boolean;
83
84
  }): Promise<VFile>;
84
85
  /**
85
- * Collapse MDAT comments in one or more Markdown files.
86
- * If no files are provided, auto-finds the closest readme.md.
87
- * Writing is the responsibility of the caller (e.g. via `await write(result)`)
88
- * @returns an array of VFiles
86
+ * Collapse MDAT comments in one or more Markdown files. If no files are
87
+ * provided, auto-finds the closest readme.md. Writing is the responsibility of
88
+ * the caller (e.g. via `await write(result)`)
89
+ *
90
+ * @returns An array of VFiles
89
91
  */
90
92
  declare function collapse(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, options?: {
91
93
  format?: boolean;
@@ -97,9 +99,27 @@ declare function collapseString(markdown: string, config?: ConfigToLoad, options
97
99
  format?: boolean;
98
100
  }): Promise<VFile>;
99
101
  /**
100
- * Dry-run expand and compare with file on disk.
101
- * If no files are provided, auto-finds the closest readme.md.
102
- * @returns per-file sync status and expanded VFiles
102
+ * Strips MDAT comments in one or more Markdown files without touching other
103
+ * content. Does _not_ automatically expand Mdat content before stripping the
104
+ * tags. If no files are provided, auto-finds the closest readme.md. Writing is
105
+ * the responsibility of the caller (e.g. via `await write(result)`)
106
+ *
107
+ * @returns An array of VFiles
108
+ */
109
+ declare function strip(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, options?: {
110
+ format?: boolean;
111
+ }): Promise<VFile[]>;
112
+ /**
113
+ * Strip MDAT comments from a Markdown string.
114
+ */
115
+ declare function stripString(markdown: string, config?: ConfigToLoad, options?: {
116
+ format?: boolean;
117
+ }): Promise<VFile>;
118
+ /**
119
+ * Dry-run expand and compare with file on disk. If no files are provided,
120
+ * auto-finds the closest readme.md.
121
+ *
122
+ * @returns Per-file sync status and expanded VFiles
103
123
  */
104
124
  declare function check(files?: string | string[], config?: ConfigToLoad, options?: {
105
125
  format?: boolean;
@@ -160,4 +180,4 @@ declare function resetMetadataCaches(): void;
160
180
  */
161
181
  declare function setLogger(logger?: ILogBasic | ILogLayer): void;
162
182
  //#endregion
163
- export { type Config, type ReadmeMetadata, type Rule, check, collapse, collapseString, createReadme as create, createReadmeInteractive as createInteractive, defineConfig, expand, expandString, getContextMetadata, getReadmeMetadata, loadConfig, mergeConfig, resetMetadataCaches, setLogger };
183
+ export { type Config, type ReadmeMetadata, type Rule, check, collapse, collapseString, createReadme as create, createReadmeInteractive as createInteractive, defineConfig, expand, expandString, getContextMetadata, getReadmeMetadata, loadConfig, mergeConfig, resetMetadataCaches, setLogger, strip, stripString };
package/dist/lib/index.js CHANGED
@@ -4,7 +4,7 @@ import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import picocolors from "picocolors";
6
6
  import plur from "plur";
7
- import { getSoleRule, mdatClean, mdatExpand, mdatSplit, rulesSchema, setLogger as setLogger$1 } from "remark-mdat";
7
+ import { getSoleRule, mdatCollapse, mdatExpand, mdatSplit, mdatStrip, rulesSchema, setLogger as setLogger$1 } from "remark-mdat";
8
8
  import { deepmerge } from "deepmerge-ts";
9
9
  import { createLogger, getChildLogger, injectionHelper } from "lognow";
10
10
  import { defineTemplate, getMetadata, helpers, setLogger as setLogger$2, templates } from "metascope";
@@ -748,17 +748,26 @@ function getExpandProcessor(config, ambientRemarkConfig) {
748
748
  emphasis: "_"
749
749
  } }).use(remarkGfm).use(ambientRemarkConfig).use(() => async function(tree, file) {
750
750
  mdatSplit(tree, file);
751
- mdatClean(tree, file);
751
+ mdatCollapse(tree, file);
752
752
  await mdatExpand(tree, file, config);
753
753
  });
754
754
  }
755
- function getCleanProcessor(_config, ambientRemarkConfig) {
755
+ function getCollapseProcessor(_config, ambientRemarkConfig) {
756
756
  return remark().use({ settings: {
757
757
  bullet: "-",
758
758
  emphasis: "_"
759
759
  } }).use(remarkGfm).use(ambientRemarkConfig).use(() => function(tree, file) {
760
760
  mdatSplit(tree, file);
761
- mdatClean(tree, file);
761
+ mdatCollapse(tree, file);
762
+ });
763
+ }
764
+ function getStripProcessor(_config, ambientRemarkConfig) {
765
+ return remark().use({ settings: {
766
+ bullet: "-",
767
+ emphasis: "_"
768
+ } }).use(remarkGfm).use(ambientRemarkConfig).use(() => function(tree, file) {
769
+ mdatSplit(tree, file);
770
+ mdatStrip(tree, file);
762
771
  });
763
772
  }
764
773
  //#endregion
@@ -888,10 +897,11 @@ function getTemplateOptions() {
888
897
  //#endregion
889
898
  //#region src/lib/api.ts
890
899
  /**
891
- * Expand MDAT comments in one or more Markdown files.
892
- * If no files are provided, auto-finds the closest readme.md.
893
- * Writing is the responsibility of the caller (e.g. via `await write(result)`)
894
- * @returns an array of VFiles
900
+ * Expand MDAT comments in one or more Markdown files. If no files are provided,
901
+ * auto-finds the closest readme.md. Writing is the responsibility of the caller
902
+ * (e.g. via `await write(result)`)
903
+ *
904
+ * @returns An array of VFiles
895
905
  */
896
906
  async function expand(files, name, output, config, options) {
897
907
  files ??= await findReadmeThrows();
@@ -908,14 +918,15 @@ async function expandString(markdown, config, options) {
908
918
  return result;
909
919
  }
910
920
  /**
911
- * Collapse MDAT comments in one or more Markdown files.
912
- * If no files are provided, auto-finds the closest readme.md.
913
- * Writing is the responsibility of the caller (e.g. via `await write(result)`)
914
- * @returns an array of VFiles
921
+ * Collapse MDAT comments in one or more Markdown files. If no files are
922
+ * provided, auto-finds the closest readme.md. Writing is the responsibility of
923
+ * the caller (e.g. via `await write(result)`)
924
+ *
925
+ * @returns An array of VFiles
915
926
  */
916
927
  async function collapse(files, name, output, config, options) {
917
928
  files ??= await findReadmeThrows();
918
- const results = await processFiles(files, loadConfig, getCleanProcessor, name, output, config);
929
+ const results = await processFiles(files, loadConfig, getCollapseProcessor, name, output, config);
919
930
  if (options?.format) await formatResults(results);
920
931
  return results;
921
932
  }
@@ -923,14 +934,37 @@ async function collapse(files, name, output, config, options) {
923
934
  * Collapse MDAT comments in a Markdown string.
924
935
  */
925
936
  async function collapseString(markdown, config, options) {
926
- const result = await processString(markdown, loadConfig, getCleanProcessor, config);
937
+ const result = await processString(markdown, loadConfig, getCollapseProcessor, config);
938
+ if (options?.format) await formatResults([result]);
939
+ return result;
940
+ }
941
+ /**
942
+ * Strips MDAT comments in one or more Markdown files without touching other
943
+ * content. Does _not_ automatically expand Mdat content before stripping the
944
+ * tags. If no files are provided, auto-finds the closest readme.md. Writing is
945
+ * the responsibility of the caller (e.g. via `await write(result)`)
946
+ *
947
+ * @returns An array of VFiles
948
+ */
949
+ async function strip(files, name, output, config, options) {
950
+ files ??= await findReadmeThrows();
951
+ const results = await processFiles(files, loadConfig, getStripProcessor, name, output, config);
952
+ if (options?.format) await formatResults(results);
953
+ return results;
954
+ }
955
+ /**
956
+ * Strip MDAT comments from a Markdown string.
957
+ */
958
+ async function stripString(markdown, config, options) {
959
+ const result = await processString(markdown, loadConfig, getStripProcessor, config);
927
960
  if (options?.format) await formatResults([result]);
928
961
  return result;
929
962
  }
930
963
  /**
931
- * Dry-run expand and compare with file on disk.
932
- * If no files are provided, auto-finds the closest readme.md.
933
- * @returns per-file sync status and expanded VFiles
964
+ * Dry-run expand and compare with file on disk. If no files are provided,
965
+ * auto-finds the closest readme.md.
966
+ *
967
+ * @returns Per-file sync status and expanded VFiles
934
968
  */
935
969
  async function check(files, config, options) {
936
970
  files ??= await findReadmeThrows();
@@ -947,4 +981,4 @@ async function formatResults(results) {
947
981
  for (const file of results) file.value = await formatWithPrettier(file.toString(), file.path || void 0);
948
982
  }
949
983
  //#endregion
950
- export { check, collapse, collapseString, createReadme as create, createReadmeInteractive as createInteractive, defineConfig, expand, expandString, getContextMetadata, getReadmeMetadata, loadConfig, mergeConfig, resetMetadataCaches, setLogger };
984
+ export { check, collapse, collapseString, createReadme as create, createReadmeInteractive as createInteractive, defineConfig, expand, expandString, getContextMetadata, getReadmeMetadata, loadConfig, mergeConfig, resetMetadataCaches, setLogger, strip, stripString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdat",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
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",
@@ -50,7 +50,7 @@
50
50
  "globby": "^16.2.0",
51
51
  "lognow": "^0.6.0",
52
52
  "mdast-util-toc": "^7.1.0",
53
- "metascope": "^0.5.0",
53
+ "metascope": "^0.6.0",
54
54
  "path-type": "^6.0.0",
55
55
  "picocolors": "^1.1.1",
56
56
  "plur": "^6.0.0",
@@ -58,7 +58,7 @@
58
58
  "pretty-ms": "^9.3.0",
59
59
  "remark": "^15.0.1",
60
60
  "remark-gfm": "^4.0.1",
61
- "remark-mdat": "^2.0.2",
61
+ "remark-mdat": "^2.1.0",
62
62
  "to-vfile": "^8.0.0",
63
63
  "type-fest": "^5.5.0",
64
64
  "unified-engine": "^11.2.2",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@arethetypeswrong/core": "^0.18.2",
72
- "@kitschpatrol/shared-config": "^7.0.0",
72
+ "@kitschpatrol/shared-config": "^7.0.1",
73
73
  "@types/mdast": "^4.0.4",
74
74
  "@types/node": "~22.17.2",
75
75
  "@types/unist": "^3.0.3",
package/readme.md CHANGED
@@ -228,6 +228,7 @@ mdat [command] [files..] [options]
228
228
  | ---------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------- |
229
229
  | `expand` | `[files..]` `[options]` | Expand MDAT placeholder comments. If no files are provided, the closest readme.md is expanded. _(Default command.)_ |
230
230
  | `collapse` | `[files..]` `[options]` | Collapse MDAT placeholder comments. If no files are provided, the closest readme.md is collapsed. |
231
+ | `strip` | `[files..]` `[options]` | Strip MDAT comments while preserving expanded content. If no files are provided, the closest readme.md is stripped. |
231
232
  | `check` | `[files..]` `[options]` | Check if MDAT placeholder comments are up to date. Exits with code 1 if any files have stale or unexpanded content. |
232
233
  | `create` | `[options]` | Create a new Markdown file from a template. |
233
234
 
@@ -282,6 +283,30 @@ mdat collapse [files..] [options]
282
283
  | `--help`<br>`-h` | Show help | `boolean` | |
283
284
  | `--version`<br>`-v` | Show version number | `boolean` | |
284
285
 
286
+ #### Subcommand: `mdat strip`
287
+
288
+ Strip MDAT comments while preserving expanded content. If no files are provided, the closest readme.md is stripped.
289
+
290
+ Usage:
291
+
292
+ ```txt
293
+ mdat strip [files..] [options]
294
+ ```
295
+
296
+ | Positional Argument | Description | Type |
297
+ | ------------------- | ----------------------------------------------------------------------------------------------------- | -------- |
298
+ | `files` | Markdown file(s) with MDAT placeholder comments. If not provided, the closest readme.md file is used. | `string` |
299
+
300
+ | Option | Description | Type | Default |
301
+ | ------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------- |
302
+ | `--verbose` | Enable verbose logging. All verbose logs are prefixed with their log level and are printed to stderr for ease of redirection. | `boolean` | |
303
+ | `--output`<br>`-o` | Output file directory. | `string` | Same directory as input file. |
304
+ | `--name`<br>`-n` | Output file name. | `string` | Same name as input file. Overwrites the input file. |
305
+ | `--print` | Print the expanded Markdown to stdout instead of saving to a file. Ignores `--output` and `--name` options. | `boolean` | |
306
+ | `--format`<br>`-f` | Format the output with Prettier. Discovers Prettier config from the file path. Requires `prettier` as a peer dependency. | `boolean` | |
307
+ | `--help`<br>`-h` | Show help | `boolean` | |
308
+ | `--version`<br>`-v` | Show version number | `boolean` | |
309
+
285
310
  #### Subcommand: `mdat check`
286
311
 
287
312
  Check if MDAT placeholder comments are up to date. Exits with code 1 if any files have stale or unexpanded content.
@@ -366,6 +391,12 @@ mdat check
366
391
  mdat collapse
367
392
  ```
368
393
 
394
+ ##### Strip MDAT comments from expanded content
395
+
396
+ ```sh
397
+ mdat strip
398
+ ```
399
+
369
400
  ##### Expand and format with Prettier
370
401
 
371
402
  ```sh
@@ -420,6 +451,12 @@ Expands MDAT comments in a Markdown string. Call `.toString()` on the returned [
420
451
 
421
452
  Removes expanded content, leaving only the opening comment placeholders. Same signatures as `expand` / `expandString`.
422
453
 
454
+ #### `strip` / `stripString`
455
+
456
+ Strips all MDAT comment tags (both opening and closing) while preserving expanded content between them. Same signatures as `expand` / `expandString` (without the `config` parameter, since rules are not needed).
457
+
458
+ This is useful for producing a "clean" Markdown file that no longer depends on MDAT for future updates.
459
+
423
460
  #### `check`
424
461
 
425
462
  ```ts
@@ -577,16 +614,16 @@ See the [Examples section](https://github.com/kitschpatrol/remark-mdat#examples)
577
614
 
578
615
  Embeds a file's size, with optional Brotli or Gzip compressed size.
579
616
 
580
- - ##### `<!-- size-table({ files: [".gitignore", "readme.md"] }) -->`
617
+ - ##### `<!-- size-table({ files: [".gitignore", "license.txt"] }) -->`
581
618
 
582
619
  A table of files and their compressed sizes:
583
620
 
584
- <!-- size-table({ files: [".gitignore", "readme.md"] }) -->
621
+ <!-- size-table({ files: [".gitignore", "license.txt"] }) -->
585
622
 
586
- | File | Original | Gzip | Brotli |
587
- | ---------- | -------- | ------ | ------ |
588
- | .gitignore | 305 B | 245 B | 216 B |
589
- | readme.md | 34.4 kB | 8.3 kB | 6.9 kB |
623
+ | File | Original | Gzip | Brotli |
624
+ | ----------- | -------- | ----- | ------ |
625
+ | .gitignore | 305 B | 245 B | 216 B |
626
+ | license.txt | 1 kB | 659 B | 468 B |
590
627
 
591
628
  <!-- /size-table -->
592
629
 
package/dist/.DS_Store DELETED
Binary file