Skip to content

Commit c85b416

Browse files
fix: fix
2 parents f57178f + 2387e73 commit c85b416

File tree

5 files changed

+17
-34
lines changed

5 files changed

+17
-34
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"@types/jsdom": "^21.1.7",
1616
"@types/lodash.chunk": "^4.2.9",
1717
"@types/shelljs": "^0.8.15",
18-
"cheerio": "^1.0.0",
1918
"jsdom": "^25.0.0",
2019
"lodash.chunk": "^4.2.0",
2120
"open": "^8.4.2",

src/migration/related/LwcMigration.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ export class LwcMigration extends BaseRelatedObjectMigration {
6363
const jsonData: LWCAssessmentInfo[] = [];
6464
fileMap.forEach((fileList, dir) => {
6565
const changeInfos: FileChangeInfo[] = [];
66-
if (dir !== 'lwc' && !dir.endsWith('English') && !dir.includes('_') && !dir.includes('cf')) {
66+
if (dir !== 'lwc' && !dir.endsWith('English') && !dir.includes('_') && !dir.startsWith('cf')) {
6767
for (const file of fileList) {
6868
if (this.isValideFile(file.name)) {
6969
const processor = FileProcessorFactory.getFileProcessor(file.ext);
7070
if (processor != null) {
7171
const path = file.location;
7272
const name = file.name + file.ext;
73+
if (file.ext === 'xml') {
74+
// if (fileutil.isAutogenratedFile(path)) { }
75+
}
7376
const diff = processor.process(file, type, this.namespace);
7477
if (diff != null) {
7578
const fileInfo: FileChangeInfo = {

src/utils/lwcparser/htmlParser/HTMLParser.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,16 @@
77
/* eslint-disable @typescript-eslint/member-ordering */
88
/* eslint-disable no-console */
99
import * as fs from 'fs';
10-
import * as cheerio from 'cheerio';
1110
import { FileConstant } from '../fileutils/FileConstant';
1211

1312
const DEFAULT_NAMESPACE = 'c';
14-
const TAG = 'tag';
15-
16-
// const { window } = new JSDOM();
17-
// const { document } = window;
1813

1914
export class HTMLParser {
20-
private parser: cheerio.CheerioAPI;
2115
html: string;
2216
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
2317
constructor(htmlFilePath: string) {
2418
// Load the HTML file and initialize cheerio
2519
this.html = this.loadHTMLFromFile(htmlFilePath);
26-
this.parser = cheerio.load(this.html, { xmlMode: true });
2720
}
2821

2922
// Method to load HTML from a file
@@ -39,27 +32,14 @@ export class HTMLParser {
3932
// Method to replace custom tags
4033
public replaceTags(namespaceTag: string): Map<string, string> {
4134
const htmlContentMap = new Map<string, string>();
42-
// Load the HTML into cheerio
43-
const $ = this.parser;
4435
htmlContentMap.set(FileConstant.BASE_CONTENT, this.html);
45-
// Find all tags that contain the substring "omnistudio" in their tag name
46-
$('*').each((i, element) => {
47-
if (element.type === TAG && element.name && element.name.includes(namespaceTag + '-')) {
48-
// Create a new tag with the same content and attributes as the old tag
49-
const newTag = DEFAULT_NAMESPACE + element.name.substring(element.name.indexOf('-'));
50-
const newElement = $(`<${newTag}>`).html($(element).html());
36+
// Use a regular expression to match <omnistudio-input> to </omnistudio-input>
5137

52-
// Copy all attributes from the old element to the new one
53-
Object.keys(element.attribs).forEach((attr) => {
54-
newElement.attr(attr, $(element).attr(attr));
55-
});
38+
this.html = this.html
39+
.replace('<' + namespaceTag, '<' + DEFAULT_NAMESPACE)
40+
.replace('</' + namespaceTag, '</' + DEFAULT_NAMESPACE);
5641

57-
// Replace the old element with the new one
58-
$(element).replaceWith(newElement);
59-
}
60-
});
61-
$.html().replace(/\n\s*/g, '');
62-
htmlContentMap.set(FileConstant.MODIFIED_CONTENT, $.html());
42+
htmlContentMap.set(FileConstant.MODIFIED_CONTENT, this.html);
6343
return htmlContentMap;
6444
}
6545

@@ -76,6 +56,6 @@ export class HTMLParser {
7656

7757
// Optional: Method to get the modified HTML as a string
7858
public getModifiedHTML(): string {
79-
return this.parser.html();
59+
return this.html;
8060
}
8161
}

src/utils/lwcparser/xmlParser/XmlParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ export class XmlParser {
5656
throw error;
5757
}
5858
}
59+
60+
// public isAutogenratedFile(filePath: string) {
61+
// this.fileContent = fs.readFileSync(filePath, 'utf-8');
62+
// return this.fileContent.includes('OmniScript Auto-generated');
63+
// }
5964
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-call */
22
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3-
import { expect } from 'chai';
3+
import { expect } from '@salesforce/command/lib/test';
44
import { HTMLParser } from '../../../../src/utils/lwcparser/htmlParser/HTMLParser';
5-
import { FileDiffUtil } from '../../../../src/utils/lwcparser/fileutils/FileDiffUtil';
65

76
describe('HTMLParser test class', () => {
87
const mockFilePath = 'test/utils/lwc/parser/input/test.html';
98
it('should read file content correctly', () => {
109
const htmlParser = new HTMLParser(mockFilePath);
11-
const html: Map<string, string> = htmlParser.replaceTags('omnistudio');
12-
// eslint-disable-next-line no-console
13-
console.log(new FileDiffUtil().getFileDiff('file.txt', html.get('original'), html.get('modified')));
14-
htmlParser.saveToFile('test/utils/lwc/parser/output/test.html', html.get('modified'));
10+
htmlParser.replaceTags('omnistudio');
1511
expect(htmlParser.getModifiedHTML()).contains('c-input');
1612
});
1713
});

0 commit comments

Comments
 (0)