Skip to content

Commit 4310b32

Browse files
committed
Provide CLI
1 parent cd83a60 commit 4310b32

File tree

7 files changed

+81
-110
lines changed

7 files changed

+81
-110
lines changed

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact=true

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ npm i @allegro/convert-description jsdom
3333

3434
## Usage
3535

36+
### API
37+
3638
JavaScript code
3739

3840
```javascript
@@ -77,6 +79,13 @@ const items = convertDescriptionToItems(description, { parseToDOM });
7779
console.log(JSON.stringify(items));
7880
```
7981

82+
### CLI
83+
84+
```shell
85+
$ echo "<p>Hello World</p>" | convert-description
86+
[{"type":"TEXT","content":"<p>Hello World</p>"}]
87+
```
88+
8089
> [!CAUTION]
8190
> Any option to `convertDescriptionToItems` that is not mentioned in the documentation is subject to change. If you
8291
> need anything more than the listed options, ask a question by opening an issue or contribute by creating a pull

bin/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env node
2+
const { JSDOM } = require("jsdom");
3+
4+
const { convertDescriptionToItems } = require("../dist/umd.js");
5+
6+
const parseToDOM = (html) => new JSDOM(html);
7+
8+
const convertDescription = (inputStream, outputStream) => {
9+
let inputData = "";
10+
11+
inputStream.on("data", (chunk) => {
12+
inputData += chunk;
13+
});
14+
15+
inputStream.on("end", () => {
16+
outputStream.write(
17+
JSON.stringify(convertDescriptionToItems(inputData, { parseToDOM })),
18+
);
19+
});
20+
};
21+
22+
convertDescription(process.stdin, process.stdout);

eslint.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = [
1414
},
1515
},
1616
{
17-
files: ["*.config.js"],
17+
files: ["*.config.js", "bin/**/*.js"],
1818
languageOptions: {
1919
globals: globals.node,
2020
},

0 commit comments

Comments
 (0)