@idomatic/parser-html 1.0.37 → 1.0.38

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.
Files changed (2) hide show
  1. package/index.js +13 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -3,12 +3,19 @@ import path from "path";
3
3
  import * as cheerio from "cheerio";
4
4
  import { randomUUID } from "crypto";
5
5
 
6
- export default async function parseHTML(filePath, config) {
6
+ /**
7
+ * @param {string} filePath
8
+ * @param {object} config
9
+ * @param {boolean} dry
10
+ * @returns {boolean}
11
+ */
12
+ export default async function parseHTML(filePath, config, dry = false) {
7
13
  const ext = path.extname(filePath).toLowerCase();
8
14
  const originalContent = fs.readFileSync(filePath, "utf-8");
9
- let updatedContent = originalContent; // fallback if nothing changes
15
+ let updatedContent = originalContent;
10
16
 
11
17
  const tagsToExclude = config.excludeTags || [];
18
+
12
19
  const addIds = ($) => {
13
20
  $("*").each((_, el) => {
14
21
  const tag = el.name;
@@ -37,6 +44,7 @@ export default async function parseHTML(filePath, config) {
37
44
  .trim()
38
45
  .toLowerCase()
39
46
  .startsWith("<html");
47
+
40
48
  if (isFullDocument) {
41
49
  const $ = cheerio.load(originalContent, { xmlMode: false });
42
50
  addIds($);
@@ -51,7 +59,9 @@ export default async function parseHTML(filePath, config) {
51
59
  }
52
60
 
53
61
  if (updatedContent !== originalContent) {
54
- fs.writeFileSync(filePath, updatedContent);
62
+ if (!dry) {
63
+ fs.writeFileSync(filePath, updatedContent);
64
+ }
55
65
  return true;
56
66
  }
57
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idomatic/parser-html",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "HTML/Vue/Angular parser for idomatic CLI",
5
5
  "type": "module",
6
6
  "main": "index.js",