mdat 0.10.0 → 1.0.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.
@@ -1,2 +1,7 @@
1
1
  import { type LoaderResult } from 'cosmiconfig';
2
+ /**
3
+ * Lets arbitrary JSON objects (like from package.json) become reasonably good mdat rule sets
4
+ * HOWEVER cosmiconfig treats package.json as a special case and will always load only specific keys from it
5
+ * So we have to intercept and load them manually in config.ts
6
+ */
2
7
  export declare function mdatJsonLoader(filePath: string, content: string): LoaderResult;
@@ -1,10 +1,46 @@
1
1
  import { type VFile } from 'vfile';
2
2
  import { type ConfigToLoad, type RulesToLoad } from '../config';
3
+ /**
4
+ * Expands MDAT readme comments in the closest readme.md file
5
+ * Basically an alias to `expandReadmeFiles()` with certain arguments elided.
6
+ * @see `findReadme()` for more details on the search process.
7
+ */
3
8
  export declare function expandReadme(config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
9
+ /**
10
+ * Expands MDAT readme comments in one or more Markdown files
11
+ * Searches up for a readme.md file if none is provided.
12
+ * @see `findReadme()` for more details on the search process.
13
+ */
4
14
  export declare function expandReadmeFiles(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
15
+ /**
16
+ * Expands MDAT readme comments in a Markdown string
17
+ */
5
18
  export declare function expandReadmeString(markdown: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
19
+ /**
20
+ * Checks and validates MDAT readme comments in the closest readme.md file
21
+ * Basically an alias to `checkReadmeFiles()` with certain arguments elided.
22
+ * @see `findReadme()` for more details on the search process.
23
+ */
6
24
  export declare function checkReadme(config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
25
+ /**
26
+ * Checks and validates MDAT readme comments in one or more Markdown files
27
+ * Searches up for a readme.md file if none is provided.
28
+ * @see `findReadme()` for more details on the search process.
29
+ */
7
30
  export declare function checkReadmeFiles(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
31
+ /**
32
+ * Checks and validates MDAT readme comments in a Markdown string
33
+ */
8
34
  export declare function checkReadmeString(markdown: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
35
+ /**
36
+ * Collapses MDAT readme comments in the closest readme.md file
37
+ * Basically an alias to `collapseReadmeFiles()` with certain arguments elided.
38
+ * @see `findReadme()` for more details on the search process.
39
+ */
9
40
  export declare function collapseReadme(config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
41
+ /**
42
+ * Collapses MDAT readme comments in one or more Markdown files
43
+ * Searches up for a readme.md file if none is provided.
44
+ * @see `findReadme()` for more details on the search process.
45
+ */
10
46
  export declare function collapseReadmeFiles(files?: string | string[], name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
@@ -1,8 +1,11 @@
1
1
  import { type Simplify } from 'type-fest';
2
2
  import { type ConfigLoaded, loadConfig } from '../config';
3
- type ReadmeConfigLoaded = Simplify<{
3
+ type ReadmeConfigLoaded = Simplify<ConfigLoaded & {
4
4
  packageFile: string;
5
- } & ConfigLoaded>;
5
+ }>;
6
6
  type LoadConfigOptions = Parameters<typeof loadConfig>[0];
7
+ /**
8
+ * Convenience loader to always include the default readme config
9
+ */
7
10
  export declare function loadConfigReadme(options?: LoadConfigOptions): Promise<ReadmeConfigLoaded>;
8
11
  export {};
@@ -1,6 +1,3 @@
1
- export type Symbolize<T extends Record<string, unknown>> = {
2
- [x in keyof T]: symbol | T[x];
3
- };
4
1
  type MdatReadmeInitOptions = {
5
2
  compound: boolean;
6
3
  expand: boolean;
@@ -8,9 +5,14 @@ type MdatReadmeInitOptions = {
8
5
  overwrite: boolean;
9
6
  template: string;
10
7
  };
8
+ /**
9
+ * Initializes a new readme file interactively.
10
+ * @returns Path to the created readme file.
11
+ */
11
12
  export declare function initReadmeInteractive(): Promise<string>;
12
13
  /**
13
- * @return Path to the created readme file.
14
+ * Creates a new readme file with the given options.
15
+ * @returns Path to the created readme file.
14
16
  */
15
17
  export declare function initReadme(options?: Partial<MdatReadmeInitOptions>): Promise<string>;
16
18
  export {};
@@ -2,4 +2,7 @@
2
2
  * Get help output from a CLI command and return it as markdown
3
3
  */
4
4
  export declare function getHelpMarkdown(cliCommand: string, helpFlag?: string, depth?: number): Promise<string>;
5
+ /**
6
+ * Exported for testing
7
+ */
5
8
  export declare function renderHelpMarkdownBasic(rawHelpString: string): string;
@@ -1,2 +1,6 @@
1
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
+ */
2
6
  export declare function helpObjectToMarkdown(programInfo: ProgramInfo, depthRemaining?: number): string;
@@ -1,2 +1,10 @@
1
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
+ */
2
10
  export declare function helpStringToObject(helpString: string): ProgramInfo | undefined;
@@ -37,6 +37,9 @@ declare const _default: {
37
37
  meow: typeof helpStringToObjectMeow;
38
38
  };
39
39
  export default _default;
40
+ /**
41
+ * Get the command and subcommand from a command string.
42
+ */
40
43
  export declare function getCommandParts(wholeCommand: string | undefined): {
41
44
  command: string;
42
45
  subcommand: string | undefined;
@@ -1,2 +1,7 @@
1
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
+ */
2
7
  export declare function helpStringToObject(helpString: string): ProgramInfo;
@@ -1,2 +1,7 @@
1
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
+ */
2
7
  export declare function helpStringToObject(helpString: string): ProgramInfo;
@@ -1,12 +1,3 @@
1
- export type Template = {
2
- content: {
3
- compound: string;
4
- explicit: string;
5
- };
6
- description: string;
7
- exampleLink: `https://${string}.md`;
8
- };
9
- export type Templates = Record<string, Template>;
10
1
  declare const _default: {
11
2
  'MDAT Readme': {
12
3
  content: {
@@ -3,8 +3,13 @@
3
3
  * 1. Searches the current working directly for readme.md
4
4
  * 2. If there's no readme.md in the current directory, search up to the closest package directory
5
5
  * 3. Give up and return undefined if no readme is found
6
- *
7
6
  * @returns The path to the readme file or undefined if not found
8
7
  */
9
8
  export declare function findReadme(): Promise<string | undefined>;
9
+ /**
10
+ * Searches up for a readme.md file
11
+ * @see `findReadme()` for more details on the search process.
12
+ * @returns The path to the readme file
13
+ * @throws if no readme is found
14
+ */
10
15
  export declare function findReadmeThrows(): Promise<string>;
@@ -5,12 +5,6 @@ export declare function getInputOutputPaths(inputs: string[], output: string | u
5
5
  name: string;
6
6
  output: string;
7
7
  }>;
8
- export declare function getInputOutputPath(input: string, output: string | undefined, name: string | undefined, extension: string | undefined, nameSuffix?: string): {
9
- input: string;
10
- name: string;
11
- output: string;
12
- };
13
- export declare function expandPath(file: string): string;
14
8
  export declare function findPackage(): Promise<string | undefined>;
15
9
  export declare function ensureArray<T>(value: T | T[] | undefined): T[];
16
10
  export declare function loadAmbientRemarkConfig(): Promise<AmbientRemarkConfig>;
package/license.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Eric Mika
3
+ Copyright (c) 2024-2025 Eric Mika
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,71 +1,69 @@
1
1
  {
2
2
  "name": "mdat",
3
- "version": "0.10.0",
4
- "type": "module",
5
- "description": "CLI tool and 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.",
6
- "repository": "github:kitschpatrol/mdat",
3
+ "version": "1.0.1",
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
+ "keywords": [
6
+ "mdat",
7
+ "markdown",
8
+ "template",
9
+ "readme",
10
+ "comments",
11
+ "docs-generator",
12
+ "docs",
13
+ "cli",
14
+ "npm-package"
15
+ ],
7
16
  "homepage": "https://github.com/kitschpatrol/mdat",
8
17
  "bugs": "https://github.com/kitschpatrol/mdat/issues",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/kitschpatrol/mdat.git"
21
+ },
22
+ "license": "MIT",
9
23
  "author": {
10
24
  "name": "Eric Mika",
11
25
  "email": "eric@ericmika.com",
12
26
  "url": "https://ericmika.com"
13
27
  },
14
- "license": "MIT",
15
- "engines": {
16
- "node": "^18.19.0 || >=20.5.0",
17
- "pnpm": ">=9.0.0"
18
- },
19
- "bin": {
20
- "mdat": "bin/cli.js"
21
- },
28
+ "type": "module",
22
29
  "main": "./dist/index.js",
23
30
  "module": "./dist/index.js",
24
31
  "types": "./dist/index.d.ts",
32
+ "bin": {
33
+ "mdat": "bin/cli.js"
34
+ },
25
35
  "files": [
26
36
  "bin/*",
27
37
  "dist/*"
28
38
  ],
29
- "keywords": [
30
- "mdat",
31
- "markdown",
32
- "template",
33
- "readme",
34
- "comments",
35
- "docs-generator",
36
- "docs",
37
- "cli",
38
- "npm-package"
39
- ],
40
39
  "dependencies": {
41
- "@clack/prompts": "^0.7.0",
42
- "@kitschpatrol/tldraw-cli": "^4.6.28",
40
+ "@clack/prompts": "^0.10.0",
41
+ "@kitschpatrol/tldraw-cli": "^4.6.31",
43
42
  "@types/mdast": "^4.0.4",
44
- "@types/node": "18.19.0",
43
+ "@types/node": "^18.19.79",
45
44
  "@types/unist": "^3.0.3",
45
+ "@types/which": "^3.0.4",
46
46
  "@types/yargs": "^17.0.33",
47
47
  "cosmiconfig": "^9.0.0",
48
48
  "cosmiconfig-typescript-loader": "^6.1.0",
49
49
  "execa": "^9.5.2",
50
- "globby": "^14.0.2",
50
+ "globby": "^14.1.0",
51
51
  "read-pkg": "^9.0.1",
52
- "remark-mdat": "^0.7.5",
53
- "type-fest": "^4.33.0",
52
+ "remark-mdat": "^1.0.2",
53
+ "type-fest": "^4.36.0",
54
54
  "unified-engine": "^11.2.2",
55
55
  "vfile": "^6.0.3",
56
56
  "which": "^5.0.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@kitschpatrol/shared-config": "^4.7.12",
60
- "@types/which": "^3.0.4",
61
- "bumpp": "^10.0.1",
59
+ "@kitschpatrol/shared-config": "^5.2.0",
60
+ "bumpp": "^10.0.3",
62
61
  "chalk": "^5.4.1",
63
62
  "chevrotain": "^11.0.3",
64
63
  "find-up": "^7.0.0",
65
64
  "is-executable": "^2.0.1",
66
- "mdast-util-to-markdown": "^2.1.2",
67
65
  "mdast-util-toc": "^7.1.0",
68
- "nanoid": "^5.0.9",
66
+ "nanoid": "^5.1.2",
69
67
  "package-up": "^5.0.0",
70
68
  "path-type": "^6.0.0",
71
69
  "pkg-dir": "^8.0.0",
@@ -73,14 +71,17 @@
73
71
  "pretty-bytes": "^6.1.1",
74
72
  "pretty-ms": "^9.2.0",
75
73
  "remark": "^15.0.1",
76
- "remark-gfm": "^4.0.0",
74
+ "remark-gfm": "^4.0.1",
77
75
  "to-vfile": "^8.0.0",
78
- "tsup": "^8.3.6",
79
- "typescript": "^5.7.3",
76
+ "tsup": "^8.4.0",
77
+ "typescript": "~5.7.3",
80
78
  "untildify": "^5.0.0",
81
- "vitest": "^2.1.8",
79
+ "vitest": "^3.0.7",
82
80
  "yargs": "^17.7.2",
83
- "zod": "^3.24.1"
81
+ "zod": "^3.24.2"
82
+ },
83
+ "engines": {
84
+ "node": "^18.19.0 || >=20.11.0"
84
85
  },
85
86
  "publishConfig": {
86
87
  "access": "public"
@@ -89,8 +90,8 @@
89
90
  "build": "tsup && tsc -p tsconfig.build.lib.json",
90
91
  "clean": "git rm -f pnpm-lock.yaml ; git clean -fdX",
91
92
  "dev": "pnpm run test",
92
- "fix": "shared-config --fix",
93
- "lint": "shared-config --lint",
93
+ "fix": "kpi fix",
94
+ "lint": "kpi lint",
94
95
  "release": "bumpp --commit 'Release: %s' && pnpm run build && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
95
96
  "test": "vitest --no-file-parallelism"
96
97
  }
package/readme.md CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  <!-- description -->
17
17
 
18
- **CLI tool and 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.**
18
+ **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.**
19
19
 
20
20
  <!-- /description -->
21
21
 
@@ -153,7 +153,7 @@ As [noted below](#similar-projects), there are several similar projects out ther
153
153
  An expansion rule can be as minimal as a file exporting a record:
154
154
 
155
155
  ```ts
156
- { keyword: "content"}`
156
+ export default { keyword: 'content' }
157
157
  ```
158
158
 
159
159
  Which will turn:
@@ -175,13 +175,13 @@ As [noted below](#similar-projects), there are several similar projects out ther
175
175
  Or, make things a bit more dynamic by returning a function instead of a string. Async functions are welcome.
176
176
 
177
177
  ```ts
178
- { date: () => `${new Date().toISOString()}` } }"
178
+ export default { date: () => `${new Date().toISOString()}` }
179
179
  ```
180
180
 
181
181
  Or enforce validation by adding some metadata:
182
182
 
183
183
  ```ts
184
- {
184
+ export default {
185
185
  date: {
186
186
  content: () => `${new Date().toISOString()}`,
187
187
  order: 1,
@@ -557,10 +557,10 @@ Similar to `expandString()`, but takes a file path and handles setting an option
557
557
  It's up to the caller to actually save the returned VFile object. The [to-vfile](https://www.npmjs.com/package/to-vfile) library can make this particularly painless:
558
558
 
559
559
  ```ts
560
- import { expandFile } from 'mdat'
560
+ import { expandFiles } from 'mdat'
561
561
  import { write } from 'to-vfile'
562
562
 
563
- const file = await expandFiles(...)
563
+ const [file] = await expandFiles('some-file.md')
564
564
  await write(file)
565
565
  ```
566
566
 
@@ -582,10 +582,10 @@ Like `expandFile()`, but accepts an array of inputs. If an output name is specif
582
582
 
583
583
  ```ts
584
584
  function loadConfig(options?: {
585
- additionalConfig?: ConfigToLoad // file paths or config objects
586
- additionalRules?: RulesToLoad // file paths or rule objects
585
+ additionalConfig?: ConfigToLoad // File paths or config objects
586
+ additionalRules?: RulesToLoad // File paths or rule objects
587
587
  searchFrom?: string
588
- }): Promise<ConfigLoaded> // returns a single merged config object
588
+ }): Promise<ConfigLoaded> // Returns a single merged config object
589
589
  ```
590
590
 
591
591
  This is provided for more advanced use cases. It assists in discovering and loading ambient configuration in your project (e.g. fields in your package.json, or dedicated `mdat` config files). It also dynamically loads, validates, and merges additional `mdat` configuration and rule files into a final `ConfigLoaded` object ready to be passed into the [`remark-mdat`](https://github.com/kitschpatrol/remark-mdat) plugin or one of the API functions like `expandFile()`.
@@ -634,12 +634,12 @@ The `mdat` configuration file is a record object allowing you to customize aspec
634
634
 
635
635
  ```ts
636
636
  type Config = {
637
- assetsPath?: string // where asset-generating rules should store their output, defaults to './assets'
638
- packageFile?: string // used by readme rules, found dynamically if undefined
639
- addMetaComment?: boolean // defaults to true
640
- closingPrefix?: string // defaults to '/'
641
- keywordPrefix?: string // defaults to ''
642
- metaCommentIdentifier?: string // defaults to '+'
637
+ addMetaComment?: boolean // Defaults to true
638
+ assetsPath?: string // Where asset-generating rules should store their output, defaults to './assets'
639
+ closingPrefix?: string // Defaults to '/'
640
+ keywordPrefix?: string // Defaults to ''
641
+ metaCommentIdentifier?: string // Defaults to '+'
642
+ packageFile?: string // Used by readme rules, found dynamically if undefined
643
643
  rules?: Rules
644
644
  }
645
645
  ```
@@ -660,12 +660,12 @@ Rules may also be defined in separate files that default-export a record of rule
660
660
  type Rules = Record<string, Rule>
661
661
 
662
662
  type Rule =
663
- | string
664
663
  | ((options: JsonValue, tree: Root) => Promise<string> | string)
665
664
  | Rule[]
665
+ | string
666
666
  | {
667
- content: string | Rule[] | ((options: JsonValue, tree: Root) => Promise<string> | string)
668
667
  applicationOrder?: number | undefined
668
+ content: ((options: JsonValue, tree: Root) => Promise<string> | string) | Rule[] | string
669
669
  order?: number | undefined
670
670
  required?: boolean | undefined
671
671
  }
@@ -745,8 +745,8 @@ See the [Examples section](https://github.com/kitschpatrol/remark-mdat#examples)
745
745
 
746
746
  | File | Original | Gzip | Brotli |
747
747
  | ------------ | -------- | ------- | ------ |
748
- | package.json | 2.6 kB | 1.2 kB | 1 kB |
749
- | readme.md | 57.4 kB | 11.4 kB | 9.1 kB |
748
+ | package.json | 2.7 kB | 1.2 kB | 1.1 kB |
749
+ | readme.md | 57.5 kB | 11.4 kB | 9.1 kB |
750
750
 
751
751
  <!-- /size-table -->
752
752