@vibe-agent-toolkit/resource-compiler 0.1.11
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 +449 -0
- package/bin/vat-compile-resources +8 -0
- package/dist/cli/compile-command.d.ts +11 -0
- package/dist/cli/compile-command.d.ts.map +1 -0
- package/dist/cli/compile-command.js +34 -0
- package/dist/cli/compile-command.js.map +1 -0
- package/dist/cli/compile-utils.d.ts +41 -0
- package/dist/cli/compile-utils.d.ts.map +1 -0
- package/dist/cli/compile-utils.js +51 -0
- package/dist/cli/compile-utils.js.map +1 -0
- package/dist/cli/generate-types-command.d.ts +11 -0
- package/dist/cli/generate-types-command.d.ts.map +1 -0
- package/dist/cli/generate-types-command.js +107 -0
- package/dist/cli/generate-types-command.js.map +1 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +34 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/watch-command.d.ts +11 -0
- package/dist/cli/watch-command.d.ts.map +1 -0
- package/dist/cli/watch-command.js +88 -0
- package/dist/cli/watch-command.js.map +1 -0
- package/dist/compiler/dts-generator.d.ts +29 -0
- package/dist/compiler/dts-generator.d.ts.map +1 -0
- package/dist/compiler/dts-generator.js +133 -0
- package/dist/compiler/dts-generator.js.map +1 -0
- package/dist/compiler/index.d.ts +9 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +9 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/javascript-generator.d.ts +22 -0
- package/dist/compiler/javascript-generator.d.ts.map +1 -0
- package/dist/compiler/javascript-generator.js +106 -0
- package/dist/compiler/javascript-generator.js.map +1 -0
- package/dist/compiler/markdown-compiler.d.ts +30 -0
- package/dist/compiler/markdown-compiler.d.ts.map +1 -0
- package/dist/compiler/markdown-compiler.js +125 -0
- package/dist/compiler/markdown-compiler.js.map +1 -0
- package/dist/compiler/markdown-parser.d.ts +32 -0
- package/dist/compiler/markdown-parser.d.ts.map +1 -0
- package/dist/compiler/markdown-parser.js +126 -0
- package/dist/compiler/markdown-parser.js.map +1 -0
- package/dist/compiler/types.d.ts +71 -0
- package/dist/compiler/types.d.ts.map +1 -0
- package/dist/compiler/types.js +5 -0
- package/dist/compiler/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/language-service/completions.d.ts +27 -0
- package/dist/language-service/completions.d.ts.map +1 -0
- package/dist/language-service/completions.js +147 -0
- package/dist/language-service/completions.js.map +1 -0
- package/dist/language-service/definitions.d.ts +14 -0
- package/dist/language-service/definitions.d.ts.map +1 -0
- package/dist/language-service/definitions.js +140 -0
- package/dist/language-service/definitions.js.map +1 -0
- package/dist/language-service/diagnostics.d.ts +13 -0
- package/dist/language-service/diagnostics.d.ts.map +1 -0
- package/dist/language-service/diagnostics.js +169 -0
- package/dist/language-service/diagnostics.js.map +1 -0
- package/dist/language-service/hover.d.ts +15 -0
- package/dist/language-service/hover.d.ts.map +1 -0
- package/dist/language-service/hover.js +125 -0
- package/dist/language-service/hover.js.map +1 -0
- package/dist/language-service/index.d.ts +26 -0
- package/dist/language-service/index.d.ts.map +1 -0
- package/dist/language-service/index.js +30 -0
- package/dist/language-service/index.js.map +1 -0
- package/dist/language-service/markdown-cache.d.ts +44 -0
- package/dist/language-service/markdown-cache.d.ts.map +1 -0
- package/dist/language-service/markdown-cache.js +77 -0
- package/dist/language-service/markdown-cache.js.map +1 -0
- package/dist/language-service/plugin.d.ts +15 -0
- package/dist/language-service/plugin.d.ts.map +1 -0
- package/dist/language-service/plugin.js +51 -0
- package/dist/language-service/plugin.js.map +1 -0
- package/dist/language-service/utils.d.ts +173 -0
- package/dist/language-service/utils.d.ts.map +1 -0
- package/dist/language-service/utils.js +341 -0
- package/dist/language-service/utils.js.map +1 -0
- package/dist/transformer/ast-helpers.d.ts +35 -0
- package/dist/transformer/ast-helpers.d.ts.map +1 -0
- package/dist/transformer/ast-helpers.js +153 -0
- package/dist/transformer/ast-helpers.js.map +1 -0
- package/dist/transformer/declaration-generator.d.ts +47 -0
- package/dist/transformer/declaration-generator.d.ts.map +1 -0
- package/dist/transformer/declaration-generator.js +53 -0
- package/dist/transformer/declaration-generator.js.map +1 -0
- package/dist/transformer/import-detector.d.ts +62 -0
- package/dist/transformer/import-detector.d.ts.map +1 -0
- package/dist/transformer/import-detector.js +115 -0
- package/dist/transformer/import-detector.js.map +1 -0
- package/dist/transformer/index.d.ts +11 -0
- package/dist/transformer/index.d.ts.map +1 -0
- package/dist/transformer/index.js +11 -0
- package/dist/transformer/index.js.map +1 -0
- package/dist/transformer/module-generator.d.ts +29 -0
- package/dist/transformer/module-generator.d.ts.map +1 -0
- package/dist/transformer/module-generator.js +48 -0
- package/dist/transformer/module-generator.js.map +1 -0
- package/dist/transformer/path-resolver.d.ts +32 -0
- package/dist/transformer/path-resolver.d.ts.map +1 -0
- package/dist/transformer/path-resolver.js +112 -0
- package/dist/transformer/path-resolver.js.map +1 -0
- package/dist/transformer/transformer.d.ts +46 -0
- package/dist/transformer/transformer.d.ts.map +1 -0
- package/dist/transformer/transformer.js +89 -0
- package/dist/transformer/transformer.js.map +1 -0
- package/dist/utils/copy-resources.d.ts +54 -0
- package/dist/utils/copy-resources.d.ts.map +1 -0
- package/dist/utils/copy-resources.js +77 -0
- package/dist/utils/copy-resources.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI generate-types command implementation
|
|
3
|
+
*/
|
|
4
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- CLI tool with user-provided paths */
|
|
5
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { relative } from 'node:path';
|
|
7
|
+
import { glob } from 'glob';
|
|
8
|
+
import { parseMarkdown } from '../compiler/markdown-parser.js';
|
|
9
|
+
import { generateMarkdownDeclarationFile, getDeclarationPath } from '../transformer/declaration-generator.js';
|
|
10
|
+
import { exitWithResults, printOperationSummary } from './compile-utils.js';
|
|
11
|
+
/**
|
|
12
|
+
* Process a single markdown file and generate its declaration
|
|
13
|
+
*
|
|
14
|
+
* @param filePath - Path to markdown file
|
|
15
|
+
* @param inputDir - Base input directory
|
|
16
|
+
* @param verbose - Enable verbose logging
|
|
17
|
+
* @returns Generation result
|
|
18
|
+
*/
|
|
19
|
+
function processMarkdownFile(filePath, inputDir, verbose) {
|
|
20
|
+
try {
|
|
21
|
+
if (verbose) {
|
|
22
|
+
const relativePath = relative(inputDir, filePath);
|
|
23
|
+
console.log(`Processing: ${relativePath}`);
|
|
24
|
+
}
|
|
25
|
+
// Read and parse markdown
|
|
26
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
27
|
+
const resource = parseMarkdown(content);
|
|
28
|
+
// Generate declaration
|
|
29
|
+
const declaration = generateMarkdownDeclarationFile(filePath, resource);
|
|
30
|
+
const declarationPath = getDeclarationPath(filePath);
|
|
31
|
+
// Write declaration file
|
|
32
|
+
writeFileSync(declarationPath, declaration, 'utf-8');
|
|
33
|
+
if (verbose) {
|
|
34
|
+
const relativeDeclarationPath = relative(inputDir, declarationPath);
|
|
35
|
+
console.log(` Generated: ${relativeDeclarationPath}`);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
sourcePath: filePath,
|
|
39
|
+
declarationPath,
|
|
40
|
+
success: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (verbose) {
|
|
45
|
+
console.error(` Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
sourcePath: filePath,
|
|
49
|
+
declarationPath: getDeclarationPath(filePath),
|
|
50
|
+
success: false,
|
|
51
|
+
error: error instanceof Error ? error.message : String(error),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generate .md.d.ts files for all markdown files in a directory
|
|
57
|
+
*
|
|
58
|
+
* @param inputDir - Directory to search for markdown files
|
|
59
|
+
* @param pattern - Glob pattern for matching markdown files
|
|
60
|
+
* @param verbose - Enable verbose logging
|
|
61
|
+
* @returns Array of generation results
|
|
62
|
+
*/
|
|
63
|
+
async function generateTypes(inputDir, pattern, verbose) {
|
|
64
|
+
// Find all markdown files
|
|
65
|
+
const files = await glob(pattern, {
|
|
66
|
+
cwd: inputDir,
|
|
67
|
+
absolute: true,
|
|
68
|
+
nodir: true,
|
|
69
|
+
});
|
|
70
|
+
if (verbose) {
|
|
71
|
+
console.log(`Found ${files.length} markdown files`);
|
|
72
|
+
}
|
|
73
|
+
// Process each file
|
|
74
|
+
return files.map((filePath) => processMarkdownFile(filePath, inputDir, verbose));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Register the generate-types command with Commander
|
|
78
|
+
*
|
|
79
|
+
* @param program - Commander program instance
|
|
80
|
+
*/
|
|
81
|
+
export function registerGenerateTypesCommand(program) {
|
|
82
|
+
program
|
|
83
|
+
.command('generate-types')
|
|
84
|
+
.description('Generate .md.d.ts declaration files for markdown resources')
|
|
85
|
+
.argument('<input>', 'Input directory containing markdown files')
|
|
86
|
+
.option('-p, --pattern <pattern>', 'Glob pattern for markdown files', '**/*.md')
|
|
87
|
+
.option('-v, --verbose', 'Enable verbose logging', false)
|
|
88
|
+
.action(async (input, options) => {
|
|
89
|
+
try {
|
|
90
|
+
if (options.verbose) {
|
|
91
|
+
console.log(`Generating type declarations for markdown files in: ${input}`);
|
|
92
|
+
console.log(`Pattern: ${options.pattern}`);
|
|
93
|
+
}
|
|
94
|
+
const results = await generateTypes(input, options.pattern, options.verbose);
|
|
95
|
+
// Summary
|
|
96
|
+
console.log('');
|
|
97
|
+
console.log('Type generation complete:');
|
|
98
|
+
printOperationSummary(results, 'Generated');
|
|
99
|
+
exitWithResults(results);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error('Type generation error:', error instanceof Error ? error.message : String(error));
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=generate-types-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-types-command.js","sourceRoot":"","sources":["../../src/cli/generate-types-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,iGAAiG;AAEjG,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAE9G,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAgB5E;;;;;;;GAOG;AACH,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,QAAgB,EAChB,OAAgB;IAEhB,IAAI,CAAC;QACH,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,eAAe,YAAY,EAAE,CAAC,CAAC;QAC7C,CAAC;QAED,0BAA0B;QAC1B,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QAExC,uBAAuB;QACvB,MAAM,WAAW,GAAG,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACxE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OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI entry point for resource compiler
|
|
3
|
+
*/
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
/**
|
|
6
|
+
* Create and configure the CLI program
|
|
7
|
+
*
|
|
8
|
+
* @returns Configured Commander program
|
|
9
|
+
*/
|
|
10
|
+
export declare function createCLIProgram(): Command;
|
|
11
|
+
/**
|
|
12
|
+
* Run the CLI with provided arguments
|
|
13
|
+
*
|
|
14
|
+
* @param argv - Command-line arguments (defaults to process.argv)
|
|
15
|
+
*/
|
|
16
|
+
export declare function runCLI(argv?: string[]): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAc1C;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI entry point for resource compiler
|
|
3
|
+
*/
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import { registerCompileCommand } from './compile-command.js';
|
|
6
|
+
import { registerGenerateTypesCommand } from './generate-types-command.js';
|
|
7
|
+
import { registerWatchCommand } from './watch-command.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create and configure the CLI program
|
|
10
|
+
*
|
|
11
|
+
* @returns Configured Commander program
|
|
12
|
+
*/
|
|
13
|
+
export function createCLIProgram() {
|
|
14
|
+
const program = new Command();
|
|
15
|
+
program
|
|
16
|
+
.name('vat-compile-resources')
|
|
17
|
+
.description('Compile markdown resources to TypeScript with full IDE support')
|
|
18
|
+
.version('0.2.0');
|
|
19
|
+
// Register commands
|
|
20
|
+
registerCompileCommand(program);
|
|
21
|
+
registerWatchCommand(program);
|
|
22
|
+
registerGenerateTypesCommand(program);
|
|
23
|
+
return program;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run the CLI with provided arguments
|
|
27
|
+
*
|
|
28
|
+
* @param argv - Command-line arguments (defaults to process.argv)
|
|
29
|
+
*/
|
|
30
|
+
export async function runCLI(argv) {
|
|
31
|
+
const program = createCLIProgram();
|
|
32
|
+
await program.parseAsync(argv);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,OAAO;SACJ,IAAI,CAAC,uBAAuB,CAAC;SAC7B,WAAW,CAAC,gEAAgE,CAAC;SAC7E,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB,oBAAoB;IACpB,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAChC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,4BAA4B,CAAC,OAAO,CAAC,CAAC;IAEtC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAe;IAC1C,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAC;IACnC,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI watch command implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { Command } from 'commander';
|
|
5
|
+
/**
|
|
6
|
+
* Register the watch command with Commander
|
|
7
|
+
*
|
|
8
|
+
* @param program - Commander program instance
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerWatchCommand(program: Command): void;
|
|
11
|
+
//# sourceMappingURL=watch-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-command.d.ts","sourceRoot":"","sources":["../../src/cli/watch-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqE3D"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI watch command implementation
|
|
3
|
+
*/
|
|
4
|
+
import { watch } from 'chokidar';
|
|
5
|
+
import { compileMarkdownResources } from '../compiler/markdown-compiler.js';
|
|
6
|
+
import { addCompileOptions, printCompilationSummary } from './compile-utils.js';
|
|
7
|
+
/**
|
|
8
|
+
* Register the watch command with Commander
|
|
9
|
+
*
|
|
10
|
+
* @param program - Commander program instance
|
|
11
|
+
*/
|
|
12
|
+
export function registerWatchCommand(program) {
|
|
13
|
+
addCompileOptions(program
|
|
14
|
+
.command('watch')
|
|
15
|
+
.description('Watch markdown files and recompile on changes')).action(async (input, output, options) => {
|
|
16
|
+
console.log(`Watching ${input} for changes...`);
|
|
17
|
+
console.log(`Pattern: ${options.pattern}`);
|
|
18
|
+
console.log(`Output: ${output}`);
|
|
19
|
+
console.log('');
|
|
20
|
+
// Initial compilation
|
|
21
|
+
try {
|
|
22
|
+
const results = await compileMarkdownResources({
|
|
23
|
+
inputDir: input,
|
|
24
|
+
outputDir: output,
|
|
25
|
+
pattern: options.pattern,
|
|
26
|
+
verbose: options.verbose,
|
|
27
|
+
});
|
|
28
|
+
const successCount = results.filter((r) => r.success).length;
|
|
29
|
+
const failureCount = results.filter((r) => !r.success).length;
|
|
30
|
+
console.log(`Initial compilation: ${successCount} succeeded, ${failureCount} failed`);
|
|
31
|
+
console.log('');
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('Initial compilation error:', error instanceof Error ? error.message : String(error));
|
|
35
|
+
}
|
|
36
|
+
// Set up file watcher
|
|
37
|
+
const watcher = watch(options.pattern, {
|
|
38
|
+
cwd: input,
|
|
39
|
+
persistent: true,
|
|
40
|
+
ignoreInitial: true,
|
|
41
|
+
});
|
|
42
|
+
const handleRecompilation = (error) => {
|
|
43
|
+
console.error('Recompilation error:', error instanceof Error ? error.message : String(error));
|
|
44
|
+
};
|
|
45
|
+
watcher.on('add', (path) => {
|
|
46
|
+
console.log(`[${new Date().toLocaleTimeString()}] File added: ${path}`);
|
|
47
|
+
recompileAll(input, output, options.pattern, options.verbose).catch(handleRecompilation);
|
|
48
|
+
});
|
|
49
|
+
watcher.on('change', (path) => {
|
|
50
|
+
console.log(`[${new Date().toLocaleTimeString()}] File changed: ${path}`);
|
|
51
|
+
recompileAll(input, output, options.pattern, options.verbose).catch(handleRecompilation);
|
|
52
|
+
});
|
|
53
|
+
watcher.on('unlink', (path) => {
|
|
54
|
+
console.log(`[${new Date().toLocaleTimeString()}] File removed: ${path}`);
|
|
55
|
+
recompileAll(input, output, options.pattern, options.verbose).catch(handleRecompilation);
|
|
56
|
+
});
|
|
57
|
+
watcher.on('error', (error) => {
|
|
58
|
+
console.error('Watcher error:', error);
|
|
59
|
+
});
|
|
60
|
+
// Keep process alive
|
|
61
|
+
process.on('SIGINT', () => {
|
|
62
|
+
console.log('');
|
|
63
|
+
console.log('Stopping file watcher...');
|
|
64
|
+
watcher.close().catch((error) => {
|
|
65
|
+
console.error('Error closing watcher:', error instanceof Error ? error.message : String(error));
|
|
66
|
+
});
|
|
67
|
+
process.exit(0);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Recompile all matching files
|
|
73
|
+
*/
|
|
74
|
+
async function recompileAll(input, output, pattern, verbose) {
|
|
75
|
+
try {
|
|
76
|
+
const results = await compileMarkdownResources({
|
|
77
|
+
inputDir: input,
|
|
78
|
+
outputDir: output,
|
|
79
|
+
pattern,
|
|
80
|
+
verbose,
|
|
81
|
+
});
|
|
82
|
+
printCompilationSummary(results);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('Recompilation error:', error instanceof Error ? error.message : String(error));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=watch-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-command.js","sourceRoot":"","sources":["../../src/cli/watch-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAEhF;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB;IACnD,iBAAiB,CACf,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,+CAA+C,CAAC,CAChE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAa,EAAE,MAAc,EAAE,OAA8C,EAAE,EAAE;QAC7F,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,iBAAiB,CAAC,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,YAAY,OAAO,CAAC,O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,qBAAqB;QACrB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACxB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;YACxC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBACvC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAClG,CAAC,CAAC,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,YAAY,CACzB,KAAa,EACb,MAAc,EACd,OAAe,EACf,OAAgB;IAEhB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,wBAAwB,CAAC;YAC7C,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,MAAM;YACjB,OAAO;YACP,OAAO;SACR,CAAC,CAAC;QAEH,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAChG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript declaration (.d.ts) generator for markdown resources
|
|
3
|
+
*/
|
|
4
|
+
import type { MarkdownResource } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Generate TypeScript declarations from a parsed markdown resource
|
|
7
|
+
*
|
|
8
|
+
* @param resource - Parsed markdown resource
|
|
9
|
+
* @returns Generated TypeScript declaration code
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const resource = parseMarkdown(content);
|
|
14
|
+
* const dtsCode = generateTypeScriptDeclarations(resource);
|
|
15
|
+
* // Outputs:
|
|
16
|
+
* // export interface Fragment {
|
|
17
|
+
* // readonly header: string;
|
|
18
|
+
* // readonly body: string;
|
|
19
|
+
* // readonly text: string;
|
|
20
|
+
* // }
|
|
21
|
+
* //
|
|
22
|
+
* // export const meta: { readonly title: string; readonly tags: readonly string[]; };
|
|
23
|
+
* // export const text: string;
|
|
24
|
+
* // export const fragments: { readonly sectionName: Fragment; };
|
|
25
|
+
* // export type FragmentName = keyof typeof fragments;
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function generateTypeScriptDeclarations(resource: MarkdownResource): string;
|
|
29
|
+
//# sourceMappingURL=dts-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dts-generator.d.ts","sourceRoot":"","sources":["../../src/compiler/dts-generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA2EnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAoDjF"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript declaration (.d.ts) generator for markdown resources
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Infer TypeScript type from a runtime value
|
|
6
|
+
*
|
|
7
|
+
* @param value - Runtime value to infer type from
|
|
8
|
+
* @returns TypeScript type string
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* inferType("hello") // "string"
|
|
13
|
+
* inferType(42) // "number"
|
|
14
|
+
* inferType(true) // "boolean"
|
|
15
|
+
* inferType(["a", "b"]) // "readonly string[]"
|
|
16
|
+
* inferType({ key: "value" }) // "{ readonly key: string }"
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function inferType(value) {
|
|
20
|
+
if (value === null || value === undefined) {
|
|
21
|
+
return 'undefined';
|
|
22
|
+
}
|
|
23
|
+
if (typeof value === 'string') {
|
|
24
|
+
return 'string';
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === 'number') {
|
|
27
|
+
return 'number';
|
|
28
|
+
}
|
|
29
|
+
if (typeof value === 'boolean') {
|
|
30
|
+
return 'boolean';
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
if (value.length === 0) {
|
|
34
|
+
return 'readonly unknown[]';
|
|
35
|
+
}
|
|
36
|
+
// Infer type from first element (assuming homogeneous arrays)
|
|
37
|
+
const elementType = inferType(value[0]);
|
|
38
|
+
return `readonly ${elementType}[]`;
|
|
39
|
+
}
|
|
40
|
+
if (typeof value === 'object') {
|
|
41
|
+
const entries = Object.entries(value);
|
|
42
|
+
if (entries.length === 0) {
|
|
43
|
+
return '{}';
|
|
44
|
+
}
|
|
45
|
+
const props = entries.map(([key, val]) => `readonly ${key}: ${inferType(val)}`);
|
|
46
|
+
return `{\n ${props.join(';\n ')};\n}`;
|
|
47
|
+
}
|
|
48
|
+
return 'unknown';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Generate TypeScript declaration from frontmatter
|
|
52
|
+
*
|
|
53
|
+
* @param frontmatter - Frontmatter object
|
|
54
|
+
* @returns TypeScript type declaration
|
|
55
|
+
*/
|
|
56
|
+
function generateMetaType(frontmatter) {
|
|
57
|
+
if (Object.keys(frontmatter).length === 0) {
|
|
58
|
+
return '{}';
|
|
59
|
+
}
|
|
60
|
+
const entries = Object.entries(frontmatter);
|
|
61
|
+
const props = entries.map(([key, value]) => {
|
|
62
|
+
const type = inferType(value);
|
|
63
|
+
return ` readonly ${key}: ${type};`;
|
|
64
|
+
});
|
|
65
|
+
return `{\n${props.join('\n')}\n}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generate TypeScript declarations from a parsed markdown resource
|
|
69
|
+
*
|
|
70
|
+
* @param resource - Parsed markdown resource
|
|
71
|
+
* @returns Generated TypeScript declaration code
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const resource = parseMarkdown(content);
|
|
76
|
+
* const dtsCode = generateTypeScriptDeclarations(resource);
|
|
77
|
+
* // Outputs:
|
|
78
|
+
* // export interface Fragment {
|
|
79
|
+
* // readonly header: string;
|
|
80
|
+
* // readonly body: string;
|
|
81
|
+
* // readonly text: string;
|
|
82
|
+
* // }
|
|
83
|
+
* //
|
|
84
|
+
* // export const meta: { readonly title: string; readonly tags: readonly string[]; };
|
|
85
|
+
* // export const text: string;
|
|
86
|
+
* // export const fragments: { readonly sectionName: Fragment; };
|
|
87
|
+
* // export type FragmentName = keyof typeof fragments;
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function generateTypeScriptDeclarations(resource) {
|
|
91
|
+
const lines = [];
|
|
92
|
+
// Header comment
|
|
93
|
+
lines.push('/**', ' * Generated TypeScript declarations - DO NOT EDIT', ' */', '');
|
|
94
|
+
// Fragment interface (always same structure)
|
|
95
|
+
const fragmentInterface = [
|
|
96
|
+
'export interface Fragment {',
|
|
97
|
+
' readonly header: string;',
|
|
98
|
+
' readonly body: string;',
|
|
99
|
+
' readonly text: string;',
|
|
100
|
+
'}',
|
|
101
|
+
'',
|
|
102
|
+
];
|
|
103
|
+
lines.push(...fragmentInterface);
|
|
104
|
+
// Meta type (from frontmatter)
|
|
105
|
+
const metaType = generateMetaType(resource.frontmatter);
|
|
106
|
+
const metaDeclaration = [`export const meta: ${metaType};`, ''];
|
|
107
|
+
lines.push(...metaDeclaration);
|
|
108
|
+
// Text export
|
|
109
|
+
const textDeclaration = ['export const text: string;', ''];
|
|
110
|
+
lines.push(...textDeclaration);
|
|
111
|
+
// Fragments type (specific to this resource)
|
|
112
|
+
if (resource.fragments.length === 0) {
|
|
113
|
+
lines.push('export const fragments: {};');
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
lines.push('export const fragments: {');
|
|
117
|
+
for (const fragment of resource.fragments) {
|
|
118
|
+
lines.push(` readonly ${fragment.camelCase}: Fragment;`);
|
|
119
|
+
}
|
|
120
|
+
lines.push('};');
|
|
121
|
+
}
|
|
122
|
+
lines.push('');
|
|
123
|
+
// FragmentName union type
|
|
124
|
+
if (resource.fragments.length === 0) {
|
|
125
|
+
lines.push('export type FragmentName = never;');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
lines.push('export type FragmentName = keyof typeof fragments;');
|
|
129
|
+
}
|
|
130
|
+
lines.push('');
|
|
131
|
+
return lines.join('\n');
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=dts-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dts-generator.js","sourceRoot":"","sources":["../../src/compiler/dts-generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;GAcG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,MAAM,KAA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,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,KAAK,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;IACnE,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core compiler exports
|
|
3
|
+
*/
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export { parseMarkdown } from './markdown-parser.js';
|
|
6
|
+
export { generateJavaScript } from './javascript-generator.js';
|
|
7
|
+
export { generateTypeScriptDeclarations } from './dts-generator.js';
|
|
8
|
+
export { compileMarkdownResources } from './markdown-compiler.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core compiler exports
|
|
3
|
+
*/
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export { parseMarkdown } from './markdown-parser.js';
|
|
6
|
+
export { generateJavaScript } from './javascript-generator.js';
|
|
7
|
+
export { generateTypeScriptDeclarations } from './dts-generator.js';
|
|
8
|
+
export { compileMarkdownResources } from './markdown-compiler.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript code generator for markdown resources
|
|
3
|
+
*/
|
|
4
|
+
import type { MarkdownResource } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Generate JavaScript code from a parsed markdown resource
|
|
7
|
+
*
|
|
8
|
+
* @param resource - Parsed markdown resource
|
|
9
|
+
* @returns Generated JavaScript code
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const resource = parseMarkdown(content);
|
|
14
|
+
* const jsCode = generateJavaScript(resource);
|
|
15
|
+
* // Outputs:
|
|
16
|
+
* // export const meta = { title: "Example", tags: ["test"] };
|
|
17
|
+
* // export const text = "...";
|
|
18
|
+
* // export const fragments = { sectionName: { header: "...", body: "...", text: "..." } };
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateJavaScript(resource: MarkdownResource): string;
|
|
22
|
+
//# sourceMappingURL=javascript-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"javascript-generator.d.ts","sourceRoot":"","sources":["../../src/compiler/javascript-generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA6EnD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAgCrE"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript code generator for markdown resources
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Escape a string for use in JavaScript string literals
|
|
6
|
+
*
|
|
7
|
+
* @param str - String to escape
|
|
8
|
+
* @returns Escaped string safe for JavaScript
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* escapeString('Hello "world"') // 'Hello \\"world\\"'
|
|
13
|
+
* escapeString("It's working") // 'It\\'s working'
|
|
14
|
+
* escapeString('Line 1\nLine 2') // 'Line 1\\nLine 2'
|
|
15
|
+
* escapeString('C:\\path\\to\\file') // 'C:\\\\path\\\\to\\\\file'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function escapeString(str) {
|
|
19
|
+
return str
|
|
20
|
+
.replaceAll('\\', String.raw `\\`) // Backslash must be first
|
|
21
|
+
.replaceAll('"', String.raw `\"`) // Escape double quotes
|
|
22
|
+
.replaceAll("'", String.raw `\'`) // Escape single quotes
|
|
23
|
+
.replaceAll('\n', String.raw `\n`) // Escape newlines
|
|
24
|
+
.replaceAll('\r', String.raw `\r`) // Escape carriage returns
|
|
25
|
+
.replaceAll('\t', String.raw `\t`) // Escape tabs
|
|
26
|
+
.replaceAll('`', String.raw `\``); // Escape backticks
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Serialize a value to JavaScript code
|
|
30
|
+
*
|
|
31
|
+
* @param value - Value to serialize
|
|
32
|
+
* @param indent - Indentation level
|
|
33
|
+
* @returns JavaScript code representing the value
|
|
34
|
+
*/
|
|
35
|
+
function serializeValue(value, indent = 0) {
|
|
36
|
+
const indentStr = ' '.repeat(indent);
|
|
37
|
+
const nextIndentStr = ' '.repeat(indent + 1);
|
|
38
|
+
if (value === null) {
|
|
39
|
+
return 'null';
|
|
40
|
+
}
|
|
41
|
+
if (value === undefined) {
|
|
42
|
+
return 'undefined';
|
|
43
|
+
}
|
|
44
|
+
if (typeof value === 'string') {
|
|
45
|
+
return `"${escapeString(value)}"`;
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
if (value.length === 0) {
|
|
52
|
+
return '[]';
|
|
53
|
+
}
|
|
54
|
+
const items = value.map((item) => `${nextIndentStr}${serializeValue(item, indent + 1)}`);
|
|
55
|
+
return `[\n${items.join(',\n')}\n${indentStr}]`;
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === 'object') {
|
|
58
|
+
const entries = Object.entries(value);
|
|
59
|
+
if (entries.length === 0) {
|
|
60
|
+
return '{}';
|
|
61
|
+
}
|
|
62
|
+
const props = entries.map(([key, val]) => `${nextIndentStr}${key}: ${serializeValue(val, indent + 1)}`);
|
|
63
|
+
return `{\n${props.join(',\n')}\n${indentStr}}`;
|
|
64
|
+
}
|
|
65
|
+
// Fallback for unsupported types
|
|
66
|
+
return 'null';
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generate JavaScript code from a parsed markdown resource
|
|
70
|
+
*
|
|
71
|
+
* @param resource - Parsed markdown resource
|
|
72
|
+
* @returns Generated JavaScript code
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const resource = parseMarkdown(content);
|
|
77
|
+
* const jsCode = generateJavaScript(resource);
|
|
78
|
+
* // Outputs:
|
|
79
|
+
* // export const meta = { title: "Example", tags: ["test"] };
|
|
80
|
+
* // export const text = "...";
|
|
81
|
+
* // export const fragments = { sectionName: { header: "...", body: "...", text: "..." } };
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export function generateJavaScript(resource) {
|
|
85
|
+
const lines = [];
|
|
86
|
+
// Generate frontmatter export
|
|
87
|
+
lines.push('/**', ' * Generated from markdown file - DO NOT EDIT', ' */', '');
|
|
88
|
+
// Export meta (frontmatter)
|
|
89
|
+
const metaExport = ['export const meta = ' + serializeValue(resource.frontmatter, 0) + ';', ''];
|
|
90
|
+
lines.push(...metaExport);
|
|
91
|
+
// Export full text
|
|
92
|
+
const textExport = ['export const text = ' + serializeValue(resource.content, 0) + ';', ''];
|
|
93
|
+
lines.push(...textExport);
|
|
94
|
+
// Export fragments
|
|
95
|
+
const fragmentsObj = {};
|
|
96
|
+
for (const fragment of resource.fragments) {
|
|
97
|
+
fragmentsObj[fragment.camelCase] = {
|
|
98
|
+
header: fragment.header,
|
|
99
|
+
body: fragment.body,
|
|
100
|
+
text: fragment.text,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
lines.push('export const fragments = ' + serializeValue(fragmentsObj, 0) + ';', '');
|
|
104
|
+
return lines.join('\n');
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=javascript-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"javascript-generator.js","sourceRoot":"","sources":["../../src/compiler/javascript-generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;GAaG;AACH,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG;SACP,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAA,IAAI,CAAC,CAAC,0BAA0B;SAC3D,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAA,IAAI,CAAC,CAAG,uBAAuB;SACzD,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAA,IAAI,CAAC,CAAG,uBAAuB;SACzD,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAA,IAAI,CAAC,CAAE,kBAAkB;SACpD,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAA,IAAI,CAAC,CAAE,0BAA0B;SAC5D,UAAU,CAAC,IAAI,EA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