Skip to content

Commit

Permalink
Provide CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
hjagodzinski committed Dec 16, 2024
1 parent cd83a60 commit 4310b32
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 110 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ npm i @allegro/convert-description jsdom

## Usage

### API

JavaScript code

```javascript
Expand Down Expand Up @@ -77,6 +79,13 @@ const items = convertDescriptionToItems(description, { parseToDOM });
console.log(JSON.stringify(items));
```

### CLI

```shell
$ echo "<p>Hello World</p>" | convert-description
[{"type":"TEXT","content":"<p>Hello World</p>"}]
```

> [!CAUTION]
> Any option to `convertDescriptionToItems` that is not mentioned in the documentation is subject to change. If you
> need anything more than the listed options, ask a question by opening an issue or contribute by creating a pull
Expand Down
22 changes: 22 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
const { JSDOM } = require("jsdom");

const { convertDescriptionToItems } = require("../dist/umd.js");

const parseToDOM = (html) => new JSDOM(html);

const convertDescription = (inputStream, outputStream) => {
let inputData = "";

inputStream.on("data", (chunk) => {
inputData += chunk;
});

inputStream.on("end", () => {
outputStream.write(
JSON.stringify(convertDescriptionToItems(inputData, { parseToDOM })),
);
});
};

convertDescription(process.stdin, process.stdout);
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = [
},
},
{
files: ["*.config.js"],
files: ["*.config.js", "bin/**/*.js"],
languageOptions: {
globals: globals.node,
},
Expand Down
Loading

0 comments on commit 4310b32

Please sign in to comment.