embedex 0.2.0 → 0.3.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/README.md +75 -44
- package/package.json +1 -1
- package/src/bin/cli.js +1 -1
- package/src/bin/cli.js.map +1 -1
- package/src/bin/processResult.js +1 -2
- package/src/bin/processResult.js.map +1 -1
- package/src/lib/internal/processTargets.js +47 -62
- package/src/lib/internal/processTargets.js.map +1 -1
- package/src/lib/types.d.ts +2 -5
- package/src/lib/internal/fileTypes.d.ts +0 -6
- package/src/lib/internal/fileTypes.js +0 -13
- package/src/lib/internal/fileTypes.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# embedex <!-- omit from toc -->
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
You can write code directly in TypeDoc comments using the [`@example` tag](https://typedoc.org/tags/example/), but keeping them up to date and guaranteed runnable is challenging since they aren't type-checked, linted, or tested.
|
|
6
|
-
|
|
7
|
-
While [`typedoc-plugin-include-example`](https://github.com/ferdodo/typedoc-plugin-include-example) embeds code into the resulting TypeDoc, the examples aren't in your code, so IDEs cannot show them on hover.
|
|
3
|
+
Embed shared text and code snippets from source files into destination files. For example, embed TypeScript examples into TypeDoc comments and your README.
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
`embedex` helps ensure a single source of truth while ensuring examples are up-to-date with the code they are documenting, runnable, linted, tested, and show on hover in IDEs.
|
|
10
6
|
|
|
11
7
|
## Table of contents <!-- omit from toc -->
|
|
12
8
|
|
|
@@ -31,50 +27,85 @@ npm install --global embedex
|
|
|
31
27
|
|
|
32
28
|
## Usage
|
|
33
29
|
|
|
34
|
-
1. Add
|
|
30
|
+
1. Add a source file to the `./examples` directory (configurable). The first line is a comma-separated list of destination file paths to embed the source's file contents into. `./examples/greeter.ts`:
|
|
35
31
|
|
|
36
32
|
```ts
|
|
37
|
-
// src/greeter.ts
|
|
33
|
+
// README.md,src/greeter.ts
|
|
38
34
|
import { greet } from "@my-scope/greeter";
|
|
39
35
|
|
|
40
36
|
greet("world");
|
|
41
37
|
```
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
39
|
+
2. In the destination file, add an `<embedex source="..."></embedex>` tag that includes the source file's path.
|
|
40
|
+
|
|
41
|
+
1. `./README.md`:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
# greeter
|
|
45
|
+
|
|
46
|
+
Greets a person by name.
|
|
47
|
+
|
|
48
|
+
<embedex source="examples/greeter.ts">
|
|
49
|
+
</embedex>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
2. `./src/greeter.ts`:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
/**
|
|
56
|
+
* Greets a person by name.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* <embedex source="examples/greeter.ts">
|
|
60
|
+
* </embedex>
|
|
61
|
+
*/
|
|
62
|
+
function greet(name: string) {
|
|
63
|
+
console.log(`Hello, ${name}!`);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
3. Run `npx embedex`.
|
|
68
|
+
4. The example is embedded! `./src/greeter.ts`:
|
|
69
|
+
|
|
70
|
+
1. `./README.md`:
|
|
71
|
+
|
|
72
|
+
````
|
|
73
|
+
# greeter
|
|
74
|
+
|
|
75
|
+
Greets a person by name.
|
|
76
|
+
|
|
77
|
+
<embedex source="examples/greeter.ts">
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { greet } from "@my-scope/greeter";
|
|
81
|
+
|
|
82
|
+
greet("world");
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
</embedex>
|
|
86
|
+
````
|
|
87
|
+
|
|
88
|
+
2. `./src/greeter.ts`:
|
|
89
|
+
|
|
90
|
+
````ts
|
|
91
|
+
/**
|
|
92
|
+
* Greets a person by name.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* <embedex source="examples/greeter.ts">
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { greet } from "@my-scope/greeter";
|
|
99
|
+
*
|
|
100
|
+
* greet("world");
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* </embedex>
|
|
104
|
+
*/
|
|
105
|
+
function greet(name: string) {
|
|
106
|
+
console.log(`Hello, ${name}!`);
|
|
107
|
+
}
|
|
108
|
+
````
|
|
78
109
|
|
|
79
110
|
## Reference
|
|
80
111
|
|
|
@@ -85,7 +116,7 @@ A command-line interface (CLI) that embeds examples into TypeDoc comments.
|
|
|
85
116
|
|
|
86
117
|
Options:
|
|
87
118
|
-V, --version output the version number
|
|
88
|
-
-e, --examplesGlob <pattern> examples glob pattern (default: "examples/**/*.ts")
|
|
119
|
+
-e, --examplesGlob <pattern> examples glob pattern (default: "examples/**/*.{md,ts}")
|
|
89
120
|
-c, --check verify if examples are correctly embedded without making changes,
|
|
90
121
|
exits with non-zero code if updates are needed; useful for CI/CD
|
|
91
122
|
pipelines (default: false)
|
package/package.json
CHANGED
package/src/bin/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ const program = new extra_typings_1.Command()
|
|
|
9
9
|
.name(package_json_1.name)
|
|
10
10
|
.description(package_json_1.description)
|
|
11
11
|
.version(String(package_json_1.version))
|
|
12
|
-
.addOption(new extra_typings_1.Option("-e, --examplesGlob <pattern>", "examples glob pattern").default("examples/**/*.ts"))
|
|
12
|
+
.addOption(new extra_typings_1.Option("-e, --examplesGlob <pattern>", "examples glob pattern").default("examples/**/*.{md,ts}"))
|
|
13
13
|
.addOption(new extra_typings_1.Option("-c, --check", "verify if examples are correctly embedded without making changes, exits with non-zero code if updates are needed; useful for CI/CD pipelines").default(false))
|
|
14
14
|
.addOption(new extra_typings_1.Option("-v, --verbose", "show verbose output").default(false));
|
|
15
15
|
program.parse();
|
package/src/bin/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/bin/cli.ts"],"names":[],"mappings":";;;AACA,+DAA8D;AAE9D,qDAAgE;AAChE,wCAAqC;AACrC,mDAAqD;AAErD,MAAM,OAAO,GAAG,IAAI,uBAAO,EAAE;KAC1B,IAAI,CAAC,mBAAI,CAAC;KACV,WAAW,CAAC,0BAAW,CAAC;KACxB,OAAO,CAAC,MAAM,CAAC,sBAAO,CAAC,CAAC;KACxB,SAAS,CACR,IAAI,sBAAM,CAAC,8BAA8B,EAAE,uBAAuB,CAAC,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/bin/cli.ts"],"names":[],"mappings":";;;AACA,+DAA8D;AAE9D,qDAAgE;AAChE,wCAAqC;AACrC,mDAAqD;AAErD,MAAM,OAAO,GAAG,IAAI,uBAAO,EAAE;KAC1B,IAAI,CAAC,mBAAI,CAAC;KACV,WAAW,CAAC,0BAAW,CAAC;KACxB,OAAO,CAAC,MAAM,CAAC,sBAAO,CAAC,CAAC;KACxB,SAAS,CACR,IAAI,sBAAM,CAAC,8BAA8B,EAAE,uBAAuB,CAAC,CAAC,OAAO,CACzE,uBAAuB,CACxB,CACF;KACA,SAAS,CACR,IAAI,sBAAM,CACR,aAAa,EACb,8IAA8I,CAC/I,CAAC,OAAO,CAAC,KAAK,CAAC,C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,IAAI,CAAC,CAAC,CAAC;IACvD,CAAC;AACH,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/src/bin/processResult.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processResult.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/bin/processResult.ts"],"names":[],"mappings":";;AAYA,kBAEC;AAED,
|
|
1
|
+
{"version":3,"file":"processResult.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/bin/processResult.ts"],"names":[],"mappings":";;AAYA,kBAEC;AAED,sCA6DC;;AA7ED,yCAAqD;AAErD,8EAAqC;AAUrC,SAAgB,GAAG,CAAC,GAAG,QAAkB;IACvC,OAAO,yBAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,SAAgB,aAAa,CAAC,MAK7B;IACC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAC/C,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAE7C,SAAS,QAAQ,CAAC,IAAY;QAC5B,OAAO,IAAA,oBAAY,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CACT,GAAG,CACD,eAAe,EACf,QAAQ;aACL,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,E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AAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;gBAC1C,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,cAAc,CAAC,MAAsD;IAC5E,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAEnC,OAAO,CAAC,EAAE,OAAO,EAAwB,EAAE,EAAE,CAAC,CAAC;QAC7C,IAAI;QACJ,OAAO;QACP,OAAO,EAAE,GAAG,yBAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,yBAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,yBAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE;KAC/F,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -2,24 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processTargets = processTargets;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const CONFIG_BY_FILE_EXTENSION = {
|
|
17
|
-
cts: TARGET_CONFIG.typeDoc,
|
|
18
|
-
md: TARGET_CONFIG.markdown,
|
|
19
|
-
mdx: TARGET_CONFIG.markdown,
|
|
20
|
-
mts: TARGET_CONFIG.typeDoc,
|
|
21
|
-
ts: TARGET_CONFIG.typeDoc,
|
|
22
|
-
tsx: TARGET_CONFIG.typeDoc,
|
|
5
|
+
const CODE_FENCE_ID_BY_FILE_EXTENSION = {
|
|
6
|
+
cjs: "js",
|
|
7
|
+
cts: "ts",
|
|
8
|
+
js: "js",
|
|
9
|
+
jsx: "js",
|
|
10
|
+
md: "",
|
|
11
|
+
mdx: "",
|
|
12
|
+
mjs: "js",
|
|
13
|
+
mts: "ts",
|
|
14
|
+
ts: "ts",
|
|
15
|
+
tsx: "ts",
|
|
23
16
|
};
|
|
24
17
|
function processTargets(params) {
|
|
25
18
|
const { targetMap, ...rest } = params;
|
|
@@ -35,66 +28,58 @@ function processTarget(params) {
|
|
|
35
28
|
function absolutePath(path) {
|
|
36
29
|
return (0, node_path_1.join)(cwd, path);
|
|
37
30
|
}
|
|
38
|
-
const
|
|
39
|
-
if (!(0, fileTypes_1.isSupportedFileExtension)(fileExtension)) {
|
|
40
|
-
return { code: "UNSUPPORTED", paths: { target, examples: [] } };
|
|
41
|
-
}
|
|
42
|
-
const targetConfig = CONFIG_BY_FILE_EXTENSION[fileExtension];
|
|
43
|
-
const matches = matchAll({
|
|
44
|
-
content,
|
|
45
|
-
exists: (example) => examples.has(absolutePath(example)),
|
|
46
|
-
targetConfig,
|
|
47
|
-
});
|
|
31
|
+
const matches = matchAll({ content, exists: (example) => examples.has(absolutePath(example)) });
|
|
48
32
|
if (matches.length === 0) {
|
|
49
33
|
return { code: "NO_MATCH", paths: { target, examples: [] } };
|
|
50
34
|
}
|
|
51
35
|
let updatedContent = content;
|
|
52
|
-
for (const { fullMatch,
|
|
53
|
-
const exampleContent = exampleMap.get(absolutePath(
|
|
54
|
-
|
|
55
|
-
const codeBlock = exampleContent.content.includes("```") ? "````" : "```";
|
|
56
|
-
const replacement = `${codeBlock}${language}\n${prefixLines({
|
|
57
|
-
content: [
|
|
58
|
-
`// ${example}`,
|
|
59
|
-
// Escape comment blocks
|
|
60
|
-
...exampleContent.content.replaceAll("*/", "*\\/").split("\n"),
|
|
61
|
-
codeBlock,
|
|
62
|
-
],
|
|
63
|
-
indent,
|
|
64
|
-
prefix: targetConfig.prefix,
|
|
65
|
-
})}`;
|
|
66
|
-
updatedContent = updatedContent.replaceAll(fullMatch, replacement);
|
|
36
|
+
for (const { fullMatch, prefix, examplePath } of matches) {
|
|
37
|
+
const exampleContent = exampleMap.get(absolutePath(examplePath));
|
|
38
|
+
updatedContent = updatedContent.replaceAll(fullMatch, createReplacement({ content: exampleContent.content, examplePath, prefix }));
|
|
67
39
|
}
|
|
68
|
-
const paths = { examples: matches.map((m) => absolutePath(m.
|
|
40
|
+
const paths = { examples: matches.map((m) => absolutePath(m.examplePath)), target };
|
|
69
41
|
return content === updatedContent
|
|
70
42
|
? { code: "NO_CHANGE", paths }
|
|
71
43
|
: { code: "UPDATE", paths, updatedContent };
|
|
72
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* A regex to match the embedex tag.
|
|
47
|
+
*
|
|
48
|
+
* Matching groups:
|
|
49
|
+
* 1. The block's prefix
|
|
50
|
+
* 2. The source file path
|
|
51
|
+
*/
|
|
52
|
+
const REGEX = /^(.*)<embedex source="(.+?)">\n[\S\s]*?<\/embedex>/gm;
|
|
73
53
|
function matchAll(params) {
|
|
74
|
-
const { content, exists
|
|
75
|
-
return [...content.matchAll(
|
|
54
|
+
const { content, exists } = params;
|
|
55
|
+
return [...content.matchAll(REGEX)]
|
|
76
56
|
.map((match) => {
|
|
77
|
-
const [fullMatch, ,
|
|
57
|
+
const [fullMatch, prefix, examplePath] = match;
|
|
78
58
|
return isDefined(fullMatch) &&
|
|
79
|
-
isDefined(
|
|
80
|
-
isDefined(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
? { fullMatch, language, indent, example }
|
|
59
|
+
isDefined(prefix) &&
|
|
60
|
+
isDefined(examplePath) &&
|
|
61
|
+
exists(examplePath)
|
|
62
|
+
? { fullMatch, prefix, examplePath }
|
|
84
63
|
: undefined;
|
|
85
64
|
})
|
|
86
65
|
.filter(isDefined);
|
|
87
66
|
}
|
|
88
|
-
function
|
|
89
|
-
const { content,
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
67
|
+
function createReplacement(params) {
|
|
68
|
+
const { content, examplePath, prefix } = params;
|
|
69
|
+
const contentHasCodeFence = content.includes("```");
|
|
70
|
+
const backticks = contentHasCodeFence ? "````" : "```";
|
|
71
|
+
const codeFenceId = CODE_FENCE_ID_BY_FILE_EXTENSION[(0, node_path_1.extname)(examplePath).slice(1)];
|
|
72
|
+
const escapedContent = content.replaceAll("*/", "*\\/").trimEnd().split("\n");
|
|
73
|
+
const lines = [
|
|
74
|
+
`<embedex source="${examplePath}">`,
|
|
75
|
+
"",
|
|
76
|
+
...(codeFenceId === ""
|
|
77
|
+
? escapedContent
|
|
78
|
+
: [`${backticks}${codeFenceId ?? ""}`, ...escapedContent, backticks]),
|
|
79
|
+
"",
|
|
80
|
+
"</embedex>",
|
|
81
|
+
];
|
|
82
|
+
return lines.map((line) => `${prefix}${line}`.trimEnd()).join("\n");
|
|
98
83
|
}
|
|
99
84
|
function isDefined(value) {
|
|
100
85
|
return value !== null && value !== undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processTargets.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/processTargets.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"processTargets.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/processTargets.ts"],"names":[],"mappings":";;AAkBA,wCAeC;AAjCD,yCAA0C;AAK1C,MAAM,+BAA+B,GAAqC;IACxE,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,EAAE;IACN,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,IAAI;IACR,GAAG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,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACvD,MAAM,WAAW,GAAG,+BAA+B,CAAC,IAAA,mBAAO,EAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACnF,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9E,MAAM,KAAK,GAAG;QACZ,oBAAoB,WAAW,IAAI;QACnC,EAAE;QACF,GAAG,CAAC,WAAW,KAAK,EAAE;YACpB,CAAC,CAAC,cAAc;YAChB,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,WAAW,IAAI,EAAE,EAAE,EAAE,GAAG,cAAc,EAAE,SAAS,CAAC,CAAC;QACvE,EAAE;QACF,YAAY;KACb,CAAC;IAEF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,SAAS,CAAI,KAAoB;IACxC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/C,CAAC"}
|
package/src/lib/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface EmbedParams {
|
|
|
5
5
|
examplesGlob: string;
|
|
6
6
|
write: boolean;
|
|
7
7
|
}
|
|
8
|
-
export type Code = "NO_CHANGE" | "NO_MATCH" | "
|
|
8
|
+
export type Code = "NO_CHANGE" | "NO_MATCH" | "UPDATE";
|
|
9
9
|
export interface Result {
|
|
10
10
|
code: Code;
|
|
11
11
|
paths: {
|
|
@@ -19,14 +19,11 @@ export type NoMatch = Result & {
|
|
|
19
19
|
export type NoChange = Result & {
|
|
20
20
|
code: "NO_CHANGE";
|
|
21
21
|
};
|
|
22
|
-
export type Unsupported = Result & {
|
|
23
|
-
code: "UNSUPPORTED";
|
|
24
|
-
};
|
|
25
22
|
export type Updated = Result & {
|
|
26
23
|
code: "UPDATE";
|
|
27
24
|
updatedContent: string;
|
|
28
25
|
};
|
|
29
|
-
export type Embed = NoMatch | Updated | NoChange
|
|
26
|
+
export type Embed = NoMatch | Updated | NoChange;
|
|
30
27
|
export interface EmbedResult {
|
|
31
28
|
embeds: Embed[];
|
|
32
29
|
examples: Array<{
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
declare const SUPPORTED_FILE_EXTENSIONS: readonly ["cts", "md", "mdx", "mts", "ts", "tsx"];
|
|
2
|
-
export type SupportedFileExtension = (typeof SUPPORTED_FILE_EXTENSIONS)[number];
|
|
3
|
-
type FileExtension = string;
|
|
4
|
-
export declare function getFileExtension(path: string): FileExtension;
|
|
5
|
-
export declare function isSupportedFileExtension(fileExtension: FileExtension): fileExtension is SupportedFileExtension;
|
|
6
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFileExtension = getFileExtension;
|
|
4
|
-
exports.isSupportedFileExtension = isSupportedFileExtension;
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const SUPPORTED_FILE_EXTENSIONS = ["cts", "md", "mdx", "mts", "ts", "tsx"];
|
|
7
|
-
function getFileExtension(path) {
|
|
8
|
-
return (0, node_path_1.extname)(path).slice(1);
|
|
9
|
-
}
|
|
10
|
-
function isSupportedFileExtension(fileExtension) {
|
|
11
|
-
return SUPPORTED_FILE_EXTENSIONS.includes(fileExtension);
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=fileTypes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fileTypes.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/fileTypes.ts"],"names":[],"mappings":";;AAOA,4CAEC;AAED,4DAIC;AAfD,yCAAoC;AAEpC,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAU,CAAC;AAKpF,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,OAAO,IAAA,mBAAO,EAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,SAAgB,wBAAwB,CACtC,aAA4B;IAE5B,OAAO,yBAAyB,CAAC,QAAQ,CAAC,aAAuC,CAAC,CAAC;AACrF,CAAC"}
|