Skip to content

Commit 67f71ae

Browse files
committed
fix: reverting package.json changes
2 parents f9d5a4c + 561b973 commit 67f71ae

File tree

12 files changed

+676
-12
lines changed

12 files changed

+676
-12
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
"preLaunchTask": "Compile"
4646
}
4747
]
48-
}
48+
}

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
{
22
"name": "@salesforce/plugin-omnistudio-migration-tool",
33
"description": "This SFDX plugin migrates FlexCard, OmniScript, DataRaptor, and Integration Procedure custom objects to standard objects.",
4-
"version": "1.5.0",
4+
"version": "1.4.1-dev.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {
8+
"@babel/parser": "^7.25.4",
89
"@apexdevtools/apex-parser": "^4.1.0",
910
"@oclif/command": "^1",
1011
"@oclif/config": "^1",
1112
"@oclif/errors": "^1",
1213
"@salesforce/command": "^4.2.1",
1314
"@salesforce/core": "^2.37.1",
15+
"@types/jsdom": "^21.1.7",
1416
"@types/lodash.chunk": "^4.2.9",
17+
"cheerio": "^1.0.0",
18+
"jsdom": "^25.0.0",
1519
"lodash.chunk": "^4.2.0",
1620
"open": "^8.4.2",
17-
"tslib": "^2"
21+
"tslib": "^2",
22+
"xmldom": "^0.6.0"
1823
},
1924
"devDependencies": {
25+
"@babel/parser": "^7.25.4",
2026
"@oclif/dev-cli": "^1",
2127
"@oclif/plugin-command-snapshot": "^3.3.15",
2228
"@oclif/plugin-help": "^3",
@@ -26,13 +32,11 @@
2632
"@salesforce/plugin-command-reference": "^1.4.7",
2733
"@salesforce/prettier-config": "^0.0.3",
2834
"@salesforce/ts-sinon": "^1",
29-
"@types/chai": "^4.3.19",
35+
"@types/babel__traverse": "^7.20.6",
3036
"@types/jsforce": "^1.11.5",
31-
"@types/mocha": "^10.0.7",
32-
"@types/sinon": "^17.0.3",
3337
"@typescript-eslint/eslint-plugin": "^4.2.0",
3438
"@typescript-eslint/parser": "^4.2.0",
35-
"chai": "^4.5.0",
39+
"chai": "^4.4.1",
3640
"eslint": "^7.27.0",
3741
"eslint-config-oclif": "^3.1",
3842
"eslint-config-prettier": "^8",
@@ -50,7 +54,7 @@
5054
"nyc": "^15.1.0",
5155
"prettier": "^2.8.8",
5256
"pretty-quick": "^3.3.1",
53-
"sinon": "^10.0.0",
57+
"sinon": "10.0.0",
5458
"ts-node": "^10.9.2",
5559
"typescript": "^4.9.5"
5660
},

src/commands/omnistudio/migration/migrate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { MigrationResult, MigrationTool } from '../../../migration/interfaces';
1818
import { ResultsBuilder } from '../../../utils/resultsbuilder';
1919
import { CardMigrationTool } from '../../../migration/flexcard';
2020
import { OmniScriptExportType, OmniScriptMigrationTool } from '../../../migration/omniscript';
21+
import { Logger } from '../../../utils/logger';
2122

2223
// Initialize Messages with the current plugin directory
2324
Messages.importMessagesDirectory(__dirname);
@@ -55,7 +56,8 @@ export default class Migrate extends OmniStudioBaseCommand {
5556
const apiVersion = (this.flags.apiversion || '55.0') as string;
5657
const migrateOnly = (this.flags.only || '') as string;
5758
const allVersions = this.flags.allversions || false;
58-
59+
Logger.initialiseLogger(this.ux, this.logger);
60+
this.logger = Logger.logger;
5961
// this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername
6062
const conn = this.org.getConnection();
6163
conn.setApiVersion(apiVersion);
@@ -126,7 +128,7 @@ export default class Migrate extends OmniStudioBaseCommand {
126128
let allTruncateComplete = true;
127129
for (const cls of migrationObjects.reverse()) {
128130
try {
129-
this.ux.log('Cleaning: ' + cls.getName());
131+
Logger.ux.log('Cleaning: ' + cls.getName());
130132
debugTimer.lap('Cleaning: ' + cls.getName());
131133
await cls.truncate();
132134
} catch (ex: any) {

src/utils/logger.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { UX } from '@salesforce/command';
2+
import { Logger as SfLogger } from '@salesforce/core';
3+
4+
export class Logger {
5+
private static sfUX: UX;
6+
private static sfLogger: SfLogger;
7+
8+
public static initialiseLogger(ux: UX, logger: SfLogger): Logger {
9+
Logger.sfUX = ux;
10+
Logger.sfLogger = logger;
11+
return Logger;
12+
}
13+
14+
public static get logger(): SfLogger {
15+
return Logger.sfLogger;
16+
}
17+
public static get ux(): UX {
18+
return Logger.sfUX;
19+
}
20+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
2+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
3+
/* eslint-disable @typescript-eslint/member-ordering */
4+
/* eslint-disable no-console */
5+
import * as fs from 'fs';
6+
import * as cheerio from 'cheerio';
7+
8+
class HTMLParser {
9+
private parser: cheerio.CheerioAPI;
10+
11+
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
12+
constructor(htmlFilePath: string) {
13+
// Load the HTML file and initialize cheerio
14+
const html = this.loadHTMLFromFile(htmlFilePath);
15+
this.parser = cheerio.load(html);
16+
}
17+
18+
// Method to load HTML from a file
19+
private loadHTMLFromFile(filePath: string): string {
20+
try {
21+
return fs.readFileSync(filePath, 'utf8');
22+
} catch (error) {
23+
console.error(`Error reading file from disk: ${error}`);
24+
throw error;
25+
}
26+
}
27+
28+
// Method to replace custom tags
29+
public replaceCustomTag(oldTag: string, newTag: string): void {
30+
this.parser(oldTag).each((_, element) => {
31+
const newElement = this.parser(`<${newTag}></${newTag}>`).html(this.parser(element).html());
32+
this.parser(element).replaceWith(newElement);
33+
});
34+
}
35+
36+
// Method to save modified HTML back to a file
37+
public saveToFile(outputFilePath: string): void {
38+
try {
39+
const modifiedHtml = this.parser.html();
40+
fs.writeFileSync(outputFilePath, modifiedHtml);
41+
console.log(`Modified HTML saved to ${outputFilePath}`);
42+
} catch (error) {
43+
console.error(`Error writing file to disk: ${error}`);
44+
throw error;
45+
}
46+
}
47+
48+
// Optional: Method to get the modified HTML as a string
49+
public getModifiedHTML(): string {
50+
return this.parser.html();
51+
}
52+
}
53+
54+
export default HTMLParser;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Replace Tags Example</title>
7+
</head>
8+
<body>
9+
<template>
10+
<omnistudio-input>Hello Shailesh</omnistudio-input>
11+
<omnistudio-input>Another Input</omnistudio-input>
12+
</template>
13+
</body>
14+
</html>

src/utils/lwcparser/input/test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { LightningElement, track, api } from 'lwc';
2+
import * as LABELS from './labels';
3+
import { cloneDeep } from 'runtime_omnistudio_common/lodash';
4+
5+
export default class TestInputJsFile extends LightningElement {
6+
labels = LABELS;
7+
@api set actionData(val) {
8+
if (val) {
9+
this.actionJson = cloneDeep(val);
10+
}
11+
}
12+
get actionData() {
13+
return this.actionJson;
14+
}
15+
16+
@api attrsToBeRemoved = [];
17+
18+
@track actionJson = [];
19+
@track filteredLogs = [];
20+
@track actionSearchInput;
21+
_displayFilteredLogs = false;
22+
23+
toggle(event) {
24+
const index = event.currentTarget.dataset.index;
25+
this.actionJson[index].expanded = !this.actionJson[index].expanded;
26+
}
27+
28+
// Search
29+
get actionLogs() {
30+
const imports = "'import fs from 'fssss'";
31+
console.log(imports);
32+
// Display filtered debug logs
33+
if (Array.isArray(this.filteredLogs) && this._displayFilteredLogs) {
34+
return this.filteredLogs;
35+
}
36+
37+
// Display entire debug logs
38+
return this.actionJson;
39+
}
40+
41+
clearLogs() {
42+
this._displayFilteredLogs = false;
43+
this.actionSearchInput = '';
44+
this.actionJson = [];
45+
}
46+
47+
searchActionLogs(event) {
48+
event.preventDefault();
49+
50+
if (event.target.value) {
51+
this._displayFilteredLogs = true;
52+
const valueToSearch = event.target.value.toLowerCase();
53+
this.filteredLogs = this.actionJson.filter((action) => {
54+
return action.title && action.title.toLowerCase().includes(valueToSearch);
55+
});
56+
} else {
57+
// Clear filtered debug logs and set flag to display entire debug logs
58+
this.filteredLogs = [];
59+
this._displayFilteredLogs = false;
60+
}
61+
}
62+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
2+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
3+
/* eslint-disable no-console */
4+
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
5+
// import * as fs from 'fs';
6+
// import { parse, type ParseResult } from '@babel/parser'; // Import all types from @babel/types
7+
8+
class JavaScriptParser {
9+
// private fileContent: string;
10+
private ast: File | null = null; // Specify the generic type argument
11+
12+
constructor(filePath: string) {
13+
// this.fileContent = fs.readFileSync(filePath, 'utf-8');
14+
this.ast = null;
15+
}
16+
17+
// public parseCode(): void {
18+
// const parseResult: File = parse(this.fileContent, {
19+
// sourceType: 'module', // Use 'script' if you're parsing non-module code
20+
// plugins: ['jsx', 'typescript'], // Add plugins as needed
21+
// });
22+
23+
// if (parseResult.type === 'File') {
24+
// this.ast = parseResult;
25+
// } else {
26+
// throw new Error("Parsing did not return a 'File' node as expected.");
27+
// }
28+
// }
29+
30+
// Method to get the AST as a string
31+
getAST(): string | null {
32+
if (!this.ast) {
33+
console.error('AST is not available. Please parse the code first.');
34+
return null;
35+
}
36+
return JSON.stringify(this.ast, null, 2);
37+
}
38+
39+
// Main method to process the file
40+
processFile(): void {
41+
// this.parseCode(); // Parse the JavaScript code
42+
const astString = this.getAST(); // Get the AST as a string
43+
if (astString) {
44+
console.log(astString); // Output the AST
45+
}
46+
}
47+
}
48+
49+
export default JavaScriptParser;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Replace Tags Example</title>
7+
</head>
8+
<body>
9+
<template>
10+
<c-input>Hello Shailesh</c-input>
11+
<c-input>Another Input</c-input>
12+
</template>
13+
</body>
14+
</html>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* eslint-disable @typescript-eslint/no-inferrable-types */
2+
/* eslint-disable @typescript-eslint/no-unsafe-return */
3+
/* eslint-disable @typescript-eslint/member-ordering */
4+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
5+
/* eslint-disable @typescript-eslint/no-unsafe-call */
6+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
7+
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
8+
import { DOMParser, XMLSerializer } from 'xmldom';
9+
10+
export class XmlParser {
11+
private xmlDoc: Document | null = null;
12+
13+
constructor(private xmlString: string) {
14+
this.parseXml();
15+
}
16+
17+
private parseXml(): void {
18+
const parser = new DOMParser();
19+
this.xmlDoc = parser.parseFromString(this.xmlString, 'text/xml');
20+
}
21+
22+
public removeNode(tagName: string, index: number = 0): void {
23+
if (!this.xmlDoc) {
24+
throw new Error('XML document has not been parsed.');
25+
}
26+
27+
const nodes = this.xmlDoc.getElementsByTagName(tagName);
28+
29+
if (nodes.length > index) {
30+
const nodeToRemove = nodes[index];
31+
nodeToRemove.parentNode?.removeChild(nodeToRemove);
32+
} else {
33+
throw new Error(`No node found with tag name "${tagName}" at index ${index}.`);
34+
}
35+
}
36+
37+
public getXmlString(): string {
38+
if (!this.xmlDoc) {
39+
throw new Error('XML document has not been parsed.');
40+
}
41+
42+
const serializer = new XMLSerializer();
43+
return serializer.serializeToString(this.xmlDoc);
44+
}
45+
}

0 commit comments

Comments
 (0)