@idomatic/parser-html 1.0.2 → 1.0.31

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 +7 -24
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import cheerio from "cheerio";
3
+ import * as cheerio from "cheerio";
4
4
  import { randomUUID } from "crypto";
5
5
 
6
6
  export default async function parseHTML(filePath, config) {
@@ -8,7 +8,7 @@ export default async function parseHTML(filePath, config) {
8
8
  let content = fs.readFileSync(filePath, "utf-8");
9
9
 
10
10
  if (ext === ".vue") {
11
- // Process Vue single file components: update the <template> block.
11
+ // Process Vue SFCs: update the <template> block.
12
12
  const templateRegex = /<template(?:\s[^>]*)?>([\s\S]*?)<\/template>/i;
13
13
  const match = content.match(templateRegex);
14
14
 
@@ -25,33 +25,13 @@ export default async function parseHTML(filePath, config) {
25
25
  });
26
26
 
27
27
  const newTemplate = $.html();
28
- // Replace the original <template> block with the updated version.
29
28
  content = content.replace(
30
29
  templateRegex,
31
30
  `<template>${newTemplate}</template>`
32
31
  );
33
32
  }
34
- } else if (ext === ".ts") {
35
- // Process TypeScript files with inline templates.
36
- // This regex matches a template property with a backtick string literal.
37
- const templateRegex = /template\s*:\s*`([\s\S]*?)`/gm;
38
- content = content.replace(templateRegex, (match, templateContent) => {
39
- const $ = cheerio.load(templateContent, { xmlMode: false });
40
-
41
- $("*").each((_, el) => {
42
- const tag = el.tagName || el.name;
43
- if (config.excludeTags.includes(tag)) return;
44
- if (!$(el).attr(config.attributeName)) {
45
- $(el).attr(config.attributeName, `${config.prefix}${randomUUID()}`);
46
- }
47
- });
48
-
49
- const newTemplate = $.html();
50
- // Replace the original inline template content.
51
- return match.replace(templateContent, newTemplate);
52
- });
53
- } else if (ext === ".html") {
54
- // For .html files, assume the entire file is HTML content.
33
+ } else if (ext === ".html" || ext === ".ng.html") {
34
+ // For .html files (including Angular's .ng.html), assume the entire file is HTML.
55
35
  const $ = cheerio.load(content, { xmlMode: false });
56
36
 
57
37
  $("*").each((_, el) => {
@@ -63,6 +43,9 @@ export default async function parseHTML(filePath, config) {
63
43
  });
64
44
 
65
45
  content = $.html();
46
+ } else {
47
+ console.log(`Skipping unsupported file: ${filePath}`);
48
+ return;
66
49
  }
67
50
 
68
51
  fs.writeFileSync(filePath, content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idomatic/parser-html",
3
- "version": "1.0.2",
3
+ "version": "1.0.31",
4
4
  "description": "HTML/Vue/Angular parser for idomatic CLI",
5
5
  "type": "module",
6
6
  "main": "index.js",