mdat 0.9.0 → 1.0.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/bin/cli.js +124 -123
- package/dist/api.d.ts +20 -0
- package/dist/config.d.ts +11 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +69 -68
- package/dist/mdat-json-loader.d.ts +5 -0
- package/dist/processors.d.ts +4 -3
- package/dist/readme/api.d.ts +36 -0
- package/dist/readme/config.d.ts +5 -2
- package/dist/readme/init.d.ts +6 -4
- package/dist/readme/rules/utilities/cli-help/get-help-markdown.d.ts +3 -0
- package/dist/readme/rules/utilities/cli-help/help-object-to-markdown.d.ts +4 -0
- package/dist/readme/rules/utilities/cli-help/help-string-to-object.d.ts +8 -0
- package/dist/readme/rules/utilities/cli-help/parsers/index.d.ts +3 -0
- package/dist/readme/rules/utilities/cli-help/parsers/meow.d.ts +5 -0
- package/dist/readme/rules/utilities/cli-help/parsers/yargs.d.ts +5 -0
- package/dist/readme/templates/index.d.ts +0 -9
- package/dist/readme/utilities.d.ts +6 -1
- package/dist/utilities.d.ts +3 -6
- package/license.txt +1 -1
- package/package.json +42 -38
- package/readme.md +30 -21
|
@@ -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;
|
package/dist/processors.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type Root } from 'mdast';
|
|
2
2
|
import { VFile } from 'vfile';
|
|
3
3
|
import { type ConfigLoaded, type ConfigToLoad, type loadConfig, type RulesToLoad } from './config';
|
|
4
|
+
import { type AmbientRemarkConfig } from './utilities';
|
|
4
5
|
type Loader = typeof loadConfig;
|
|
5
6
|
type ProcessorGetter = typeof getCleanProcessor | typeof getExpandProcessor;
|
|
6
7
|
export declare function processFiles(files: string | string[], loader: Loader, processorGetter: ProcessorGetter, name?: string, output?: string, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile[]>;
|
|
7
8
|
export declare function processString(markdown: string, loader: Loader, processorGetter: ProcessorGetter, config?: ConfigToLoad, rules?: RulesToLoad): Promise<VFile>;
|
|
8
|
-
export declare function getExpandProcessor(options: ConfigLoaded): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
9
|
-
export declare function getCleanProcessor(options: ConfigLoaded): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
10
|
-
export declare function getCheckProcessor(options: ConfigLoaded): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
9
|
+
export declare function getExpandProcessor(options: ConfigLoaded, ambientRemarkConfig: AmbientRemarkConfig): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
10
|
+
export declare function getCleanProcessor(options: ConfigLoaded, ambientRemarkConfig: AmbientRemarkConfig): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
11
|
+
export declare function getCheckProcessor(options: ConfigLoaded, ambientRemarkConfig: AmbientRemarkConfig): import("unified").Processor<Root, undefined, undefined, Root, string>;
|
|
11
12
|
export {};
|
package/dist/readme/api.d.ts
CHANGED
|
@@ -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[]>;
|
package/dist/readme/config.d.ts
CHANGED
|
@@ -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
|
-
}
|
|
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 {};
|
package/dist/readme/init.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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>;
|
package/dist/utilities.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { type ConfigResult as AmbientRemarkConfig } from 'unified-engine';
|
|
2
|
+
export { type ConfigResult as AmbientRemarkConfig } from 'unified-engine';
|
|
1
3
|
export declare function getInputOutputPaths(inputs: string[], output: string | undefined, name: string | undefined, extension: string | undefined): Array<{
|
|
2
4
|
input: string;
|
|
3
5
|
name: string;
|
|
4
6
|
output: string;
|
|
5
7
|
}>;
|
|
6
|
-
export declare function getInputOutputPath(input: string, output: string | undefined, name: string | undefined, extension: string | undefined, nameSuffix?: string): {
|
|
7
|
-
input: string;
|
|
8
|
-
name: string;
|
|
9
|
-
output: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function expandPath(file: string): string;
|
|
12
8
|
export declare function findPackage(): Promise<string | undefined>;
|
|
13
9
|
export declare function ensureArray<T>(value: T | T[] | undefined): T[];
|
|
10
|
+
export declare function loadAmbientRemarkConfig(): Promise<AmbientRemarkConfig>;
|
package/license.txt
CHANGED
package/package.json
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdat",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "1.0.0",
|
|
5
4
|
"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
|
-
"
|
|
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": "https://github.com/kitschpatrol/mdat"
|
|
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
|
-
"
|
|
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.
|
|
42
|
-
"@kitschpatrol/tldraw-cli": "^4.6.
|
|
40
|
+
"@clack/prompts": "^0.10.0",
|
|
41
|
+
"@kitschpatrol/tldraw-cli": "^4.6.30",
|
|
43
42
|
"@types/mdast": "^4.0.4",
|
|
44
43
|
"@types/node": "18.19.0",
|
|
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
|
|
50
|
+
"globby": "^14.1.0",
|
|
51
51
|
"read-pkg": "^9.0.1",
|
|
52
|
-
"remark-mdat": "^0.
|
|
53
|
-
"type-fest": "^4.
|
|
52
|
+
"remark-mdat": "^1.0.1",
|
|
53
|
+
"type-fest": "^4.36.0",
|
|
54
|
+
"unified-engine": "^11.2.2",
|
|
54
55
|
"vfile": "^6.0.3",
|
|
55
56
|
"which": "^5.0.0"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"@kitschpatrol/shared-config": "^
|
|
59
|
-
"
|
|
60
|
-
"bumpp": "^9.10.1",
|
|
59
|
+
"@kitschpatrol/shared-config": "^5.0.6",
|
|
60
|
+
"bumpp": "^10.0.3",
|
|
61
61
|
"chalk": "^5.4.1",
|
|
62
62
|
"chevrotain": "^11.0.3",
|
|
63
63
|
"find-up": "^7.0.0",
|
|
64
64
|
"is-executable": "^2.0.1",
|
|
65
65
|
"mdast-util-toc": "^7.1.0",
|
|
66
|
-
"nanoid": "^5.
|
|
66
|
+
"nanoid": "^5.1.2",
|
|
67
67
|
"package-up": "^5.0.0",
|
|
68
68
|
"path-type": "^6.0.0",
|
|
69
69
|
"pkg-dir": "^8.0.0",
|
|
@@ -71,14 +71,18 @@
|
|
|
71
71
|
"pretty-bytes": "^6.1.1",
|
|
72
72
|
"pretty-ms": "^9.2.0",
|
|
73
73
|
"remark": "^15.0.1",
|
|
74
|
-
"remark-gfm": "^4.0.
|
|
74
|
+
"remark-gfm": "^4.0.1",
|
|
75
75
|
"to-vfile": "^8.0.0",
|
|
76
|
-
"tsup": "^8.
|
|
77
|
-
"typescript": "
|
|
76
|
+
"tsup": "^8.4.0",
|
|
77
|
+
"typescript": "~5.7.3",
|
|
78
78
|
"untildify": "^5.0.0",
|
|
79
|
-
"vitest": "^
|
|
79
|
+
"vitest": "^3.0.7",
|
|
80
80
|
"yargs": "^17.7.2",
|
|
81
|
-
"zod": "^3.24.
|
|
81
|
+
"zod": "^3.24.2"
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": "^18.19.0 || >=20.11.0",
|
|
85
|
+
"pnpm": ">=10.0.0"
|
|
82
86
|
},
|
|
83
87
|
"publishConfig": {
|
|
84
88
|
"access": "public"
|
|
@@ -87,8 +91,8 @@
|
|
|
87
91
|
"build": "tsup && tsc -p tsconfig.build.lib.json",
|
|
88
92
|
"clean": "git rm -f pnpm-lock.yaml ; git clean -fdX",
|
|
89
93
|
"dev": "pnpm run test",
|
|
90
|
-
"fix": "
|
|
91
|
-
"lint": "
|
|
94
|
+
"fix": "kpi fix",
|
|
95
|
+
"lint": "kpi lint",
|
|
92
96
|
"release": "bumpp --commit 'Release: %s' && pnpm run build && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
|
|
93
97
|
"test": "vitest --no-file-parallelism"
|
|
94
98
|
}
|
package/readme.md
CHANGED
|
@@ -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:
|
|
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,
|
|
@@ -216,7 +216,8 @@ As [noted below](#similar-projects), there are several similar projects out ther
|
|
|
216
216
|
|
|
217
217
|
## Usage
|
|
218
218
|
|
|
219
|
-
>
|
|
219
|
+
> [!WARNING]
|
|
220
|
+
>
|
|
220
221
|
> **The MDAT CLI tool directly manipulates the contents of readme files, in close (and perhaps dangerous) proximity to your painstakingly crafted words.**
|
|
221
222
|
>
|
|
222
223
|
> Please make sure any text you care about is committed before running `mdat`, and never directly modify content inside of the comment expansion blocks.
|
|
@@ -556,10 +557,10 @@ Similar to `expandString()`, but takes a file path and handles setting an option
|
|
|
556
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:
|
|
557
558
|
|
|
558
559
|
```ts
|
|
559
|
-
import {
|
|
560
|
+
import { expandFiles } from 'mdat'
|
|
560
561
|
import { write } from 'to-vfile'
|
|
561
562
|
|
|
562
|
-
const file = await expandFiles(
|
|
563
|
+
const [file] = await expandFiles('some-file.md')
|
|
563
564
|
await write(file)
|
|
564
565
|
```
|
|
565
566
|
|
|
@@ -581,10 +582,10 @@ Like `expandFile()`, but accepts an array of inputs. If an output name is specif
|
|
|
581
582
|
|
|
582
583
|
```ts
|
|
583
584
|
function loadConfig(options?: {
|
|
584
|
-
additionalConfig?: ConfigToLoad //
|
|
585
|
-
additionalRules?: RulesToLoad //
|
|
585
|
+
additionalConfig?: ConfigToLoad // File paths or config objects
|
|
586
|
+
additionalRules?: RulesToLoad // File paths or rule objects
|
|
586
587
|
searchFrom?: string
|
|
587
|
-
}): Promise<ConfigLoaded> //
|
|
588
|
+
}): Promise<ConfigLoaded> // Returns a single merged config object
|
|
588
589
|
```
|
|
589
590
|
|
|
590
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()`.
|
|
@@ -633,12 +634,12 @@ The `mdat` configuration file is a record object allowing you to customize aspec
|
|
|
633
634
|
|
|
634
635
|
```ts
|
|
635
636
|
type Config = {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
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
|
|
642
643
|
rules?: Rules
|
|
643
644
|
}
|
|
644
645
|
```
|
|
@@ -647,6 +648,10 @@ A valid configuration file default-exports an object conforming to the above typ
|
|
|
647
648
|
|
|
648
649
|
The configuration file may be located in any location supported by [cosmicconfig](https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#searchplaces). I use an `mdat.config.ts` file in the root of my projects.
|
|
649
650
|
|
|
651
|
+
> [!NOTE]
|
|
652
|
+
>
|
|
653
|
+
> The `mdat` commands _also_ search for and merge any ambient Remark `.remarkrc` configuration files you might have in your project. This is unrelated to the `mdat` rule configuration files, but it _can_ have an affect how Markdown is validated and rendered by `mdat`.
|
|
654
|
+
|
|
650
655
|
#### Rule file format
|
|
651
656
|
|
|
652
657
|
Rules may also be defined in separate files that default-export a record of rules. The record keys become the keywords used to reference a rule from your comments in Markdown.
|
|
@@ -655,12 +660,12 @@ Rules may also be defined in separate files that default-export a record of rule
|
|
|
655
660
|
type Rules = Record<string, Rule>
|
|
656
661
|
|
|
657
662
|
type Rule =
|
|
658
|
-
| string
|
|
659
663
|
| ((options: JsonValue, tree: Root) => Promise<string> | string)
|
|
660
664
|
| Rule[]
|
|
665
|
+
| string
|
|
661
666
|
| {
|
|
662
|
-
content: string | Rule[] | ((options: JsonValue, tree: Root) => Promise<string> | string)
|
|
663
667
|
applicationOrder?: number | undefined
|
|
668
|
+
content: ((options: JsonValue, tree: Root) => Promise<string> | string) | Rule[] | string
|
|
664
669
|
order?: number | undefined
|
|
665
670
|
required?: boolean | undefined
|
|
666
671
|
}
|
|
@@ -738,10 +743,10 @@ See the [Examples section](https://github.com/kitschpatrol/remark-mdat#examples)
|
|
|
738
743
|
|
|
739
744
|
<!-- size-table { files: ["package.json", "readme.md"] } -->
|
|
740
745
|
|
|
741
|
-
| File | Original | Gzip
|
|
742
|
-
| ------------ | -------- |
|
|
743
|
-
| package.json | 2.
|
|
744
|
-
| readme.md |
|
|
746
|
+
| File | Original | Gzip | Brotli |
|
|
747
|
+
| ------------ | -------- | ------- | ------ |
|
|
748
|
+
| package.json | 2.6 kB | 1.2 kB | 1 kB |
|
|
749
|
+
| readme.md | 57.4 kB | 11.4 kB | 9.1 kB |
|
|
745
750
|
|
|
746
751
|
<!-- /size-table -->
|
|
747
752
|
|
|
@@ -856,6 +861,10 @@ Recommended workflow integration approach:
|
|
|
856
861
|
|
|
857
862
|
- Invoke via hooks / GitHub actions?
|
|
858
863
|
|
|
864
|
+
Architectural improvements:
|
|
865
|
+
|
|
866
|
+
- Use [unified-engine](https://github.com/unifiedjs/unified-engine) to handle file loading and transformation.
|
|
867
|
+
|
|
859
868
|
## Maintainers
|
|
860
869
|
|
|
861
870
|
[@kitschpatrol](https://github.com/kitschpatrol)
|