@functional-examples/javascript 0.0.0-alpha.1 → 0.0.0-alpha.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 +76 -0
- package/README.md.template +51 -0
- package/dist/frontmatter.d.ts +4 -0
- package/dist/frontmatter.d.ts.map +1 -1
- package/dist/frontmatter.js +17 -0
- package/dist/frontmatter.js.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -34
- package/dist/index.js.map +1 -1
- package/dist/parser.d.ts +12 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +24 -8
- package/dist/parser.js.map +1 -1
- package/package.json +5 -4
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @functional-examples/javascript
|
|
2
|
+
|
|
3
|
+
JavaScript/TypeScript extractor plugin for functional-examples.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @functional-examples/javascript
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
This plugin adds JavaScript and TypeScript support to functional-examples:
|
|
14
|
+
|
|
15
|
+
- **YAML frontmatter extraction** from JS/TS files (comment-wrapped frontmatter)
|
|
16
|
+
- **Automatic dependency tree resolution** via `dependency-tree`
|
|
17
|
+
- **TypeScript-aware file matching** with configurable glob patterns
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { createJavaScriptPlugin } from '@functional-examples/javascript';
|
|
23
|
+
import type { Config } from 'functional-examples';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for the JavaScript plugin example.
|
|
27
|
+
*
|
|
28
|
+
* This example demonstrates:
|
|
29
|
+
* - Frontmatter metadata extraction (id, title, description, custom fields)
|
|
30
|
+
* - Region markers for code snippets (#region / #endregion)
|
|
31
|
+
*
|
|
32
|
+
* Plugin options (all optional):
|
|
33
|
+
* - skipFrontmatter: true - Disable frontmatter parsing
|
|
34
|
+
* - skipRegions: true - Disable region extraction
|
|
35
|
+
*/
|
|
36
|
+
const config: Config = {
|
|
37
|
+
plugins: [createJavaScriptPlugin()],
|
|
38
|
+
scan: {
|
|
39
|
+
include: ['**/*'],
|
|
40
|
+
exclude: ['**/node_modules/**', '**/dist/**'],
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default config;
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
### Frontmatter Extraction
|
|
51
|
+
|
|
52
|
+
The plugin detects YAML frontmatter in JS/TS comment blocks:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// ---
|
|
56
|
+
// title: My Example
|
|
57
|
+
// description: Demonstrates something useful
|
|
58
|
+
// tags: [typescript, async]
|
|
59
|
+
// ---
|
|
60
|
+
|
|
61
|
+
export async function main() {
|
|
62
|
+
console.log('Hello!');
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Dependency Resolution
|
|
67
|
+
|
|
68
|
+
When an entry point is specified, the plugin automatically resolves its dependency tree to discover related files.
|
|
69
|
+
|
|
70
|
+
### Path Mappings
|
|
71
|
+
|
|
72
|
+
Configure path mappings to handle TypeScript path aliases in your examples.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @functional-examples/javascript
|
|
2
|
+
|
|
3
|
+
JavaScript/TypeScript extractor plugin for functional-examples.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @functional-examples/javascript
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
This plugin adds JavaScript and TypeScript support to functional-examples:
|
|
14
|
+
|
|
15
|
+
- **YAML frontmatter extraction** from JS/TS files (comment-wrapped frontmatter)
|
|
16
|
+
- **Automatic dependency tree resolution** via `dependency-tree`
|
|
17
|
+
- **TypeScript-aware file matching** with configurable glob patterns
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
<%= example('javascript-plugin').file('functional-examples.config.ts') %>
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
### Frontmatter Extraction
|
|
26
|
+
|
|
27
|
+
The plugin detects YAML frontmatter in JS/TS comment blocks:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// ---
|
|
31
|
+
// title: My Example
|
|
32
|
+
// description: Demonstrates something useful
|
|
33
|
+
// tags: [typescript, async]
|
|
34
|
+
// ---
|
|
35
|
+
|
|
36
|
+
export async function main() {
|
|
37
|
+
console.log('Hello!');
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Dependency Resolution
|
|
42
|
+
|
|
43
|
+
When an entry point is specified, the plugin automatically resolves its dependency tree to discover related files.
|
|
44
|
+
|
|
45
|
+
### Path Mappings
|
|
46
|
+
|
|
47
|
+
Configure path mappings to handle TypeScript path aliases in your examples.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
package/dist/frontmatter.d.ts
CHANGED
|
@@ -4,14 +4,18 @@ import { type FileContentsParser } from '@functional-examples/devkit';
|
|
|
4
4
|
*
|
|
5
5
|
* Supports two formats:
|
|
6
6
|
* 1. Line comment style:
|
|
7
|
+
* ```javascript
|
|
7
8
|
* // ---
|
|
8
9
|
* // title: Example
|
|
9
10
|
* // ---
|
|
11
|
+
* ```
|
|
10
12
|
*
|
|
11
13
|
* 2. Block comment wrapped style:
|
|
14
|
+
* ```javascript
|
|
12
15
|
* /* ---
|
|
13
16
|
* title: Example
|
|
14
17
|
* --- *\/
|
|
18
|
+
* ```
|
|
15
19
|
*
|
|
16
20
|
* Frontmatter must be at the very start of the file (line 1).
|
|
17
21
|
* Extracted metadata is merged into context.metadata.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../src/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../src/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,6BAA6B,CAAC;AAuIrC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,IAAI,kBAAkB,CA6C5D"}
|
package/dist/frontmatter.js
CHANGED
|
@@ -51,9 +51,11 @@ async function extractLineCommentFrontmatter(lines) {
|
|
|
51
51
|
const metadata = yamlContent.trim()
|
|
52
52
|
? (await parseYaml(yamlContent)) ?? {}
|
|
53
53
|
: {};
|
|
54
|
+
const rawBlock = lines.slice(0, endIndex + 1).join('\n');
|
|
54
55
|
return {
|
|
55
56
|
metadata,
|
|
56
57
|
linesConsumed: endIndex + 1,
|
|
58
|
+
rawBlock,
|
|
57
59
|
};
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
@@ -91,9 +93,11 @@ async function extractBlockCommentFrontmatter(lines) {
|
|
|
91
93
|
const metadata = yamlContent.trim()
|
|
92
94
|
? (await parseYaml(yamlContent)) ?? {}
|
|
93
95
|
: {};
|
|
96
|
+
const rawBlock = lines.slice(0, endIndex + 1).join('\n');
|
|
94
97
|
return {
|
|
95
98
|
metadata,
|
|
96
99
|
linesConsumed: endIndex + 1,
|
|
100
|
+
rawBlock,
|
|
97
101
|
};
|
|
98
102
|
}
|
|
99
103
|
/**
|
|
@@ -101,14 +105,18 @@ async function extractBlockCommentFrontmatter(lines) {
|
|
|
101
105
|
*
|
|
102
106
|
* Supports two formats:
|
|
103
107
|
* 1. Line comment style:
|
|
108
|
+
* ```javascript
|
|
104
109
|
* // ---
|
|
105
110
|
* // title: Example
|
|
106
111
|
* // ---
|
|
112
|
+
* ```
|
|
107
113
|
*
|
|
108
114
|
* 2. Block comment wrapped style:
|
|
115
|
+
* ```javascript
|
|
109
116
|
* /* ---
|
|
110
117
|
* title: Example
|
|
111
118
|
* --- *\/
|
|
119
|
+
* ```
|
|
112
120
|
*
|
|
113
121
|
* Frontmatter must be at the very start of the file (line 1).
|
|
114
122
|
* Extracted metadata is merged into context.metadata.
|
|
@@ -134,10 +142,19 @@ export function createFrontmatterParser() {
|
|
|
134
142
|
...context.metadata,
|
|
135
143
|
...result.metadata,
|
|
136
144
|
};
|
|
145
|
+
// Emit a "frontmatter" hunk so docs can reference it via region('frontmatter')
|
|
146
|
+
const frontmatterHunk = {
|
|
147
|
+
id: 'frontmatter',
|
|
148
|
+
content: result.rawBlock,
|
|
149
|
+
startLine: 1,
|
|
150
|
+
endLine: result.linesConsumed,
|
|
151
|
+
};
|
|
152
|
+
const hunks = [frontmatterHunk];
|
|
137
153
|
return {
|
|
138
154
|
...context,
|
|
139
155
|
parsed,
|
|
140
156
|
metadata,
|
|
157
|
+
hunks,
|
|
141
158
|
};
|
|
142
159
|
},
|
|
143
160
|
};
|
package/dist/frontmatter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../src/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../src/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,GACV,MAAM,6BAA6B,CAAC;AAErC,8DAA8D;AAC9D,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,4DAA4D;AAC5D,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACjD,0DAA0D;AAC1D,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAEnD,+DAA+D;AAC/D,MAAM,mBAAmB,GAAG,uBAAu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AAe,CAAC,CAAC;YAEhC,OAAO;gBACL,GAAG,OAAO;gBACV,MAAM;gBACN,QAAQ;gBACR,KAAK;aACN,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from '@functional-examples/devkit';
|
|
2
|
-
|
|
3
|
-
export
|
|
2
|
+
import { type RegionTagConfig } from './parser.js';
|
|
3
|
+
export declare const JAVASCRIPT_EXTENSIONS: readonly [".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts", ".json"];
|
|
4
|
+
export { createJavaScriptParser, type RegionTagConfig } from './parser.js';
|
|
4
5
|
export { createFrontmatterParser } from './frontmatter.js';
|
|
5
6
|
export { createJavaScriptExtractor } from './extractor.js';
|
|
6
7
|
/**
|
|
@@ -11,6 +12,10 @@ export interface JavaScriptPluginOptions {
|
|
|
11
12
|
skipFrontmatter?: boolean;
|
|
12
13
|
/** Skip region extraction (default: false) */
|
|
13
14
|
skipRegions?: boolean;
|
|
15
|
+
/** Custom region tag markers (default: { start: '#region', end: '#endregion' }) */
|
|
16
|
+
regionTag?: RegionTagConfig;
|
|
17
|
+
/** Skip file extraction/discovery — only contribute parsing (default: false) */
|
|
18
|
+
skipExtraction?: boolean;
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* Create a JavaScript/TypeScript plugin for functional-examples.
|
|
@@ -21,8 +26,8 @@ export interface JavaScriptPluginOptions {
|
|
|
21
26
|
* - Extracts code regions from #region/#endregion markers
|
|
22
27
|
* - Provides a single-file extractor for discovering examples
|
|
23
28
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
29
|
+
* Parsers are listed in pipeline order: frontmatter first, then regions.
|
|
30
|
+
* The core's runParsePipeline handles hunk accumulation across parsers.
|
|
26
31
|
*
|
|
27
32
|
* @param options - Optional plugin configuration
|
|
28
33
|
* @returns A configured JavaScript plugin
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EAGP,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAI3E,eAAO,MAAM,qBAAqB,kFAUxB,CAAC;AAEX,OAAO,EAAE,sBAAsB,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,mDAAmD;IACnD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mFAAmF;IACnF,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,gFAAgF;IAChF,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAmED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,CA8BR"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export const JAVASCRIPT_EXTENSIONS = [
|
|
|
10
10
|
'.tsx',
|
|
11
11
|
'.mts',
|
|
12
12
|
'.cts',
|
|
13
|
+
'.json',
|
|
13
14
|
];
|
|
14
15
|
export { createJavaScriptParser } from './parser.js';
|
|
15
16
|
export { createFrontmatterParser } from './frontmatter.js';
|
|
@@ -28,28 +29,34 @@ const OPTIONS_SCHEMA = JSON.stringify({
|
|
|
28
29
|
type: 'boolean',
|
|
29
30
|
description: 'Skip region parsing',
|
|
30
31
|
},
|
|
32
|
+
regionTag: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
description: 'Custom region tag markers',
|
|
35
|
+
properties: {
|
|
36
|
+
start: { type: 'string' },
|
|
37
|
+
end: { type: 'string' },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
skipExtraction: {
|
|
41
|
+
type: 'boolean',
|
|
42
|
+
description: 'Skip file extraction/discovery',
|
|
43
|
+
},
|
|
31
44
|
},
|
|
32
45
|
});
|
|
33
46
|
/**
|
|
34
|
-
* JSON Schema for metadata
|
|
47
|
+
* JSON Schema for metadata fields contributed by the JavaScript plugin.
|
|
48
|
+
* Universal fields (id, title, description) are provided by the base schema;
|
|
49
|
+
* this plugin adds tags, which it validates at runtime.
|
|
35
50
|
*/
|
|
36
51
|
const METADATA_SCHEMA = JSON.stringify({
|
|
37
52
|
type: 'object',
|
|
38
53
|
properties: {
|
|
39
|
-
|
|
40
|
-
type: '
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
title: {
|
|
44
|
-
type: 'string',
|
|
45
|
-
description: 'Example title',
|
|
46
|
-
},
|
|
47
|
-
description: {
|
|
48
|
-
type: 'string',
|
|
49
|
-
description: 'Example description',
|
|
54
|
+
tags: {
|
|
55
|
+
type: 'array',
|
|
56
|
+
items: { type: 'string' },
|
|
57
|
+
description: 'Tags for categorizing the example',
|
|
50
58
|
},
|
|
51
59
|
},
|
|
52
|
-
required: ['id', 'title'],
|
|
53
60
|
});
|
|
54
61
|
/**
|
|
55
62
|
* Validate metadata extracted by this plugin.
|
|
@@ -78,35 +85,26 @@ function validateMetadata(metadata) {
|
|
|
78
85
|
* - Extracts code regions from #region/#endregion markers
|
|
79
86
|
* - Provides a single-file extractor for discovering examples
|
|
80
87
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
88
|
+
* Parsers are listed in pipeline order: frontmatter first, then regions.
|
|
89
|
+
* The core's runParsePipeline handles hunk accumulation across parsers.
|
|
83
90
|
*
|
|
84
91
|
* @param options - Optional plugin configuration
|
|
85
92
|
* @returns A configured JavaScript plugin
|
|
86
93
|
*/
|
|
87
94
|
export function createJavaScriptPlugin(options) {
|
|
88
|
-
const { skipFrontmatter = false, skipRegions = false } = options ?? {};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
result = await createFrontmatterParser().parse(result);
|
|
97
|
-
}
|
|
98
|
-
// Run region parser second (extracts hunks, strips markers)
|
|
99
|
-
if (!skipRegions) {
|
|
100
|
-
result = createJavaScriptParser().parse(result);
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
},
|
|
104
|
-
};
|
|
95
|
+
const { skipFrontmatter = false, skipRegions = false, regionTag, skipExtraction = false, } = options ?? {};
|
|
96
|
+
const parsers = [];
|
|
97
|
+
if (!skipFrontmatter) {
|
|
98
|
+
parsers.push(createFrontmatterParser());
|
|
99
|
+
}
|
|
100
|
+
if (!skipRegions) {
|
|
101
|
+
parsers.push(createJavaScriptParser(regionTag));
|
|
102
|
+
}
|
|
105
103
|
return {
|
|
106
104
|
name: 'javascript',
|
|
107
105
|
extensions: [...JAVASCRIPT_EXTENSIONS],
|
|
108
|
-
extractor: createJavaScriptExtractor(),
|
|
109
|
-
|
|
106
|
+
extractor: skipExtraction ? undefined : createJavaScriptExtractor(),
|
|
107
|
+
fileContentsParsers: parsers,
|
|
110
108
|
schemas: {
|
|
111
109
|
options: OPTIONS_SCHEMA,
|
|
112
110
|
metadata: METADATA_SCHEMA,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAwB,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAA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yBAAyB,EAAE;QACnE,mBAAmB,EAAE,OAAO;QAC5B,OAAO,EAAE;YACP,OAAO,EAAE,cAAc;YACvB,QAAQ,EAAE,eAAe;SAC1B;QACD,UAAU,EAAE;YACV,QAAQ,EAAE,gBAAgB;SAC3B;QACD,QAAQ,EAAE,OAAO;KAClB,CAAC;AACJ,CAAC"}
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import type { FileContentsParser } from '@functional-examples/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for custom region tag markers.
|
|
4
|
+
*/
|
|
5
|
+
export interface RegionTagConfig {
|
|
6
|
+
/** The start marker (default: '#region') */
|
|
7
|
+
start: string;
|
|
8
|
+
/** The end marker (default: '#endregion') */
|
|
9
|
+
end: string;
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* Create a FileContentsParser for JavaScript/TypeScript files.
|
|
4
13
|
* Handles region extraction and marker stripping.
|
|
14
|
+
*
|
|
15
|
+
* @param regionTag - Optional custom region tag markers
|
|
5
16
|
*/
|
|
6
|
-
export declare function createJavaScriptParser(): FileContentsParser;
|
|
17
|
+
export declare function createJavaScriptParser(regionTag?: RegionTagConfig): FileContentsParser;
|
|
7
18
|
//# sourceMappingURL=parser.d.ts.map
|
package/dist/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,6BAA6B,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,GAAG,EAAE,MAAM,CAAC;CACb;AA+BD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,CAAC,EAAE,eAAe,GAC1B,kBAAkB,CA6DpB"}
|
package/dist/parser.js
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const DEFAULT_REGION_TAG = {
|
|
2
|
+
start: '#region',
|
|
3
|
+
end: '#endregion',
|
|
4
|
+
};
|
|
5
|
+
function escapeRegex(str) {
|
|
6
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
7
|
+
}
|
|
8
|
+
function buildRegionRegexes(tag) {
|
|
9
|
+
const start = escapeRegex(tag.start);
|
|
10
|
+
const end = escapeRegex(tag.end);
|
|
11
|
+
return {
|
|
12
|
+
lineStart: new RegExp(`^[ \\t]*\\/\\/\\s*${start}\\s+(\\S+)\\s*$`),
|
|
13
|
+
lineEnd: new RegExp(`^[ \\t]*\\/\\/\\s*${end}(?:\\s+(\\S+))?\\s*$`),
|
|
14
|
+
blockStart: new RegExp(`^[ \\t]*\\/\\*\\s*${start}\\s+(\\S+)\\s*\\*\\/\\s*$`),
|
|
15
|
+
blockEnd: new RegExp(`^[ \\t]*\\/\\*\\s*${end}(?:\\s+(\\S+))?\\s*\\*\\/\\s*$`),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
5
18
|
/**
|
|
6
19
|
* Create a FileContentsParser for JavaScript/TypeScript files.
|
|
7
20
|
* Handles region extraction and marker stripping.
|
|
21
|
+
*
|
|
22
|
+
* @param regionTag - Optional custom region tag markers
|
|
8
23
|
*/
|
|
9
|
-
export function createJavaScriptParser() {
|
|
24
|
+
export function createJavaScriptParser(regionTag) {
|
|
25
|
+
const tag = regionTag ?? DEFAULT_REGION_TAG;
|
|
26
|
+
const regex = buildRegionRegexes(tag);
|
|
10
27
|
return {
|
|
11
28
|
name: 'javascript-parser',
|
|
12
29
|
parse(context) {
|
|
@@ -18,7 +35,7 @@ export function createJavaScriptParser() {
|
|
|
18
35
|
const line = lines[i];
|
|
19
36
|
const lineNum = i + 1;
|
|
20
37
|
// Check for region start
|
|
21
|
-
const startMatch = line.match(
|
|
38
|
+
const startMatch = line.match(regex.lineStart) || line.match(regex.blockStart);
|
|
22
39
|
if (startMatch) {
|
|
23
40
|
regionStack.push({
|
|
24
41
|
id: startMatch[1],
|
|
@@ -28,8 +45,7 @@ export function createJavaScriptParser() {
|
|
|
28
45
|
continue; // Don't include marker in output
|
|
29
46
|
}
|
|
30
47
|
// Check for region end
|
|
31
|
-
const endMatch = line.match(
|
|
32
|
-
line.match(BLOCK_COMMENT_ENDREGION);
|
|
48
|
+
const endMatch = line.match(regex.lineEnd) || line.match(regex.blockEnd);
|
|
33
49
|
if (endMatch) {
|
|
34
50
|
const current = regionStack.pop();
|
|
35
51
|
if (current) {
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAgBA,MAAM,kBAAkB,GAAoB;IAC1C,KAAK,EAAE,SAAS;IAChB,GAAG,EAAE,YAAY;CAClB,CAAC;AAEF,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAoB;IAC9C,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEjC,OAAO;QACL,SAAS,EAAE,IAAI,MAAM,CAAC,qBAAqB,KAAK,iBAAiB,CAAC;QAClE,OAAO,EAAE,IAAI,MAAM,CAAC,qBAAqB,GAAG,sBAAsB,C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O,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAE1D,IAAI,QAAQ,EAAE,CAAC;oBACb,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;oBAClC,IAAI,OAAO,EAAE,CAAC;wBACZ,KAAK,CAAC,IAAI,CAAC;4BACT,EAAE,EAAE,OAAO,CAAC,EAAE;4BACd,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;4BACjC,SAAS,EAAE,OAAO,CAAC,SAAS;4BAC5B,OAAO,EAAE,OAAO;yBACjB,CAAC,CAAC;oBACL,CAAC;oBACD,SAAS,CAAC,iCAAiC;gBAC7C,CAAC;gBAED,sDAAsD;gBACtD,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACvB,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC;oBACjC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC;YAED,OAAO;gBACL,GAAG,OAAO;gBACV,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC9B,KAAK;aACN,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@functional-examples/javascript",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.2",
|
|
4
4
|
"description": "JavaScript/TypeScript plugin for functional-examples",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"typescript": "^5.7.2",
|
|
23
23
|
"vitest": "^1.3.1",
|
|
24
|
-
"@functional-examples/devkit": "0.0.0-alpha.
|
|
24
|
+
"@functional-examples/devkit": "0.0.0-alpha.2"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"dependency-tree": "^11.0.0",
|
|
28
28
|
"picomatch": "^4.0.3",
|
|
29
29
|
"tinyglobby": "^0.2.15",
|
|
30
30
|
"yaml": "^2.7.1",
|
|
31
|
-
"@functional-examples/devkit": "0.0.0-alpha.
|
|
31
|
+
"@functional-examples/devkit": "0.0.0-alpha.2"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"author": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsc -p tsconfig.lib.json",
|
|
48
48
|
"test": "vitest run",
|
|
49
|
-
"test:watch": "vitest"
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"extract-docs": "typedoc --options typedoc.json"
|
|
50
51
|
}
|
|
51
52
|
}
|