embedex 0.3.0 → 0.3.2
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 +67 -64
- package/package.json +3 -2
- package/src/bin/cli.js +5 -5
- package/src/bin/cli.js.map +1 -1
- package/src/bin/processResult.js +11 -11
- package/src/bin/processResult.js.map +1 -1
- package/src/lib/embed.d.ts +1 -1
- package/src/lib/embed.js +13 -16
- package/src/lib/embed.js.map +1 -1
- package/src/lib/internal/createDestinationMap.d.ts +4 -0
- package/src/lib/internal/createDestinationMap.js +22 -0
- package/src/lib/internal/createDestinationMap.js.map +1 -0
- package/src/lib/internal/createSourceMap.d.ts +5 -0
- package/src/lib/internal/{createExampleMap.js → createSourceMap.js} +12 -12
- package/src/lib/internal/createSourceMap.js.map +1 -0
- package/src/lib/internal/processDestinations.d.ts +7 -0
- package/src/lib/internal/{processTargets.js → processDestinations.js} +22 -22
- package/src/lib/internal/processDestinations.js.map +1 -0
- package/src/lib/internal/types.d.ts +7 -7
- package/src/lib/types.d.ts +11 -11
- package/src/lib/internal/createExampleMap.d.ts +0 -5
- package/src/lib/internal/createExampleMap.js.map +0 -1
- package/src/lib/internal/createTargetMap.d.ts +0 -4
- package/src/lib/internal/createTargetMap.js +0 -22
- package/src/lib/internal/createTargetMap.js.map +0 -1
- package/src/lib/internal/processTargets.d.ts +0 -7
- package/src/lib/internal/processTargets.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
# embedex <!-- omit from toc -->
|
|
2
2
|
|
|
3
|
-
Embed shared text and code snippets from source files into destination files. For example
|
|
3
|
+
Embed shared text and code snippets from source files into destination files. For example:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- Embed TypeScript examples into TypeDoc comments and your README.
|
|
6
|
+
- Embed a Markdown snippet into multiple JSDoc comments.
|
|
7
|
+
|
|
8
|
+
`embedex` helps ensure a single source of truth while ensuring sources are up-to-date with the code they are documenting, runnable, linted, tested, and show on hover in IDEs.
|
|
6
9
|
|
|
7
10
|
## Table of contents <!-- omit from toc -->
|
|
8
11
|
|
|
9
12
|
- [Install](#install)
|
|
10
13
|
- [Usage](#usage)
|
|
11
|
-
- [
|
|
14
|
+
- [CLI reference](#cli-reference)
|
|
12
15
|
- [Local development commands](#local-development-commands)
|
|
13
16
|
|
|
14
17
|
## Install
|
|
@@ -38,90 +41,90 @@ npm install --global embedex
|
|
|
38
41
|
|
|
39
42
|
2. In the destination file, add an `<embedex source="..."></embedex>` tag that includes the source file's path.
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
- `./README.md`:
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
```
|
|
47
|
+
# greeter
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
Greets a person by name.
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
<embedex source="examples/greeter.ts">
|
|
52
|
+
</embedex>
|
|
53
|
+
```
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
- `./src/greeter.ts`:
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
```ts
|
|
58
|
+
/**
|
|
59
|
+
* Greets a person by name.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* <embedex source="examples/greeter.ts">
|
|
63
|
+
* </embedex>
|
|
64
|
+
*/
|
|
65
|
+
function greet(name: string) {
|
|
66
|
+
console.log(`Hello, ${name}!`);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
66
69
|
|
|
67
70
|
3. Run `npx embedex`.
|
|
68
|
-
4. The
|
|
71
|
+
4. The source is embedded!
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
- `./README.md`:
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
````
|
|
76
|
+
# greeter
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
Greets a person by name.
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
<embedex source="examples/greeter.ts">
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
```ts
|
|
83
|
+
import { greet } from "@my-scope/greeter";
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
greet("world");
|
|
86
|
+
```
|
|
84
87
|
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
</embedex>
|
|
89
|
+
````
|
|
87
90
|
|
|
88
|
-
|
|
91
|
+
- `./src/greeter.ts`:
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
93
|
+
````ts
|
|
94
|
+
/**
|
|
95
|
+
* Greets a person by name.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* <embedex source="examples/greeter.ts">
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { greet } from "@my-scope/greeter";
|
|
102
|
+
*
|
|
103
|
+
* greet("world");
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* </embedex>
|
|
107
|
+
*/
|
|
108
|
+
function greet(name: string) {
|
|
109
|
+
console.log(`Hello, ${name}!`);
|
|
110
|
+
}
|
|
111
|
+
````
|
|
109
112
|
|
|
110
|
-
##
|
|
113
|
+
## CLI reference
|
|
111
114
|
|
|
112
115
|
```
|
|
113
116
|
Usage: embedex [options]
|
|
114
117
|
|
|
115
|
-
|
|
118
|
+
Embed shared text and code snippets from source files into destination files.
|
|
116
119
|
|
|
117
120
|
Options:
|
|
118
|
-
-V, --version
|
|
119
|
-
-e, --
|
|
120
|
-
-c, --check
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
-v, --verbose
|
|
124
|
-
-h, --help
|
|
121
|
+
-V, --version output the version number
|
|
122
|
+
-e, --sourcesGlob <pattern> sources glob pattern (default: "examples/**/*.{md,ts}")
|
|
123
|
+
-c, --check verify if sources are correctly embedded without making changes,
|
|
124
|
+
exits with non-zero code if updates are needed; useful for CI/CD
|
|
125
|
+
pipelines (default: false)
|
|
126
|
+
-v, --verbose show verbose output (default: false)
|
|
127
|
+
-h, --help display help for command
|
|
125
128
|
```
|
|
126
129
|
|
|
127
130
|
## Local development commands
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "embedex",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.3.
|
|
3
|
+
"description": "Embed shared text and code snippets from source files into destination files.",
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"bin": {
|
|
6
6
|
"embedex": "./src/bin/cli.js"
|
|
7
7
|
},
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"documentation",
|
|
18
18
|
"embed",
|
|
19
19
|
"examples",
|
|
20
|
+
"snippets",
|
|
20
21
|
"typedoc",
|
|
21
22
|
"typescript"
|
|
22
23
|
],
|
package/src/bin/cli.js
CHANGED
|
@@ -9,20 +9,20 @@ 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, --
|
|
13
|
-
.addOption(new extra_typings_1.Option("-c, --check", "verify if
|
|
12
|
+
.addOption(new extra_typings_1.Option("-e, --sourcesGlob <pattern>", "sources glob pattern").default("examples/**/*.{md,ts}"))
|
|
13
|
+
.addOption(new extra_typings_1.Option("-c, --check", "verify if sources 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();
|
|
16
16
|
const options = program.opts();
|
|
17
|
-
const { check,
|
|
17
|
+
const { check, sourcesGlob, verbose } = options;
|
|
18
18
|
const cwd = process.cwd();
|
|
19
19
|
if (verbose) {
|
|
20
|
-
console.log((0, processResult_1.dim)("
|
|
20
|
+
console.log((0, processResult_1.dim)("sourcesGlob:\n ", sourcesGlob));
|
|
21
21
|
console.log((0, processResult_1.dim)("cwd:\n ", cwd));
|
|
22
22
|
}
|
|
23
23
|
(0, embed_1.embed)({
|
|
24
24
|
cwd,
|
|
25
|
-
|
|
25
|
+
sourcesGlob,
|
|
26
26
|
write: !check,
|
|
27
27
|
})
|
|
28
28
|
.then((result) => {
|
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,
|
|
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,6BAA6B,EAAE,s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AAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,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
|
@@ -10,25 +10,25 @@ function dim(...messages) {
|
|
|
10
10
|
}
|
|
11
11
|
function processResult(params) {
|
|
12
12
|
const { check, result, cwd, verbose } = params;
|
|
13
|
-
const { embeds,
|
|
13
|
+
const { embeds, sources, destinations } = result;
|
|
14
14
|
function relative(path) {
|
|
15
15
|
return (0, node_path_1.relative)(cwd, path);
|
|
16
16
|
}
|
|
17
|
+
function format(item) {
|
|
18
|
+
const items = "destinations" in item ? item.destinations : item.sources;
|
|
19
|
+
return `${relative(item.path)} -> ${items.map((item) => relative(item)).join(", ")}`;
|
|
20
|
+
}
|
|
17
21
|
if (verbose) {
|
|
18
|
-
console.log(dim("
|
|
19
|
-
|
|
20
|
-
.join("\n ")));
|
|
21
|
-
console.log(dim("targets:\n ", targets
|
|
22
|
-
.map(({ path, examples }) => `${relative(path)} -> ${examples.map(relative).join(", ")}`)
|
|
23
|
-
.join("\n ")));
|
|
22
|
+
console.log(dim("sources:\n ", sources.map(format).join("\n ")));
|
|
23
|
+
console.log(dim("destinations:\n ", destinations.map(format).join("\n ")));
|
|
24
24
|
}
|
|
25
25
|
const output = [];
|
|
26
26
|
for (const embed of embeds) {
|
|
27
27
|
const { code, paths } = embed;
|
|
28
|
-
const {
|
|
28
|
+
const { destination, sources } = paths;
|
|
29
29
|
const toOutput = createToOutput({
|
|
30
30
|
code,
|
|
31
|
-
paths: {
|
|
31
|
+
paths: { destination: relative(destination), sources: sources.map((path) => relative(path)) },
|
|
32
32
|
});
|
|
33
33
|
// eslint-disable-next-line default-case -- ignore so we get @typescript-eslint/switch-exhaustiveness-check
|
|
34
34
|
switch (code) {
|
|
@@ -50,11 +50,11 @@ function processResult(params) {
|
|
|
50
50
|
}
|
|
51
51
|
function createToOutput(params) {
|
|
52
52
|
const { code, paths } = params;
|
|
53
|
-
const {
|
|
53
|
+
const { destination, sources } = paths;
|
|
54
54
|
return ({ isError }) => ({
|
|
55
55
|
code,
|
|
56
56
|
isError,
|
|
57
|
-
message: `${yoctocolors_cjs_1.default.green(code)} ${yoctocolors_cjs_1.default.gray(
|
|
57
|
+
message: `${yoctocolors_cjs_1.default.green(code)} ${yoctocolors_cjs_1.default.gray(destination)} -> ${yoctocolors_cjs_1.default.gray(sources.join(", "))}`,
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
//# sourceMappingURL=processResult.js.map
|
|
@@ -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,sCAoDC;;AApED,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,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEjD,SAAS,QAAQ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});
|
|
3
3
|
exports.embed = embed;
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const createDestinationMap_1 = require("./internal/createDestinationMap");
|
|
6
|
+
const createSourceMap_1 = require("./internal/createSourceMap");
|
|
7
|
+
const processDestinations_1 = require("./internal/processDestinations");
|
|
8
8
|
/**
|
|
9
|
-
* Embed
|
|
9
|
+
* Embed sources into destinations.
|
|
10
10
|
*/
|
|
11
11
|
async function embed(params) {
|
|
12
|
-
const {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const embeds = (0,
|
|
12
|
+
const { sourcesGlob, cwd, write } = params;
|
|
13
|
+
const sourceMap = await (0, createSourceMap_1.createSourceMap)({ cwd, sourcesGlob });
|
|
14
|
+
const destinationMap = await (0, createDestinationMap_1.createDestinationMap)({ sourceMap });
|
|
15
|
+
const embeds = (0, processDestinations_1.processDestinations)({ cwd, sourceMap, destinationMap });
|
|
16
16
|
await Promise.all(embeds.map(async (embed) => {
|
|
17
17
|
if (write && embed.code === "UPDATE") {
|
|
18
|
-
await (0, promises_1.writeFile)(embed.paths.
|
|
18
|
+
await (0, promises_1.writeFile)(embed.paths.destination, embed.updatedContent);
|
|
19
19
|
}
|
|
20
20
|
}));
|
|
21
21
|
return {
|
|
22
22
|
embeds,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
targets: [...targetMap.entries()].map(([key, value]) => ({
|
|
28
|
-
path: key,
|
|
29
|
-
examples: [...value.examples],
|
|
23
|
+
sources: [...sourceMap.entries()].map(([path, { destinations }]) => ({ path, destinations })),
|
|
24
|
+
destinations: [...destinationMap.entries()].map(([path, { sources }]) => ({
|
|
25
|
+
path,
|
|
26
|
+
sources: [...sources],
|
|
30
27
|
})),
|
|
31
28
|
};
|
|
32
29
|
}
|
package/src/lib/embed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/lib/embed.ts"],"names":[],"mappings":";;AAUA,
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../../../../packages/embedex/src/lib/embed.ts"],"names":[],"mappings":";;AAUA,sBAuBC;AAjCD,+CAA6C;AAE7C,0EAAuE;AACvE,gEAA6D;AAC7D,wEAAqE;AAGrE;;GAEG;AACI,KAAK,UAAU,KAAK,CAAC,MAA6B;IACvD,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,SAAS,GAAG,MAAM,IAAA,iCAAe,EAAC,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9D,MAAM,cAAc,GAAG,MAAM,IAAA,2CAAoB,EAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAEjE,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,EAAE,GAAG,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,CAAC;IAEvE,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACzB,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,IAAA,oBAAS,EAAC,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;QACjE,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,MAAM;QACN,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QAC7F,YAAY,EAAE,CAAC,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACxE,IAAI;YACJ,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC;SACtB,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDestinationMap = createDestinationMap;
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
async function createDestinationMap(params) {
|
|
6
|
+
const { sourceMap } = params;
|
|
7
|
+
const uniqueDestinationPaths = new Set([...sourceMap.values()].flatMap(({ destinations }) => destinations));
|
|
8
|
+
const destinationContents = new Map();
|
|
9
|
+
await Promise.all([...uniqueDestinationPaths].map(async (path) => {
|
|
10
|
+
destinationContents.set(path, await (0, promises_1.readFile)(path, "utf8"));
|
|
11
|
+
}));
|
|
12
|
+
return new Map([...uniqueDestinationPaths].map((destinationPath) => [
|
|
13
|
+
destinationPath,
|
|
14
|
+
{
|
|
15
|
+
content: destinationContents.get(destinationPath),
|
|
16
|
+
sources: new Set([...sourceMap.entries()]
|
|
17
|
+
.filter(([_, { destinations }]) => destinations.includes(destinationPath))
|
|
18
|
+
.map(([sourcePath]) => sourcePath)),
|
|
19
|
+
},
|
|
20
|
+
]));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=createDestinationMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDestinationMap.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/createDestinationMap.ts"],"names":[],"mappings":";;AAKA,oDA4BC;AAjCD,+CAA4C;AAKrC,KAAK,UAAU,oBAAoB,CACxC,MAAoD;IAEpD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAE7B,MAAM,sBAAsB,GAAG,IAAI,GAAG,CACpC,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,CACpE,CAAC;IACF,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC/D,MAAM,OAAO,CAAC,GAAG,CACf,CAAC,GAAG,sBAAsB,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7C,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,IAAI,GAAG,CACZ,CAAC,GAAG,sBAAsB,CAAC,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC;QACnD,eAAe;QACf;YACE,OAAO,EAAE,mBAAmB,CAAC,GAAG,CAAC,eAAe,CAAE;YAClD,OAAO,EAAE,IAAI,GAAG,CACd,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;iBACrB,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;iBACzE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CACrC;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createSourceMap = createSourceMap;
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
6
|
const glob_1 = require("glob");
|
|
7
|
-
const
|
|
8
|
-
async function
|
|
9
|
-
const { cwd,
|
|
10
|
-
const
|
|
11
|
-
const paths = await (0, glob_1.glob)(
|
|
7
|
+
const SOURCE_MARKER_PREFIX = "// ";
|
|
8
|
+
async function createSourceMap(params) {
|
|
9
|
+
const { cwd, sourcesGlob } = params;
|
|
10
|
+
const sourceMap = new Map();
|
|
11
|
+
const paths = await (0, glob_1.glob)(sourcesGlob, { absolute: true, cwd, nodir: true });
|
|
12
12
|
for await (const path of paths) {
|
|
13
13
|
const content = await (0, promises_1.readFile)(path, "utf8");
|
|
14
14
|
const [first, ...rest] = content.split("\n");
|
|
15
|
-
if (first?.startsWith(
|
|
16
|
-
|
|
15
|
+
if (first?.startsWith(SOURCE_MARKER_PREFIX)) {
|
|
16
|
+
sourceMap.set(path, {
|
|
17
17
|
content: rest.join("\n"),
|
|
18
|
-
|
|
19
|
-
.replace(
|
|
18
|
+
destinations: first
|
|
19
|
+
.replace(SOURCE_MARKER_PREFIX, "")
|
|
20
20
|
.split(",")
|
|
21
21
|
.map((t) => (0, node_path_1.join)(cwd, t.trim())),
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return sourceMap;
|
|
26
26
|
}
|
|
27
|
-
//# sourceMappingURL=
|
|
27
|
+
//# sourceMappingURL=createSourceMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceMap.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/createSourceMap.ts"],"names":[],"mappings":";;AAUA,0CAsBC;AAhCD,+CAA4C;AAC5C,yCAAiC;AAEjC,+BAA4B;AAK5B,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAE5B,KAAK,UAAU,eAAe,CACnC,MAAsD;IAEtD,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;IAChD,MAAM,KAAK,GAAG,MAAM,IAAA,WAAI,EAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5E,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,KAAK,EAAE,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAC5C,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE;gBAClB,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBACxB,YAAY,EAAE,KAAK;qBAChB,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC;qBACjC,KAAK,CAAC,GAAG,CAAC;qBACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,gBAAI,EAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;aACnC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Embed } from "../types";
|
|
2
|
+
import { type DestinationMap, type SourceMap } from "./types";
|
|
3
|
+
export declare function processDestinations(params: Readonly<{
|
|
4
|
+
cwd: string;
|
|
5
|
+
sourceMap: Readonly<SourceMap>;
|
|
6
|
+
destinationMap: Readonly<DestinationMap>;
|
|
7
|
+
}>): Embed[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.processDestinations = processDestinations;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
const CODE_FENCE_ID_BY_FILE_EXTENSION = {
|
|
6
6
|
cjs: "js",
|
|
@@ -14,30 +14,30 @@ const CODE_FENCE_ID_BY_FILE_EXTENSION = {
|
|
|
14
14
|
ts: "ts",
|
|
15
15
|
tsx: "ts",
|
|
16
16
|
};
|
|
17
|
-
function
|
|
18
|
-
const {
|
|
17
|
+
function processDestinations(params) {
|
|
18
|
+
const { cwd, destinationMap, sourceMap } = params;
|
|
19
19
|
const result = [];
|
|
20
|
-
for (const entry of
|
|
21
|
-
result.push(
|
|
20
|
+
for (const entry of destinationMap.entries()) {
|
|
21
|
+
result.push(processDestination({ cwd, entry, sourceMap }));
|
|
22
22
|
}
|
|
23
23
|
return result;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
const { cwd,
|
|
27
|
-
const [
|
|
25
|
+
function processDestination(params) {
|
|
26
|
+
const { cwd, sourceMap, entry } = params;
|
|
27
|
+
const [destination, { content, sources }] = entry;
|
|
28
28
|
function absolutePath(path) {
|
|
29
29
|
return (0, node_path_1.join)(cwd, path);
|
|
30
30
|
}
|
|
31
|
-
const matches = matchAll({ content, exists: (
|
|
31
|
+
const matches = matchAll({ content, exists: (source) => sources.has(absolutePath(source)) });
|
|
32
32
|
if (matches.length === 0) {
|
|
33
|
-
return { code: "NO_MATCH", paths: {
|
|
33
|
+
return { code: "NO_MATCH", paths: { destination, sources: [] } };
|
|
34
34
|
}
|
|
35
35
|
let updatedContent = content;
|
|
36
|
-
for (const { fullMatch, prefix,
|
|
37
|
-
const
|
|
38
|
-
updatedContent = updatedContent.replaceAll(fullMatch, createReplacement({ content
|
|
36
|
+
for (const { fullMatch, prefix, sourcePath } of matches) {
|
|
37
|
+
const { content } = sourceMap.get(absolutePath(sourcePath));
|
|
38
|
+
updatedContent = updatedContent.replaceAll(fullMatch, createReplacement({ content, sourcePath, prefix }));
|
|
39
39
|
}
|
|
40
|
-
const paths = {
|
|
40
|
+
const paths = { sources: matches.map((m) => absolutePath(m.sourcePath)), destination };
|
|
41
41
|
return content === updatedContent
|
|
42
42
|
? { code: "NO_CHANGE", paths }
|
|
43
43
|
: { code: "UPDATE", paths, updatedContent };
|
|
@@ -54,24 +54,24 @@ function matchAll(params) {
|
|
|
54
54
|
const { content, exists } = params;
|
|
55
55
|
return [...content.matchAll(REGEX)]
|
|
56
56
|
.map((match) => {
|
|
57
|
-
const [fullMatch, prefix,
|
|
57
|
+
const [fullMatch, prefix, sourcePath] = match;
|
|
58
58
|
return isDefined(fullMatch) &&
|
|
59
59
|
isDefined(prefix) &&
|
|
60
|
-
isDefined(
|
|
61
|
-
exists(
|
|
62
|
-
? { fullMatch, prefix,
|
|
60
|
+
isDefined(sourcePath) &&
|
|
61
|
+
exists(sourcePath)
|
|
62
|
+
? { fullMatch, prefix, sourcePath }
|
|
63
63
|
: undefined;
|
|
64
64
|
})
|
|
65
65
|
.filter(isDefined);
|
|
66
66
|
}
|
|
67
67
|
function createReplacement(params) {
|
|
68
|
-
const { content,
|
|
68
|
+
const { content, sourcePath, prefix } = params;
|
|
69
69
|
const contentHasCodeFence = content.includes("```");
|
|
70
70
|
const backticks = contentHasCodeFence ? "````" : "```";
|
|
71
|
-
const codeFenceId = CODE_FENCE_ID_BY_FILE_EXTENSION[(0, node_path_1.extname)(
|
|
71
|
+
const codeFenceId = CODE_FENCE_ID_BY_FILE_EXTENSION[(0, node_path_1.extname)(sourcePath).slice(1)];
|
|
72
72
|
const escapedContent = content.replaceAll("*/", "*\\/").trimEnd().split("\n");
|
|
73
73
|
const lines = [
|
|
74
|
-
`<embedex source="${
|
|
74
|
+
`<embedex source="${sourcePath}">`,
|
|
75
75
|
"",
|
|
76
76
|
...(codeFenceId === ""
|
|
77
77
|
? escapedContent
|
|
@@ -84,4 +84,4 @@ function createReplacement(params) {
|
|
|
84
84
|
function isDefined(value) {
|
|
85
85
|
return value !== null && value !== undefined;
|
|
86
86
|
}
|
|
87
|
-
//# sourceMappingURL=
|
|
87
|
+
//# sourceMappingURL=processDestinations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processDestinations.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib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1,11 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export interface
|
|
1
|
+
import { type DestinationPath, type SourcePath } from "../types";
|
|
2
|
+
export interface Source {
|
|
3
3
|
content: string;
|
|
4
|
-
|
|
4
|
+
destinations: DestinationPath[];
|
|
5
5
|
}
|
|
6
|
-
export type
|
|
7
|
-
export interface
|
|
6
|
+
export type SourceMap = ReadonlyMap<SourcePath, Source>;
|
|
7
|
+
export interface Destination {
|
|
8
8
|
content: string;
|
|
9
|
-
|
|
9
|
+
sources: ReadonlySet<SourcePath>;
|
|
10
10
|
}
|
|
11
|
-
export type
|
|
11
|
+
export type DestinationMap = ReadonlyMap<DestinationPath, Destination>;
|
package/src/lib/types.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type
|
|
1
|
+
export type SourcePath = string;
|
|
2
|
+
export type DestinationPath = string;
|
|
3
3
|
export interface EmbedParams {
|
|
4
4
|
cwd: string;
|
|
5
|
-
|
|
5
|
+
sourcesGlob: string;
|
|
6
6
|
write: boolean;
|
|
7
7
|
}
|
|
8
8
|
export type Code = "NO_CHANGE" | "NO_MATCH" | "UPDATE";
|
|
9
9
|
export interface Result {
|
|
10
10
|
code: Code;
|
|
11
11
|
paths: {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
sources: SourcePath[];
|
|
13
|
+
destination: DestinationPath;
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
export type NoMatch = Result & {
|
|
@@ -26,12 +26,12 @@ export type Updated = Result & {
|
|
|
26
26
|
export type Embed = NoMatch | Updated | NoChange;
|
|
27
27
|
export interface EmbedResult {
|
|
28
28
|
embeds: Embed[];
|
|
29
|
-
|
|
30
|
-
path:
|
|
31
|
-
|
|
29
|
+
sources: Array<{
|
|
30
|
+
path: SourcePath;
|
|
31
|
+
destinations: DestinationPath[];
|
|
32
32
|
}>;
|
|
33
|
-
|
|
34
|
-
path:
|
|
35
|
-
|
|
33
|
+
destinations: Array<{
|
|
34
|
+
path: DestinationPath;
|
|
35
|
+
sources: SourcePath[];
|
|
36
36
|
}>;
|
|
37
37
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createExampleMap.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/createExampleMap.ts"],"names":[],"mappings":";;AAUA,4CAsBC;AAhCD,+CAA4C;AAC5C,yCAAiC;AAEjC,+BAA4B;AAK5B,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAE7B,KAAK,UAAU,gBAAgB,CACpC,MAAsD;IAEtD,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAwB,CAAC;IACnD,MAAM,KAAK,GAAG,MAAM,IAAA,WAAI,EAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5E,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,KAAK,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;YAC7C,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE;gBACnB,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBACxB,OAAO,EAAE,KAAK;qBACX,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC;qBAClC,KAAK,CAAC,GAAG,CAAC;qBACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,gBAAI,EAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;aACnC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTargetMap = createTargetMap;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
async function createTargetMap(params) {
|
|
6
|
-
const { exampleMap } = params;
|
|
7
|
-
const uniqueTargetPaths = new Set([...exampleMap.values()].flatMap(({ targets }) => targets));
|
|
8
|
-
const targetContents = new Map();
|
|
9
|
-
await Promise.all([...uniqueTargetPaths].map(async (path) => {
|
|
10
|
-
targetContents.set(path, await (0, promises_1.readFile)(path, "utf8"));
|
|
11
|
-
}));
|
|
12
|
-
return new Map([...uniqueTargetPaths].map((targetPath) => [
|
|
13
|
-
targetPath,
|
|
14
|
-
{
|
|
15
|
-
content: targetContents.get(targetPath),
|
|
16
|
-
examples: new Set([...exampleMap.entries()]
|
|
17
|
-
.filter(([_, { targets }]) => targets.includes(targetPath))
|
|
18
|
-
.map(([examplePath]) => examplePath)),
|
|
19
|
-
},
|
|
20
|
-
]));
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=createTargetMap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createTargetMap.js","sourceRoot":"","sources":["../../../../../../packages/embedex/src/lib/internal/createTargetMap.ts"],"names":[],"mappings":";;AAKA,0CA0BC;AA/BD,+CAA4C;AAKrC,KAAK,UAAU,eAAe,CACnC,MAAsD;IAEtD,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE9B,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9F,MAAM,cAAc,GAAG,IAAI,GAAG,EAAsB,CAAC;IACrD,MAAM,OAAO,CAAC,GAAG,CACf,CAAC,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACxC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACzD,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,IAAI,GAAG,CACZ,CAAC,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC;QACzC,UAAU;QACV;YACE,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAE;YACxC,QAAQ,EAAE,IAAI,GAAG,CACf,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;iBACtB,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;iBAC1D,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CACvC;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAE,IAAI;CACD,CAAC;AAEX,SAAgB,cAAc,CAC5B,MAIE;IAEF,MAAM,EAAE,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