UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

1 lines 2.76 kB
{"version":3,"sources":["../../../packages/tools/wac-cli/src/angular15/utils/file-comparison.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,KAAA,EAAE,SAAS,KAAA,WA+ClD","file":"file-comparison.d.ts","sourcesContent":["import { Logger } from \"./logger\";\r\n\r\nconst fs = require('fs');\r\n\r\n/**\r\n * the normalize line endings function.\r\n * @param text the text.\r\n * @returns the normalized line endings.\r\n */\r\nfunction normalizeLineEndings(text) {\r\n return text.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n');\r\n}\r\n\r\n/**\r\n * the file comparison function.\r\n * @param file1Path the file 1 path.\r\n * @param file2Path the file 2 path.\r\n * @returns the file comparison result.\r\n */\r\nexport function fileComparison(file1Path, file2Path) {\r\n const prefix = 'fileComparison';\r\n try {\r\n Logger.log(`Reading ${file1Path} and ${file2Path}`, prefix);\r\n const content1 = fs.readFileSync(file1Path, 'utf-8');\r\n const content2 = fs.readFileSync(file2Path, 'utf-8');\r\n\r\n const normalizedContent1 = normalizeLineEndings(content1);\r\n const normalizedContent2 = normalizeLineEndings(content2);\r\n\r\n const lines1 = normalizedContent1.split('\\n');\r\n const lines2 = normalizedContent2.split('\\n');\r\n\r\n let differencesFound = false;\r\n for (let i = 0; i < Math.min(lines1.length, lines2.length); i++) {\r\n if (lines1[i] !== lines2[i]) {\r\n Logger.log(`Difference at line ${i + 1}:`, prefix);\r\n Logger.log(`File 1: ${lines1[i]}`, prefix);\r\n Logger.log(`File 2: ${lines2[i]}`, prefix);\r\n differencesFound = true;\r\n }\r\n }\r\n\r\n // Check for additional lines in either file\r\n if (lines1.length > lines2.length) {\r\n for (let i = lines2.length; i < lines1.length; i++) {\r\n Logger.log(`Additional line in File 1 at line ${i + 1}:`, prefix);\r\n Logger.log(`File 1: ${lines1[i]}`, prefix);\r\n differencesFound = true;\r\n }\r\n } else if (lines2.length > lines1.length) {\r\n for (let i = lines1.length; i < lines2.length; i++) {\r\n Logger.log(`Additional line in File 2 at line ${i + 1}:`, prefix);\r\n Logger.log(`File 2: ${lines2[i]}`, prefix);\r\n differencesFound = true;\r\n }\r\n }\r\n\r\n if (!differencesFound) {\r\n Logger.log('No differences found.', prefix);\r\n return true;\r\n }\r\n } catch (error) {\r\n Logger.error(`Error reading files: ${error.message}`);\r\n }\r\n\r\n return false;\r\n}\r\n"]}