legal-markdown-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/browser.d.ts +87 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +157 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli/index.d.ts +34 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +221 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/service.d.ts +128 -0
- package/dist/cli/service.d.ts.map +1 -0
- package/dist/cli/service.js +284 -0
- package/dist/cli/service.js.map +1 -0
- package/dist/constants/index.d.ts +229 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +232 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/core/exporters/metadata-exporter.d.ts +104 -0
- package/dist/core/exporters/metadata-exporter.d.ts.map +1 -0
- package/dist/core/exporters/metadata-exporter.js +201 -0
- package/dist/core/exporters/metadata-exporter.js.map +1 -0
- package/dist/core/index.d.ts +40 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +56 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/parsers/yaml-parser.d.ts +149 -0
- package/dist/core/parsers/yaml-parser.d.ts.map +1 -0
- package/dist/core/parsers/yaml-parser.js +321 -0
- package/dist/core/parsers/yaml-parser.js.map +1 -0
- package/dist/core/processors/clause-processor.d.ts +74 -0
- package/dist/core/processors/clause-processor.d.ts.map +1 -0
- package/dist/core/processors/clause-processor.js +213 -0
- package/dist/core/processors/clause-processor.js.map +1 -0
- package/dist/core/processors/date-processor.d.ts +90 -0
- package/dist/core/processors/date-processor.d.ts.map +1 -0
- package/dist/core/processors/date-processor.js +336 -0
- package/dist/core/processors/date-processor.js.map +1 -0
- package/dist/core/processors/header-processor.d.ts +104 -0
- package/dist/core/processors/header-processor.d.ts.map +1 -0
- package/dist/core/processors/header-processor.js +585 -0
- package/dist/core/processors/header-processor.js.map +1 -0
- package/dist/core/processors/import-processor.d.ts +116 -0
- package/dist/core/processors/import-processor.d.ts.map +1 -0
- package/dist/core/processors/import-processor.js +236 -0
- package/dist/core/processors/import-processor.js.map +1 -0
- package/dist/core/processors/mixin-processor.d.ts +93 -0
- package/dist/core/processors/mixin-processor.d.ts.map +1 -0
- package/dist/core/processors/mixin-processor.js +378 -0
- package/dist/core/processors/mixin-processor.js.map +1 -0
- package/dist/core/processors/reference-processor.d.ts +115 -0
- package/dist/core/processors/reference-processor.d.ts.map +1 -0
- package/dist/core/processors/reference-processor.js +273 -0
- package/dist/core/processors/reference-processor.js.map +1 -0
- package/dist/errors/index.d.ts +234 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +267 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/extensions/batch-processor.d.ts +197 -0
- package/dist/extensions/batch-processor.d.ts.map +1 -0
- package/dist/extensions/batch-processor.js +392 -0
- package/dist/extensions/batch-processor.js.map +1 -0
- package/dist/extensions/formatters/index.d.ts +99 -0
- package/dist/extensions/formatters/index.d.ts.map +1 -0
- package/dist/extensions/formatters/index.js +128 -0
- package/dist/extensions/formatters/index.js.map +1 -0
- package/dist/extensions/index.d.ts +53 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +71 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/latex-parser.d.ts +111 -0
- package/dist/extensions/latex-parser.d.ts.map +1 -0
- package/dist/extensions/latex-parser.js +563 -0
- package/dist/extensions/latex-parser.js.map +1 -0
- package/dist/extensions/rst-parser.d.ts +112 -0
- package/dist/extensions/rst-parser.d.ts.map +1 -0
- package/dist/extensions/rst-parser.js +268 -0
- package/dist/extensions/rst-parser.js.map +1 -0
- package/dist/extensions/template-loops.d.ts +61 -0
- package/dist/extensions/template-loops.d.ts.map +1 -0
- package/dist/extensions/template-loops.js +418 -0
- package/dist/extensions/template-loops.js.map +1 -0
- package/dist/extensions/utilities/index.d.ts +114 -0
- package/dist/extensions/utilities/index.d.ts.map +1 -0
- package/dist/extensions/utilities/index.js +137 -0
- package/dist/extensions/utilities/index.js.map +1 -0
- package/dist/extensions/validators/index.d.ts +65 -0
- package/dist/extensions/validators/index.d.ts.map +1 -0
- package/dist/extensions/validators/index.js +88 -0
- package/dist/extensions/validators/index.js.map +1 -0
- package/dist/generators/html-generator.d.ts +184 -0
- package/dist/generators/html-generator.d.ts.map +1 -0
- package/dist/generators/html-generator.js +361 -0
- package/dist/generators/html-generator.js.map +1 -0
- package/dist/generators/pdf-generator.d.ts +165 -0
- package/dist/generators/pdf-generator.d.ts.map +1 -0
- package/dist/generators/pdf-generator.js +275 -0
- package/dist/generators/pdf-generator.js.map +1 -0
- package/dist/helpers/date-helpers.d.ts +216 -0
- package/dist/helpers/date-helpers.d.ts.map +1 -0
- package/dist/helpers/date-helpers.js +402 -0
- package/dist/helpers/date-helpers.js.map +1 -0
- package/dist/helpers/index.d.ts +87 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +149 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/number-helpers.d.ts +269 -0
- package/dist/helpers/number-helpers.d.ts.map +1 -0
- package/dist/helpers/number-helpers.js +406 -0
- package/dist/helpers/number-helpers.js.map +1 -0
- package/dist/helpers/string-helpers.d.ts +391 -0
- package/dist/helpers/string-helpers.d.ts.map +1 -0
- package/dist/helpers/string-helpers.js +549 -0
- package/dist/helpers/string-helpers.js.map +1 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +384 -0
- package/dist/index.js.map +1 -0
- package/dist/legal-markdown.umd.min.js +2 -0
- package/dist/legal-markdown.umd.min.js.LICENSE.txt +14 -0
- package/dist/legal-markdown.umd.min.js.map +1 -0
- package/dist/lib/index.d.ts +150 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +265 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/parsers/content-detector.d.ts +131 -0
- package/dist/parsers/content-detector.d.ts.map +1 -0
- package/dist/parsers/content-detector.js +220 -0
- package/dist/parsers/content-detector.js.map +1 -0
- package/dist/parsers/fallback-parsers.d.ts +14 -0
- package/dist/parsers/fallback-parsers.d.ts.map +1 -0
- package/dist/parsers/fallback-parsers.js +188 -0
- package/dist/parsers/fallback-parsers.js.map +1 -0
- package/dist/parsers/implementations/pandoc-native.d.ts +13 -0
- package/dist/parsers/implementations/pandoc-native.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-native.js +63 -0
- package/dist/parsers/implementations/pandoc-native.js.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts +14 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.js +64 -0
- package/dist/parsers/implementations/pandoc-wasm.js.map +1 -0
- package/dist/parsers/pandoc-factory.d.ts +97 -0
- package/dist/parsers/pandoc-factory.d.ts.map +1 -0
- package/dist/parsers/pandoc-factory.js +146 -0
- package/dist/parsers/pandoc-factory.js.map +1 -0
- package/dist/parsers/pandoc-loader.d.ts +24 -0
- package/dist/parsers/pandoc-loader.d.ts.map +1 -0
- package/dist/parsers/pandoc-loader.js +124 -0
- package/dist/parsers/pandoc-loader.js.map +1 -0
- package/dist/parsers/pandoc-parser.d.ts +27 -0
- package/dist/parsers/pandoc-parser.d.ts.map +1 -0
- package/dist/parsers/pandoc-parser.js +3 -0
- package/dist/parsers/pandoc-parser.js.map +1 -0
- package/dist/styles/default.css +125 -0
- package/dist/styles/headers.css +146 -0
- package/dist/styles/highlight.css +171 -0
- package/dist/tracking/field-tracker.d.ts +206 -0
- package/dist/tracking/field-tracker.d.ts.map +1 -0
- package/dist/tracking/field-tracker.js +247 -0
- package/dist/tracking/field-tracker.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +33 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/logger.d.ts +107 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +122 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/web/bundle-standalone.js +28 -0
- package/dist/web/bundle.js +17 -0
- package/dist/web/index.html +1465 -0
- package/dist/web/legal-markdown.umd.min.js +2 -0
- package/dist/web/standalone.html +390 -0
- package/dist/web/styles.css +874 -0
- package/package.json +118 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Command Line Interface for Legal Markdown Processing
|
|
5
|
+
*
|
|
6
|
+
* This module provides a comprehensive CLI tool for processing Legal Markdown
|
|
7
|
+
* documents with support for various output formats, processing options, and
|
|
8
|
+
* input/output methods (files, stdin/stdout).
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - File and stdin input processing
|
|
12
|
+
* - Multiple output formats (Markdown, HTML, PDF)
|
|
13
|
+
* - Comprehensive processing options and flags
|
|
14
|
+
* - Field highlighting and styling options
|
|
15
|
+
* - Metadata export capabilities
|
|
16
|
+
* - Error handling and user feedback
|
|
17
|
+
* - Debug mode support
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```bash
|
|
21
|
+
* # Process a file
|
|
22
|
+
* legal-md input.md output.md
|
|
23
|
+
*
|
|
24
|
+
* # Generate PDF with highlighting
|
|
25
|
+
* legal-md input.md --pdf --highlight --title "Contract"
|
|
26
|
+
*
|
|
27
|
+
* # Process from stdin
|
|
28
|
+
* cat input.md | legal-md --stdin --stdout
|
|
29
|
+
*
|
|
30
|
+
* # Export metadata
|
|
31
|
+
* legal-md input.md --export-yaml --output-path metadata.yaml
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
35
|
+
if (k2 === undefined) k2 = k;
|
|
36
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
37
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
38
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
39
|
+
}
|
|
40
|
+
Object.defineProperty(o, k2, desc);
|
|
41
|
+
}) : (function(o, m, k, k2) {
|
|
42
|
+
if (k2 === undefined) k2 = k;
|
|
43
|
+
o[k2] = m[k];
|
|
44
|
+
}));
|
|
45
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
46
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
47
|
+
}) : function(o, v) {
|
|
48
|
+
o["default"] = v;
|
|
49
|
+
});
|
|
50
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
51
|
+
var ownKeys = function(o) {
|
|
52
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
53
|
+
var ar = [];
|
|
54
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
55
|
+
return ar;
|
|
56
|
+
};
|
|
57
|
+
return ownKeys(o);
|
|
58
|
+
};
|
|
59
|
+
return function (mod) {
|
|
60
|
+
if (mod && mod.__esModule) return mod;
|
|
61
|
+
var result = {};
|
|
62
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
63
|
+
__setModuleDefault(result, mod);
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
})();
|
|
67
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
68
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
69
|
+
};
|
|
70
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
+
const commander_1 = require("commander");
|
|
72
|
+
const path = __importStar(require("path"));
|
|
73
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
74
|
+
const service_1 = require("./service");
|
|
75
|
+
const _errors_1 = require("../errors/index.js");
|
|
76
|
+
/**
|
|
77
|
+
* Helper function to read content from standard input
|
|
78
|
+
*
|
|
79
|
+
* @async
|
|
80
|
+
* @returns {Promise<string>} A promise that resolves to the stdin content
|
|
81
|
+
* @throws {Error} When stdin reading fails
|
|
82
|
+
*/
|
|
83
|
+
async function readStdin() {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
let data = '';
|
|
86
|
+
process.stdin.setEncoding('utf8');
|
|
87
|
+
process.stdin.on('data', chunk => {
|
|
88
|
+
data += chunk;
|
|
89
|
+
});
|
|
90
|
+
process.stdin.on('end', () => {
|
|
91
|
+
resolve(data);
|
|
92
|
+
});
|
|
93
|
+
process.stdin.on('error', error => {
|
|
94
|
+
reject(error);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// Create program
|
|
99
|
+
const program = new commander_1.Command();
|
|
100
|
+
// Setup CLI information
|
|
101
|
+
program
|
|
102
|
+
.name('legal-md')
|
|
103
|
+
.description('Node.js implementation of LegalMarkdown for processing legal documents')
|
|
104
|
+
.version('0.1.0');
|
|
105
|
+
// Main command
|
|
106
|
+
program
|
|
107
|
+
.argument('[input]', 'Input file path')
|
|
108
|
+
.argument('[output]', 'Output file path')
|
|
109
|
+
.option('-d, --debug', 'Enable debug mode')
|
|
110
|
+
.option('-y, --yaml', 'Process only YAML front matter')
|
|
111
|
+
.option('--headers', 'Process only headers')
|
|
112
|
+
.option('--no-headers', 'Skip header processing')
|
|
113
|
+
.option('--no-clauses', 'Skip optional clause processing')
|
|
114
|
+
.option('--no-references', 'Skip cross-reference processing')
|
|
115
|
+
.option('--no-imports', 'Skip import processing')
|
|
116
|
+
.option('--no-mixins', 'Skip mixin processing')
|
|
117
|
+
.option('--no-reset', 'Disable header numbering reset (continuous numbering)')
|
|
118
|
+
.option('--no-indent', 'Disable header indentation (flat formatting)')
|
|
119
|
+
.option('--throwOnYamlError', 'Throw error on invalid YAML')
|
|
120
|
+
.option('--to-markdown', 'Convert output to markdown format')
|
|
121
|
+
.option('--stdin', 'Read from standard input')
|
|
122
|
+
.option('--stdout', 'Write to standard output')
|
|
123
|
+
.option('--export-yaml', 'Export metadata as YAML')
|
|
124
|
+
.option('--export-json', 'Export metadata as JSON')
|
|
125
|
+
.option('-o, --output-path <path>', 'Path for metadata export')
|
|
126
|
+
.option('--pdf', 'Generate PDF output')
|
|
127
|
+
.option('--html', 'Generate HTML output')
|
|
128
|
+
.option('--highlight', 'Enable field highlighting in HTML/PDF output')
|
|
129
|
+
.option('--css <path>', 'Path to custom CSS file for HTML/PDF')
|
|
130
|
+
.option('--title <title>', 'Document title for HTML/PDF')
|
|
131
|
+
.action(async (input, output, options) => {
|
|
132
|
+
try {
|
|
133
|
+
// Handle stdin input
|
|
134
|
+
if (options.stdin) {
|
|
135
|
+
const stdinContent = await readStdin();
|
|
136
|
+
const cliOptions = {
|
|
137
|
+
debug: options.debug,
|
|
138
|
+
yamlOnly: options.yaml,
|
|
139
|
+
noHeaders: options.headers === false,
|
|
140
|
+
noClauses: options.headers === true ? true : options.clauses === false,
|
|
141
|
+
noReferences: options.headers === true ? true : options.references === false,
|
|
142
|
+
noImports: options.headers === true ? true : options.imports === false,
|
|
143
|
+
noMixins: options.headers === true ? true : options.mixins === false,
|
|
144
|
+
noReset: options.reset === false,
|
|
145
|
+
noIndent: options.indent === false,
|
|
146
|
+
throwOnYamlError: options.throwOnYamlError,
|
|
147
|
+
toMarkdown: options.toMarkdown,
|
|
148
|
+
exportMetadata: options.exportYaml || options.exportJson,
|
|
149
|
+
exportFormat: options.exportYaml ? 'yaml' : 'json',
|
|
150
|
+
exportPath: options.outputPath,
|
|
151
|
+
basePath: input ? path.dirname(path.resolve(input)) : process.cwd(),
|
|
152
|
+
verbose: options.debug,
|
|
153
|
+
pdf: options.pdf,
|
|
154
|
+
html: options.html,
|
|
155
|
+
highlight: options.highlight,
|
|
156
|
+
css: options.css,
|
|
157
|
+
title: options.title,
|
|
158
|
+
};
|
|
159
|
+
const cliService = new service_1.CliService(cliOptions);
|
|
160
|
+
const result = await cliService.processContent(stdinContent);
|
|
161
|
+
// When using stdin, first argument is the output file
|
|
162
|
+
const outputFile = input;
|
|
163
|
+
if (options.stdout || !outputFile) {
|
|
164
|
+
console.log(result);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
require('fs').writeFileSync(outputFile, result);
|
|
168
|
+
console.error(`✅ Output written to: ${outputFile}`);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Handle input file
|
|
173
|
+
if (!input) {
|
|
174
|
+
console.error(chalk_1.default.red('Error: Input file is required'));
|
|
175
|
+
process.exit(1);
|
|
176
|
+
}
|
|
177
|
+
const cliOptions = {
|
|
178
|
+
debug: options.debug,
|
|
179
|
+
yamlOnly: options.yaml,
|
|
180
|
+
noHeaders: options.headers === false,
|
|
181
|
+
noClauses: options.headers === true ? true : options.clauses === false,
|
|
182
|
+
noReferences: options.headers === true ? true : options.references === false,
|
|
183
|
+
noImports: options.headers === true ? true : options.imports === false,
|
|
184
|
+
noMixins: options.headers === true ? true : options.mixins === false,
|
|
185
|
+
noReset: options.reset === false,
|
|
186
|
+
noIndent: options.indent === false,
|
|
187
|
+
throwOnYamlError: options.throwOnYamlError,
|
|
188
|
+
toMarkdown: options.toMarkdown,
|
|
189
|
+
exportMetadata: options.exportYaml || options.exportJson,
|
|
190
|
+
exportFormat: options.exportYaml ? 'yaml' : 'json',
|
|
191
|
+
exportPath: options.outputPath,
|
|
192
|
+
basePath: path.dirname(path.resolve(input)),
|
|
193
|
+
verbose: options.debug,
|
|
194
|
+
pdf: options.pdf,
|
|
195
|
+
html: options.html,
|
|
196
|
+
highlight: options.highlight,
|
|
197
|
+
css: options.css,
|
|
198
|
+
title: options.title,
|
|
199
|
+
};
|
|
200
|
+
const cliService = new service_1.CliService(cliOptions);
|
|
201
|
+
// Force stdout if --stdout flag is used
|
|
202
|
+
if (options.stdout) {
|
|
203
|
+
await cliService.processFile(input);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
await cliService.processFile(input, output);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
if (error instanceof _errors_1.FileNotFoundError) {
|
|
211
|
+
console.error(chalk_1.default.red('Error: Input file not found'));
|
|
212
|
+
process.exit(1);
|
|
213
|
+
}
|
|
214
|
+
console.error(chalk_1.default.red('Error processing document:'));
|
|
215
|
+
console.error(error);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
// Parse command line arguments
|
|
220
|
+
program.parse();
|
|
221
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yCAAoC;AACpC,2CAA6B;AAC7B,kDAA0B;AAG1B,uCAAuC;AACvC,qCAA4C;AAE5C;;;;;;GAMG;AACH,KAAK,UAAU,SAAS;IACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;YAC/B,IAAI,IAAI,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE;YAChC,MAAM,C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AK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC,UAAU,CAAC,CAAC;QAE9C,wCAAwC;QACxC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,2BAAiB,EAAE,CAAC;YACvC,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC,CAAC;YACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,CAAC;QACvD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,+BAA+B;AAC/B,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview CLI Service for Legal Markdown Processing
|
|
3
|
+
*
|
|
4
|
+
* This module provides a service class that handles the business logic for
|
|
5
|
+
* the CLI tool, including file processing, output generation, error handling,
|
|
6
|
+
* and user feedback. It coordinates between the core processing functions
|
|
7
|
+
* and the command-line interface.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - File and content processing orchestration
|
|
11
|
+
* - Multi-format output generation (HTML, PDF, Markdown)
|
|
12
|
+
* - Error handling and user feedback
|
|
13
|
+
* - Verbose logging and debugging support
|
|
14
|
+
* - Path resolution and file system operations
|
|
15
|
+
* - Flexible output options (file, stdout)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { CliService } from './cli/service';
|
|
20
|
+
*
|
|
21
|
+
* const service = new CliService({
|
|
22
|
+
* verbose: true,
|
|
23
|
+
* pdf: true,
|
|
24
|
+
* highlight: true
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* await service.processFile('input.md', 'output.md');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import { LegalMarkdownOptions } from '@types';
|
|
31
|
+
/**
|
|
32
|
+
* Extended options interface for CLI operations
|
|
33
|
+
*
|
|
34
|
+
* @interface CliOptions
|
|
35
|
+
* @extends LegalMarkdownOptions
|
|
36
|
+
*/
|
|
37
|
+
export interface CliOptions extends LegalMarkdownOptions {
|
|
38
|
+
/** Input file path */
|
|
39
|
+
input?: string;
|
|
40
|
+
/** Output file path */
|
|
41
|
+
output?: string;
|
|
42
|
+
/** Enable verbose logging */
|
|
43
|
+
verbose?: boolean;
|
|
44
|
+
/** Generate PDF output */
|
|
45
|
+
pdf?: boolean;
|
|
46
|
+
/** Generate HTML output */
|
|
47
|
+
html?: boolean;
|
|
48
|
+
/** Enable field highlighting */
|
|
49
|
+
highlight?: boolean;
|
|
50
|
+
/** Path to custom CSS file */
|
|
51
|
+
css?: string;
|
|
52
|
+
/** Document title */
|
|
53
|
+
title?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Service class for CLI operations and document processing
|
|
57
|
+
*
|
|
58
|
+
* Handles file processing, output generation, and error management
|
|
59
|
+
* for the Legal Markdown CLI tool.
|
|
60
|
+
*
|
|
61
|
+
* @class CliService
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const service = new CliService({
|
|
65
|
+
* verbose: true,
|
|
66
|
+
* pdf: true,
|
|
67
|
+
* highlight: true
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare class CliService {
|
|
72
|
+
private options;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new CLI service instance
|
|
75
|
+
*
|
|
76
|
+
* @param {CliOptions} [options={}] - Configuration options
|
|
77
|
+
*/
|
|
78
|
+
constructor(options?: CliOptions);
|
|
79
|
+
/**
|
|
80
|
+
* Processes a file from input path to output path
|
|
81
|
+
*
|
|
82
|
+
* @async
|
|
83
|
+
* @param {string} inputPath - Path to the input file
|
|
84
|
+
* @param {string} [outputPath] - Path for output file (optional for stdout)
|
|
85
|
+
* @returns {Promise<void>}
|
|
86
|
+
* @throws {FileNotFoundError} When input file doesn't exist
|
|
87
|
+
* @throws {LegalMarkdownError} When processing fails
|
|
88
|
+
*/
|
|
89
|
+
processFile(inputPath: string, outputPath?: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Processes content directly without file I/O
|
|
92
|
+
*
|
|
93
|
+
* @async
|
|
94
|
+
* @param {string} content - The content to process
|
|
95
|
+
* @returns {Promise<string>} The processed content
|
|
96
|
+
* @throws {LegalMarkdownError} When processing fails
|
|
97
|
+
*/
|
|
98
|
+
processContent(content: string): Promise<string>;
|
|
99
|
+
/**
|
|
100
|
+
* Logs messages with appropriate styling and prefixes
|
|
101
|
+
*
|
|
102
|
+
* @private
|
|
103
|
+
* @param {string} message - The message to log
|
|
104
|
+
* @param {'info' | 'success' | 'warn' | 'error'} [level='info'] - The log level
|
|
105
|
+
* @returns {void}
|
|
106
|
+
*/
|
|
107
|
+
private log;
|
|
108
|
+
/**
|
|
109
|
+
* Generates formatted output (HTML/PDF) from processed content
|
|
110
|
+
*
|
|
111
|
+
* @private
|
|
112
|
+
* @async
|
|
113
|
+
* @param {string} content - The content to format
|
|
114
|
+
* @param {string} inputPath - Original input path for naming
|
|
115
|
+
* @param {string} [outputPath] - Output path override
|
|
116
|
+
* @returns {Promise<void>}
|
|
117
|
+
*/
|
|
118
|
+
private generateFormattedOutput;
|
|
119
|
+
/**
|
|
120
|
+
* Handles and formats errors for user display
|
|
121
|
+
*
|
|
122
|
+
* @private
|
|
123
|
+
* @param {unknown} error - The error to handle
|
|
124
|
+
* @returns {void}
|
|
125
|
+
*/
|
|
126
|
+
private handleError;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/cli/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAM9C;;;;;GAKG;AACH,MAAM,WAAW,UAAW,SAAQ,oBAAoB;IACtD,sBAAsB;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0BAA0B;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,2BAA2B;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gCAAgC;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAa;IAE5B;;;;OAIG;gBACS,OAAO,GAAE,UAAe;IAIpC;;;;;;;;;OASG;IACU,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4C/E;;;;;;;OAOG;IACU,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU7D;;;;;;;OAOG;IACH,OAAO,CAAC,GAAG;IAoBX;;;;;;;;;OASG;YACW,uBAAuB;IAoErC;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;CAgBpB"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview CLI Service for Legal Markdown Processing
|
|
4
|
+
*
|
|
5
|
+
* This module provides a service class that handles the business logic for
|
|
6
|
+
* the CLI tool, including file processing, output generation, error handling,
|
|
7
|
+
* and user feedback. It coordinates between the core processing functions
|
|
8
|
+
* and the command-line interface.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - File and content processing orchestration
|
|
12
|
+
* - Multi-format output generation (HTML, PDF, Markdown)
|
|
13
|
+
* - Error handling and user feedback
|
|
14
|
+
* - Verbose logging and debugging support
|
|
15
|
+
* - Path resolution and file system operations
|
|
16
|
+
* - Flexible output options (file, stdout)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { CliService } from './cli/service';
|
|
21
|
+
*
|
|
22
|
+
* const service = new CliService({
|
|
23
|
+
* verbose: true,
|
|
24
|
+
* pdf: true,
|
|
25
|
+
* highlight: true
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* await service.processFile('input.md', 'output.md');
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
32
|
+
if (k2 === undefined) k2 = k;
|
|
33
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
34
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
35
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(o, k2, desc);
|
|
38
|
+
}) : (function(o, m, k, k2) {
|
|
39
|
+
if (k2 === undefined) k2 = k;
|
|
40
|
+
o[k2] = m[k];
|
|
41
|
+
}));
|
|
42
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
43
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
44
|
+
}) : function(o, v) {
|
|
45
|
+
o["default"] = v;
|
|
46
|
+
});
|
|
47
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
48
|
+
var ownKeys = function(o) {
|
|
49
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
50
|
+
var ar = [];
|
|
51
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
return ownKeys(o);
|
|
55
|
+
};
|
|
56
|
+
return function (mod) {
|
|
57
|
+
if (mod && mod.__esModule) return mod;
|
|
58
|
+
var result = {};
|
|
59
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
60
|
+
__setModuleDefault(result, mod);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
65
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
66
|
+
};
|
|
67
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
+
exports.CliService = void 0;
|
|
69
|
+
const index_1 = require("../index");
|
|
70
|
+
const _lib_1 = require("../lib/index.js");
|
|
71
|
+
const _errors_1 = require("../errors/index.js");
|
|
72
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
73
|
+
const path = __importStar(require("path"));
|
|
74
|
+
/**
|
|
75
|
+
* Service class for CLI operations and document processing
|
|
76
|
+
*
|
|
77
|
+
* Handles file processing, output generation, and error management
|
|
78
|
+
* for the Legal Markdown CLI tool.
|
|
79
|
+
*
|
|
80
|
+
* @class CliService
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const service = new CliService({
|
|
84
|
+
* verbose: true,
|
|
85
|
+
* pdf: true,
|
|
86
|
+
* highlight: true
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
class CliService {
|
|
91
|
+
/**
|
|
92
|
+
* Creates a new CLI service instance
|
|
93
|
+
*
|
|
94
|
+
* @param {CliOptions} [options={}] - Configuration options
|
|
95
|
+
*/
|
|
96
|
+
constructor(options = {}) {
|
|
97
|
+
this.options = options;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Processes a file from input path to output path
|
|
101
|
+
*
|
|
102
|
+
* @async
|
|
103
|
+
* @param {string} inputPath - Path to the input file
|
|
104
|
+
* @param {string} [outputPath] - Path for output file (optional for stdout)
|
|
105
|
+
* @returns {Promise<void>}
|
|
106
|
+
* @throws {FileNotFoundError} When input file doesn't exist
|
|
107
|
+
* @throws {LegalMarkdownError} When processing fails
|
|
108
|
+
*/
|
|
109
|
+
async processFile(inputPath, outputPath) {
|
|
110
|
+
try {
|
|
111
|
+
this.log(`Processing file: ${inputPath}`, 'info');
|
|
112
|
+
const resolvedInputPath = (0, _lib_1.resolveFilePath)(this.options.basePath, inputPath);
|
|
113
|
+
// Check if file exists before trying to read it
|
|
114
|
+
if (!require('fs').existsSync(resolvedInputPath)) {
|
|
115
|
+
throw new _errors_1.FileNotFoundError(resolvedInputPath);
|
|
116
|
+
}
|
|
117
|
+
const content = (0, _lib_1.readFileSync)(resolvedInputPath);
|
|
118
|
+
// Determine output format
|
|
119
|
+
if (this.options.pdf || this.options.html) {
|
|
120
|
+
await this.generateFormattedOutput(content, inputPath, outputPath);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// Normal markdown processing
|
|
124
|
+
const result = (0, index_1.processLegalMarkdown)(content, this.options);
|
|
125
|
+
if (outputPath) {
|
|
126
|
+
const resolvedOutputPath = (0, _lib_1.resolveFilePath)(this.options.basePath, outputPath);
|
|
127
|
+
(0, _lib_1.writeFileSync)(resolvedOutputPath, result.content);
|
|
128
|
+
this.log(`Output written to: ${resolvedOutputPath}`, 'success');
|
|
129
|
+
console.log('Successfully processed');
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
console.log(result.content);
|
|
133
|
+
}
|
|
134
|
+
if (result.exportedFiles && result.exportedFiles.length > 0) {
|
|
135
|
+
this.log(`Exported files: ${result.exportedFiles.join(', ')}`, 'info');
|
|
136
|
+
}
|
|
137
|
+
if (result.metadata && this.options.verbose) {
|
|
138
|
+
this.log('Metadata:', 'info');
|
|
139
|
+
console.log(JSON.stringify(result.metadata, null, 2));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
this.handleError(error);
|
|
145
|
+
throw error; // Re-throw to allow CLI to handle exit codes
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Processes content directly without file I/O
|
|
150
|
+
*
|
|
151
|
+
* @async
|
|
152
|
+
* @param {string} content - The content to process
|
|
153
|
+
* @returns {Promise<string>} The processed content
|
|
154
|
+
* @throws {LegalMarkdownError} When processing fails
|
|
155
|
+
*/
|
|
156
|
+
async processContent(content) {
|
|
157
|
+
try {
|
|
158
|
+
const result = (0, index_1.processLegalMarkdown)(content, this.options);
|
|
159
|
+
return result.content;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
this.handleError(error);
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Logs messages with appropriate styling and prefixes
|
|
168
|
+
*
|
|
169
|
+
* @private
|
|
170
|
+
* @param {string} message - The message to log
|
|
171
|
+
* @param {'info' | 'success' | 'warn' | 'error'} [level='info'] - The log level
|
|
172
|
+
* @returns {void}
|
|
173
|
+
*/
|
|
174
|
+
log(message, level = 'info') {
|
|
175
|
+
if (!this.options.verbose && level === 'info')
|
|
176
|
+
return;
|
|
177
|
+
const colors = {
|
|
178
|
+
info: chalk_1.default.blue,
|
|
179
|
+
success: chalk_1.default.green,
|
|
180
|
+
warn: chalk_1.default.yellow,
|
|
181
|
+
error: chalk_1.default.red,
|
|
182
|
+
};
|
|
183
|
+
const prefix = {
|
|
184
|
+
info: '📝',
|
|
185
|
+
success: '✅',
|
|
186
|
+
warn: '⚠️',
|
|
187
|
+
error: '❌',
|
|
188
|
+
};
|
|
189
|
+
console.log(`${prefix[level]} ${colors[level](message)}`);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Generates formatted output (HTML/PDF) from processed content
|
|
193
|
+
*
|
|
194
|
+
* @private
|
|
195
|
+
* @async
|
|
196
|
+
* @param {string} content - The content to format
|
|
197
|
+
* @param {string} inputPath - Original input path for naming
|
|
198
|
+
* @param {string} [outputPath] - Output path override
|
|
199
|
+
* @returns {Promise<void>}
|
|
200
|
+
*/
|
|
201
|
+
async generateFormattedOutput(content, inputPath, outputPath) {
|
|
202
|
+
const baseOutputPath = outputPath || inputPath;
|
|
203
|
+
const baseName = path.basename(baseOutputPath, path.extname(baseOutputPath));
|
|
204
|
+
const dirName = path.dirname(baseOutputPath);
|
|
205
|
+
// Prepare generation options
|
|
206
|
+
const generateOptions = {
|
|
207
|
+
...this.options,
|
|
208
|
+
includeHighlighting: this.options.highlight,
|
|
209
|
+
cssPath: this.options.css,
|
|
210
|
+
title: this.options.title || baseName,
|
|
211
|
+
highlightCssPath: path.join(__dirname, '../../styles/highlight.css'),
|
|
212
|
+
};
|
|
213
|
+
// Generate HTML if requested
|
|
214
|
+
if (this.options.html) {
|
|
215
|
+
if (this.options.highlight) {
|
|
216
|
+
// Generate both normal and highlighted versions
|
|
217
|
+
const normalHtmlPath = path.join(dirName, `${baseName}.html`);
|
|
218
|
+
const highlightedHtmlPath = path.join(dirName, `${baseName}.HIGHLIGHT.html`);
|
|
219
|
+
const normalHtmlContent = await (0, index_1.generateHtml)(content, {
|
|
220
|
+
...generateOptions,
|
|
221
|
+
includeHighlighting: false,
|
|
222
|
+
});
|
|
223
|
+
const highlightedHtmlContent = await (0, index_1.generateHtml)(content, {
|
|
224
|
+
...generateOptions,
|
|
225
|
+
includeHighlighting: true,
|
|
226
|
+
});
|
|
227
|
+
(0, _lib_1.writeFileSync)(normalHtmlPath, normalHtmlContent);
|
|
228
|
+
(0, _lib_1.writeFileSync)(highlightedHtmlPath, highlightedHtmlContent);
|
|
229
|
+
this.log(`HTML output written to: ${normalHtmlPath}`, 'success');
|
|
230
|
+
this.log(`Highlighted HTML output written to: ${highlightedHtmlPath}`, 'success');
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// Generate single HTML
|
|
234
|
+
const htmlPath = path.join(dirName, `${baseName}.html`);
|
|
235
|
+
const htmlContent = await (0, index_1.generateHtml)(content, generateOptions);
|
|
236
|
+
(0, _lib_1.writeFileSync)(htmlPath, htmlContent);
|
|
237
|
+
this.log(`HTML output written to: ${htmlPath}`, 'success');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Generate PDF if requested
|
|
241
|
+
if (this.options.pdf) {
|
|
242
|
+
if (this.options.highlight) {
|
|
243
|
+
// Generate both normal and highlighted versions
|
|
244
|
+
const normalPdfPath = path.join(dirName, `${baseName}.pdf`);
|
|
245
|
+
const highlightedPdfPath = path.join(dirName, `${baseName}.HIGHLIGHT.pdf`);
|
|
246
|
+
await (0, index_1.generatePdfVersions)(content, normalPdfPath, generateOptions);
|
|
247
|
+
this.log(`PDF output written to: ${normalPdfPath}`, 'success');
|
|
248
|
+
this.log(`Highlighted PDF output written to: ${highlightedPdfPath}`, 'success');
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
// Generate single PDF
|
|
252
|
+
const pdfPath = path.join(dirName, `${baseName}.pdf`);
|
|
253
|
+
await (0, index_1.generatePdf)(content, pdfPath, generateOptions);
|
|
254
|
+
this.log(`PDF output written to: ${pdfPath}`, 'success');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Handles and formats errors for user display
|
|
260
|
+
*
|
|
261
|
+
* @private
|
|
262
|
+
* @param {unknown} error - The error to handle
|
|
263
|
+
* @returns {void}
|
|
264
|
+
*/
|
|
265
|
+
handleError(error) {
|
|
266
|
+
if (error instanceof _errors_1.LegalMarkdownError) {
|
|
267
|
+
this.log(`${error.name}: ${error.message}`, 'error');
|
|
268
|
+
if (error.context && this.options.verbose) {
|
|
269
|
+
console.log('Context:', error.context);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else if (error instanceof Error) {
|
|
273
|
+
this.log(`Error: ${error.message}`, 'error');
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
this.log(`Unexpected error: ${String(error)}`, 'error');
|
|
277
|
+
}
|
|
278
|
+
if (this.options.debug) {
|
|
279
|
+
console.error(error);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
exports.CliService = CliService;
|
|
284
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/cli/service.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oCAAgG;AAEhG,+BAAoE;AACpE,qCAAgE;AAChE,kDAA0B;AAC1B,2CAA6B;AA2B7B;;;;;;;;;;;;;;;GAeG;AACH,MAAa,UAAU;IAGrB;;;;OAIG;IACH,YAAY,UAAsB,EAAE;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,WAAW,CAAC,SAAiB,EAAE,UAAmB;QAC7D,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,oBAAoB,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;YAElD,MAAM,iBAAiB,GAAG,IAAA,sBAAe,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,C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