@swerr/converter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/html/html-boilerplate.d.ts +3 -0
- package/dist/modules/html/html-boilerplate.js +113 -0
- package/dist/modules/html/html-boilerplate.js.map +1 -0
- package/dist/modules/html/html-converter-config.d.ts +4 -0
- package/dist/modules/html/html-converter-config.js +2 -0
- package/dist/modules/html/html-converter-config.js.map +1 -0
- package/dist/modules/html/html-converter.d.ts +3 -0
- package/dist/modules/html/html-converter.js +30 -0
- package/dist/modules/html/html-converter.js.map +1 -0
- package/dist/modules/markdown/markdown-converter-config.d.ts +4 -0
- package/dist/modules/markdown/markdown-converter-config.js +2 -0
- package/dist/modules/markdown/markdown-converter-config.js.map +1 -0
- package/dist/modules/markdown/markdown-converter.d.ts +3 -0
- package/dist/modules/markdown/markdown-converter.js +51 -0
- package/dist/modules/markdown/markdown-converter.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Swerr Converter
|
|
2
|
+
|
|
3
|
+
This library contains multiple useful converters to transform error definitions into various formats such as Markdown, HTML, and more. <br>
|
|
4
|
+
Swerr is designed to be easily extendable, allowing developers to add custom converters as needed. <br>
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
To install Swerr Converter, use npm:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @swerr/converter
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
First, ensure the Swerr cli is installed and you have a `swerr.config.js` file in your project root. You can create one manually or run:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @swerr/cli
|
|
20
|
+
swerr init
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Once you have your configuration file set up, you can run the swerr configuration with:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
swerr run
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This command will generate the error documentation based on your JSDoc comments and the settings in your `swerr.config.js` file.
|
|
30
|
+
|
|
31
|
+
## Documentation
|
|
32
|
+
|
|
33
|
+
soon...
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAC;AACzD,cAAc,iDAAiD,CAAC;AAChE,cAAc,yCAAyC,CAAC;AACxD,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export const htmlBoilerplate = (config, scheme) => {
|
|
2
|
+
return `
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="UTF-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<title>Swerr Error Catalog - ${scheme.name} ${scheme.version}</title>
|
|
9
|
+
<style>
|
|
10
|
+
:root {
|
|
11
|
+
--primary-color: #D72323;
|
|
12
|
+
--background-color: #000000;
|
|
13
|
+
--background-color-depth: #151414;
|
|
14
|
+
--border-color: #454545;
|
|
15
|
+
--text-color: #F5EDED;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
::-moz-selection {
|
|
19
|
+
background: var(--primary-color);
|
|
20
|
+
color: #fff;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
::selection {
|
|
24
|
+
background: var(--primary-color);
|
|
25
|
+
color: #fff;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
* {
|
|
29
|
+
box-sizing: border-box;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
body {
|
|
33
|
+
font-family: Arial, sans-serif;
|
|
34
|
+
background-color: var(--background-color);
|
|
35
|
+
color: var(--text-color);
|
|
36
|
+
margin: 20px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
h1 {
|
|
40
|
+
color: var(--primary-color);
|
|
41
|
+
font-size: 2.5em;
|
|
42
|
+
margin-bottom: 10px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
h2 {
|
|
46
|
+
color: var(--primary-color);
|
|
47
|
+
font-size: 1.8em;
|
|
48
|
+
margin-bottom: 10px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
h3 {
|
|
52
|
+
color: var(--primary-color);
|
|
53
|
+
font-size: 1.5em;
|
|
54
|
+
margin-bottom: 20px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
main {
|
|
58
|
+
max-width: 1000px;
|
|
59
|
+
margin: 0 auto;
|
|
60
|
+
padding: 20px;
|
|
61
|
+
background-color: var(--background-color-depth);
|
|
62
|
+
border: 2px solid var(--border-color);
|
|
63
|
+
border-radius: 8px;
|
|
64
|
+
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: column;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
table {
|
|
72
|
+
width: 100%;
|
|
73
|
+
border-collapse: collapse;
|
|
74
|
+
margin-top: 20px;
|
|
75
|
+
border: 2px solid var(--primary-color);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
th, td {
|
|
79
|
+
padding: 12px;
|
|
80
|
+
text-align: left;
|
|
81
|
+
border-bottom: 1px solid var(--primary-color);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
th {
|
|
85
|
+
background-color: var(--primary-color);
|
|
86
|
+
color: #fff;
|
|
87
|
+
}
|
|
88
|
+
</style>
|
|
89
|
+
</head>
|
|
90
|
+
<body>
|
|
91
|
+
<main>
|
|
92
|
+
<h1>Swerr Error Documentation / Catalog</h1>
|
|
93
|
+
<h4>${scheme.name} v${scheme.version}</h4>
|
|
94
|
+
<p>${scheme.description}</p>
|
|
95
|
+
<h2>Error Catalog</h2>
|
|
96
|
+
<table border="1" cellpadding="5" cellspacing="0">
|
|
97
|
+
<tr>
|
|
98
|
+
<th>Error</th>
|
|
99
|
+
<th>Description</th>
|
|
100
|
+
</tr>
|
|
101
|
+
${scheme.errors.map(error => `
|
|
102
|
+
<tr>
|
|
103
|
+
<td>${error.name}</td>
|
|
104
|
+
<td>${error.description}</td>
|
|
105
|
+
</tr>
|
|
106
|
+
`).join('')}
|
|
107
|
+
</table>
|
|
108
|
+
</main>
|
|
109
|
+
</body>
|
|
110
|
+
</html>
|
|
111
|
+
`;
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=html-boilerplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-boilerplate.js","sourceRoot":"","sources":["../../../src/modules/html/html-boilerplate.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAA2B,EAAE,MAAmB,EAAE,EAAE;IACnF,OAAO;;;;;;iCAMyB,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAqFrD,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO;QAC/B,MAAM,CAAC,WAAW;;;;;;;MAOpB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;;WAEtB,KAAK,CAAC,IAAI;WACV,KAAK,CAAC,WAAW;;KAEvB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;;;;;CAKd,CAAA;AACD,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-converter-config.js","sourceRoot":"","sources":["../../../src/modules/html/html-converter-config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LogUtils } from "@swerr/core";
|
|
2
|
+
import { htmlBoilerplate } from "./html-boilerplate.js";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
export const htmlConverter = async (config, scheme) => {
|
|
5
|
+
if (!config.outputPath) {
|
|
6
|
+
LogUtils.error("No output path specified in the markdown converter configuration.");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const html = htmlBoilerplate(config, scheme);
|
|
10
|
+
const fileName = config.fileName || "swerr-docs.html";
|
|
11
|
+
const outputFilePath = `${config.outputPath}/${fileName}`;
|
|
12
|
+
if (!fs.existsSync(config.outputPath)) {
|
|
13
|
+
try {
|
|
14
|
+
await fs.promises.mkdir(config.outputPath, { recursive: true });
|
|
15
|
+
LogUtils.info(`Created output directory at ${config.outputPath}`);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
LogUtils.error(`Failed to create output directory at ${config.outputPath}: ${err}`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
await fs.promises.writeFile(outputFilePath, html);
|
|
24
|
+
LogUtils.success(`HTML documentation saved to ${outputFilePath}`);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
LogUtils.error(`Failed to save HTML documentation: ${err}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=html-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-converter.js","sourceRoot":"","sources":["../../../src/modules/html/html-converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAc,MAAM,aAAa,CAAC;AAClD,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,MAA2B,EAAE,MAAmB,EAAE,EAAE;IACvF,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACxB,QAAQ,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAA;QACnF,OAAO;IACR,CAAC;IAED,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,iBAAiB,CAAC;IACtD,MAAM,cAAc,GAAG,GAAG,MAAM,CAAC,UAAU,IAAI,QAAQ,EAAE,CAAC;IAE1D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC;YACJ,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;YAC9D,QAAQ,CAAC,IAAI,CAAC,+BAA+B,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACnE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,QAAQ,CAAC,KAAK,CAAC,wCAAwC,MAAM,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC,CAAC;YACpF,OAAO;QACR,CAAC;IACF,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;QAClD,QAAQ,CAAC,OAAO,CAAC,+BAA+B,cAAc,EAAE,CAAC,CAAC;IACnE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,QAAQ,CAAC,KAAK,CAAC,sCAAsC,GAAG,EAAE,CAAC,CAAC;IAC7D,CAAC;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-converter-config.js","sourceRoot":"","sources":["../../../src/modules/markdown/markdown-converter-config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LogUtils } from "@swerr/core";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
export const markdownConverter = async (config, scheme) => {
|
|
4
|
+
LogUtils.info("Starting markdown conversion");
|
|
5
|
+
if (!config.outputPath) {
|
|
6
|
+
LogUtils.error("No output path specified in the markdown converter configuration.");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const content = createMarkdownContent(scheme);
|
|
10
|
+
const fileName = config.fileName || "swerr-docs.md";
|
|
11
|
+
const outputFilePath = `${config.outputPath}/${fileName}`;
|
|
12
|
+
if (!fs.existsSync(config.outputPath)) {
|
|
13
|
+
try {
|
|
14
|
+
await fs.promises.mkdir(config.outputPath, { recursive: true });
|
|
15
|
+
LogUtils.info(`Created output directory at ${config.outputPath}`);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
LogUtils.error(`Failed to create output directory at ${config.outputPath}: ${err}`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
await fs.promises.writeFile(outputFilePath, content);
|
|
24
|
+
LogUtils.success(`Markdown documentation saved to ${outputFilePath}`);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
LogUtils.error(`Failed to save markdown documentation: ${err}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function createMarkdownContent(scheme) {
|
|
31
|
+
let content = `# Error Documentation / Catalog`;
|
|
32
|
+
if (scheme.name)
|
|
33
|
+
content += ` (${scheme.name}`;
|
|
34
|
+
if (scheme.version)
|
|
35
|
+
content += ` v${scheme.version}`;
|
|
36
|
+
if (scheme.name)
|
|
37
|
+
content += `)`;
|
|
38
|
+
content += `\n\n`;
|
|
39
|
+
content += scheme.description + `\n\n`;
|
|
40
|
+
content += `## Error Catalog\n\n`;
|
|
41
|
+
content += createErrorTable(scheme);
|
|
42
|
+
return content;
|
|
43
|
+
}
|
|
44
|
+
function createErrorTable(scheme) {
|
|
45
|
+
let table = `| Error | Description |\n|------------|-------------|\n`;
|
|
46
|
+
for (const error of scheme.errors) {
|
|
47
|
+
table += `| ${error.name} | ${error.description} |\n`;
|
|
48
|
+
}
|
|
49
|
+
return table;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=markdown-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-converter.js","sourceRoot":"","sources":["../../../src/modules/markdown/markdown-converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAc,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,MAA+B,EAAE,MAAmB,EAAE,EAAE;IAC/F,QAAQ,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IAE7C,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACxB,QAAQ,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAA;QACnF,OAAO;IACR,CAAC;IAED,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,eAAe,CAAC;IACpD,MAAM,cAAc,GAAG,GAAG,MAAM,CAAC,UAAU,IAAI,QAAQ,EAAE,CAAC;IAE1D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC;YACJ,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;YAC9D,QAAQ,CAAC,IAAI,CAAC,+BAA+B,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACnE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,QAAQ,CAAC,KAAK,CAAC,wCAAwC,MAAM,CAAC,UAAU,KAAK,GAAG,E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": "Bundle of converters to transform Swerr source files into different documentation formats.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"repository": "https://github.com/Shukaaa/swerr-converter",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"default": "./dist/index.js",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"watch": "tsc --watch"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"swerr",
|
|
21
|
+
"errors",
|
|
22
|
+
"documentation",
|
|
23
|
+
"api",
|
|
24
|
+
"jsdoc",
|
|
25
|
+
"jsdocs",
|
|
26
|
+
"docs",
|
|
27
|
+
"converter",
|
|
28
|
+
"converters",
|
|
29
|
+
"html",
|
|
30
|
+
"markdown"
|
|
31
|
+
],
|
|
32
|
+
"author": "Shukaaa",
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^24.3.2",
|
|
36
|
+
"typescript": "^5.9.2"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@swerr/core": "^0.0.4"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"package.json",
|
|
44
|
+
"README.md"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
|
+
}
|