@thi.ng/tangle 0.1.0 → 0.1.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.
- package/CHANGELOG.md +8 -1
- package/README.md +15 -4
- package/api.d.ts +22 -0
- package/package.json +2 -2
- package/tangle.d.ts +13 -2
- package/tangle.js +14 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-09-
|
|
3
|
+
- **Last updated**: 2022-09-22T10:09:17Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [0.1.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/tangle@0.1.1) (2022-09-22)
|
|
13
|
+
|
|
14
|
+
#### 🩹 Bug fixes
|
|
15
|
+
|
|
16
|
+
- in-memory rel path handling ([d184eb2](https://github.com/thi-ng/umbrella/commit/d184eb2))
|
|
17
|
+
- update test fixtures
|
|
18
|
+
|
|
12
19
|
## [0.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/tangle@0.1.0) (2022-09-21)
|
|
13
20
|
|
|
14
21
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -271,7 +271,11 @@ The published version of the input markdown file: `out/main.md`
|
|
|
271
271
|
|
|
272
272
|
### VSCode
|
|
273
273
|
|
|
274
|
-
Using the [Run On Save
|
|
274
|
+
Using the [Run On Save
|
|
275
|
+
extension](https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave),
|
|
276
|
+
tangling can be automatically performed on each save of an Literate Programming
|
|
277
|
+
source file. E.g. this configuration (add to your VSCode workspace
|
|
278
|
+
`settings.json`) runs the tangle command on each save of a `*.lit.md` file.
|
|
275
279
|
|
|
276
280
|
```json
|
|
277
281
|
"emeraldwalk.runonsave": {
|
|
@@ -284,7 +288,8 @@ Using the [Run On Save extension](https://marketplace.visualstudio.com/items?ite
|
|
|
284
288
|
}
|
|
285
289
|
```
|
|
286
290
|
|
|
287
|
-
Note: This also assumes you have this package (@thi.ng/tangle) added to your
|
|
291
|
+
Note: This also assumes you have this package (@thi.ng/tangle) added to your
|
|
292
|
+
dependencies...
|
|
288
293
|
|
|
289
294
|
### Other editors
|
|
290
295
|
|
|
@@ -319,7 +324,7 @@ node --experimental-repl-await
|
|
|
319
324
|
> const tangle = await import("@thi.ng/tangle");
|
|
320
325
|
```
|
|
321
326
|
|
|
322
|
-
Package sizes (gzipped, pre-treeshake): ESM: 1.
|
|
327
|
+
Package sizes (gzipped, pre-treeshake): ESM: 1.97 KB
|
|
323
328
|
|
|
324
329
|
## Dependencies
|
|
325
330
|
|
|
@@ -338,7 +343,13 @@ Package sizes (gzipped, pre-treeshake): ESM: 1.96 KB
|
|
|
338
343
|
|
|
339
344
|
[Generated API docs](https://docs.thi.ng/umbrella/tangle/)
|
|
340
345
|
|
|
341
|
-
|
|
346
|
+
In addition to the CLI wrapper, the package provides the
|
|
347
|
+
[`tangleFile()`](https://docs.thi.ng/umbrella/tangle/modules.html#tangleFile)
|
|
348
|
+
and
|
|
349
|
+
[`tangleString()`](https://docs.thi.ng/umbrella/tangle/modules.html#tangleString)
|
|
350
|
+
functions. See
|
|
351
|
+
[/test/index.ts](https://github.com/thi-ng/umbrella/blob/develop/packages/tangle/test/index.ts)
|
|
352
|
+
for usage examples.
|
|
342
353
|
|
|
343
354
|
## Authors
|
|
344
355
|
|
package/api.d.ts
CHANGED
|
@@ -21,11 +21,33 @@ export interface TangleRef {
|
|
|
21
21
|
}
|
|
22
22
|
export declare type Blocks = Record<string, Block>;
|
|
23
23
|
export interface TangleCtx {
|
|
24
|
+
/**
|
|
25
|
+
* Code block marker definitions for current source file format. If not
|
|
26
|
+
* pre-defined, then {@link tangleFile} will auto-detect the format based on
|
|
27
|
+
* given file extension. See {@link BLOCK_FORMATS} for supported source
|
|
28
|
+
* formats.
|
|
29
|
+
*/
|
|
24
30
|
format: CodeBlockFormat;
|
|
31
|
+
/**
|
|
32
|
+
* Stores all referenced source files and their extracted code blocks.
|
|
33
|
+
*/
|
|
25
34
|
files: Record<string, TangleRef>;
|
|
35
|
+
/**
|
|
36
|
+
* Stores all generated outputs (absolute file paths are used as keys)
|
|
37
|
+
*/
|
|
26
38
|
outputs: Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* Logger for debug outputs
|
|
41
|
+
*/
|
|
27
42
|
logger: ILogger;
|
|
43
|
+
/**
|
|
44
|
+
* "Filesystem" implementation. When using {@link tangleString}, in-memory
|
|
45
|
+
* stubs will be used to obtain file contents from a given object.
|
|
46
|
+
*/
|
|
28
47
|
fs: FileSystem;
|
|
48
|
+
/**
|
|
49
|
+
* Tangle & codegen options
|
|
50
|
+
*/
|
|
29
51
|
opts: Partial<TangleOpts>;
|
|
30
52
|
}
|
|
31
53
|
export interface FileSystem {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/tangle",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Literate programming code block tangling / codegen utility, inspired by org-mode & noweb",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"status": "alpha",
|
|
92
92
|
"year": 2022
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "84d9d694065457d30eafc3556f93a307b78b20fb\n"
|
|
95
95
|
}
|
package/tangle.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { IObjectOf } from "@thi.ng/api";
|
|
2
2
|
import { TangleCtx } from "./api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Takes a file `path` and partial {@link TangleCtx}. Reads "file"
|
|
5
|
+
* (implementation specific, could be from memory or other source) and then
|
|
6
|
+
* performs all tangling steps on the document body, i.e. expanding &
|
|
7
|
+
* transcluding code blocks, generating outputs for various target files etc.
|
|
8
|
+
* Returns updated TangleCtx with all generated outputs stored under the
|
|
9
|
+
* {@link TangleCtx.outputs} key.
|
|
10
|
+
*
|
|
11
|
+
* @param path
|
|
12
|
+
* @param ctx
|
|
13
|
+
*/
|
|
3
14
|
export declare const tangleFile: (path: string, ctx?: Partial<TangleCtx>) => TangleCtx;
|
|
4
15
|
/**
|
|
5
16
|
* In-memory version of {@link tangleFile}. Take a file name and an object of
|
|
@@ -8,8 +19,8 @@ export declare const tangleFile: (path: string, ctx?: Partial<TangleCtx>) => Tan
|
|
|
8
19
|
* virtual "file system" (of sorts).
|
|
9
20
|
*
|
|
10
21
|
* @remarks
|
|
11
|
-
*
|
|
12
|
-
* `../foo/bar.md` is NOT supported.
|
|
22
|
+
* Relative file reference paths are only supported if they refer to children or
|
|
23
|
+
* siblings, i.e. `foo/bar.md` is okay, but `../foo/bar.md` is NOT supported.
|
|
13
24
|
*
|
|
14
25
|
* @param fileID
|
|
15
26
|
* @param files
|
package/tangle.js
CHANGED
|
@@ -114,6 +114,17 @@ const loadAndResolveBlocks = (path, ctx) => {
|
|
|
114
114
|
}
|
|
115
115
|
return ctx.files[path];
|
|
116
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Takes a file `path` and partial {@link TangleCtx}. Reads "file"
|
|
119
|
+
* (implementation specific, could be from memory or other source) and then
|
|
120
|
+
* performs all tangling steps on the document body, i.e. expanding &
|
|
121
|
+
* transcluding code blocks, generating outputs for various target files etc.
|
|
122
|
+
* Returns updated TangleCtx with all generated outputs stored under the
|
|
123
|
+
* {@link TangleCtx.outputs} key.
|
|
124
|
+
*
|
|
125
|
+
* @param path
|
|
126
|
+
* @param ctx
|
|
127
|
+
*/
|
|
117
128
|
export const tangleFile = (path, ctx = {}) => {
|
|
118
129
|
const fmt = ctx.format || BLOCK_FORMATS[extname(path)];
|
|
119
130
|
!fmt && illegalArgs(`unsupported file type: ${extname(path)}`);
|
|
@@ -182,8 +193,8 @@ export const tangleFile = (path, ctx = {}) => {
|
|
|
182
193
|
* virtual "file system" (of sorts).
|
|
183
194
|
*
|
|
184
195
|
* @remarks
|
|
185
|
-
*
|
|
186
|
-
* `../foo/bar.md` is NOT supported.
|
|
196
|
+
* Relative file reference paths are only supported if they refer to children or
|
|
197
|
+
* siblings, i.e. `foo/bar.md` is okay, but `../foo/bar.md` is NOT supported.
|
|
187
198
|
*
|
|
188
199
|
* @param fileID
|
|
189
200
|
* @param files
|
|
@@ -191,7 +202,7 @@ export const tangleFile = (path, ctx = {}) => {
|
|
|
191
202
|
*/
|
|
192
203
|
export const tangleString = (fileID, files, ctx = {}) => tangleFile(fileID, {
|
|
193
204
|
fs: {
|
|
194
|
-
isAbsolute: () =>
|
|
205
|
+
isAbsolute: (path) => path[0] === "/" || path[0] === "\\",
|
|
195
206
|
resolve: (...path) => path[path.length - 1],
|
|
196
207
|
read: (path, logger) => {
|
|
197
208
|
logger.debug("reading file ref", path);
|