Skip to content

Commit

Permalink
Merge pull request #42 from Hargne/feature/upgrade-dependencies
Browse files Browse the repository at this point in the history
Upgraded dependencies
  • Loading branch information
Hargne authored May 4, 2023
2 parents 357893c + 16a7d73 commit 2def67e
Show file tree
Hide file tree
Showing 6 changed files with 2,402 additions and 3,726 deletions.
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,54 @@
## Installation

```shell
yarn add html-creator
$ npm i html-creator
```

## Usage

```Javascript
const htmlCreator = require('html-creator');
const htmlCreator = require("html-creator");

const html = new htmlCreator([
{
type: 'head',
content: [{ type: 'title', content: 'Generated HTML' }]
type: "head",
content: [
{
type: "title",
content: "Generated HTML",
},
{
type: "style",
content: `
#cool-text {
color: red;
}
`,
},
],
},
{
type: 'body',
attributes: { style: 'padding: 1rem' },
type: "body",
content: [
{
type: 'div',
type: "div",
content: [
{
type: 'span',
content: 'A Button Span Deluxe',
attributes: { className: 'button' },
type: "div",
content: "This is a cool text 😎",
attributes: { id: "cool-text" },
},
{
type: 'a',
content: 'Click here',
attributes: { href: '/path-to-infinity', target: '_blank' },
type: "a",
content: "Click here",
attributes: { href: "/path-to-infinity", target: "_blank" },
},
],
},
],
},
]);

html.renderHTML();
const result = html.renderHTML();
```

The above code will result with the following HTML output:
Expand All @@ -57,10 +68,15 @@ The above code will result with the following HTML output:
<html>
<head>
<title>Generated HTML</title>
<style>
#cool-text {
color: red;
}
</style>
</head>
<body style="padding: 1rem">
<body>
<div>
<span class="button">A Button Span Deluxe</span>
<div id="cool-text">This is a cool text 😎</div>
<a href="/path-to-infinity" target="_blank">Click here</a>
</div>
</body>
Expand Down
37 changes: 17 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-creator",
"version": "0.6.3",
"version": "0.7.0",
"description": "Generate HTML with node.js",
"main": "dist/index.js",
"unpkg": "dist/index.js",
Expand Down Expand Up @@ -38,27 +38,24 @@
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.8.7",
"@babel/preset-typescript": "^7.8.3",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.6",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"babel-jest": "^25.2.4",
"eslint": "^7.30.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"babel-jest": "^29.5.0",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^25.1.0",
"rollup": "2.47.0",
"rollup-plugin-terser": "^5.3.0",
"ts-jest": "^25.3.0",
"typescript": "^3.7.2"
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"rollup": "^3.21.4",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"
},
"dependencies": {
"@types/mkdirp": "^1.0.0",
"@types/node": "^12.12.7",
"lodash": "^4.17.5",
"prettier": "^2.4.1",
"mkdirp": "^1.0.3"
"@types/node": "^18.16.3",
"mkdirp": "^3.0.1",
"prettier": "^2.4.1"
}
}
2 changes: 1 addition & 1 deletion rollup.config.js → rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import babel from "@rollup/plugin-babel";
import resolve from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";

const externalLibraries = ["fs", "path", "lodash", "mkdirp", "prettier"];
const externalLibraries = ["fs", "path", "mkdirp", "prettier"];
const extensions = [".ts", ".js"];

const config = {
Expand Down
20 changes: 10 additions & 10 deletions src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ class HTMLCreatorDocument {
element: HTMLCreatorElement,
search: { id?: string; class?: string; type?: string }
) {
let targetElementList: HTMLCreatorElement[] = [];
if (!search) {
return this;
}

// Look up the target element
if (search) {
if (search.id) {
targetElementList = this.findElementById(search.id);
} else if (search.class) {
targetElementList = this.findElementByClassName(search.class);
} else if (search.type) {
targetElementList = this.findElementByType(search.type);
}
let targetElementList: HTMLCreatorElement[] = [];
if (search.id) {
targetElementList = this.findElementById(search.id);
} else if (search.class) {
targetElementList = this.findElementByClassName(search.class);
} else if (search.type) {
targetElementList = this.findElementByType(search.type);
}

if (targetElementList.length > 0) {
Expand Down
10 changes: 2 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import fs from "fs";
import mkdirp from "mkdirp";
import { mkdirp } from "mkdirp";
import { HTMLCreatorElement } from "./index.d";

export const logMessage = (
Expand Down Expand Up @@ -72,13 +72,7 @@ export const searchForElement = ({
}
// Flatten result array or just return a single object
const flatResult = result.flat();
if (flatResult.length > 0) {
if (flatResult.length === 1) {
return [flatResult[0]];
}
return flatResult;
}
return [];
return flatResult.length === 1 ? [flatResult[0]] : flatResult;
};

export const pushOrConcat = (
Expand Down
Loading

0 comments on commit 2def67e

Please sign in to comment.