@atlaskit/codemod-cli 0.27.2 → 0.27.3

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 (65) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/main.js +85 -33
  3. package/dist/cjs/presets/index.js +2 -1
  4. package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +225 -0
  5. package/dist/cjs/presets/remove-token-fallbacks/types.js +5 -0
  6. package/dist/cjs/presets/remove-token-fallbacks/utils/all-tokens.js +44 -0
  7. package/dist/cjs/presets/remove-token-fallbacks/utils/color-utils.js +93 -0
  8. package/dist/cjs/presets/remove-token-fallbacks/utils/get-team-info.js +51 -0
  9. package/dist/cjs/presets/remove-token-fallbacks/utils/normalize-values.js +113 -0
  10. package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-imports.js +61 -0
  11. package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-variables.js +37 -0
  12. package/dist/cjs/presets/remove-token-fallbacks/utils/reporter.js +310 -0
  13. package/dist/cjs/presets/remove-token-fallbacks/utils/token-processor.js +632 -0
  14. package/dist/cjs/presets/remove-token-fallbacks/utils/update-comments.js +58 -0
  15. package/dist/es2019/main.js +24 -0
  16. package/dist/es2019/presets/index.js +2 -1
  17. package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +130 -0
  18. package/dist/es2019/presets/remove-token-fallbacks/types.js +1 -0
  19. package/dist/es2019/presets/remove-token-fallbacks/utils/all-tokens.js +30 -0
  20. package/dist/es2019/presets/remove-token-fallbacks/utils/color-utils.js +84 -0
  21. package/dist/es2019/presets/remove-token-fallbacks/utils/get-team-info.js +22 -0
  22. package/dist/es2019/presets/remove-token-fallbacks/utils/normalize-values.js +104 -0
  23. package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-imports.js +51 -0
  24. package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-variables.js +31 -0
  25. package/dist/es2019/presets/remove-token-fallbacks/utils/reporter.js +118 -0
  26. package/dist/es2019/presets/remove-token-fallbacks/utils/token-processor.js +377 -0
  27. package/dist/es2019/presets/remove-token-fallbacks/utils/update-comments.js +46 -0
  28. package/dist/esm/main.js +85 -33
  29. package/dist/esm/presets/index.js +2 -1
  30. package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +215 -0
  31. package/dist/esm/presets/remove-token-fallbacks/types.js +1 -0
  32. package/dist/esm/presets/remove-token-fallbacks/utils/all-tokens.js +38 -0
  33. package/dist/esm/presets/remove-token-fallbacks/utils/color-utils.js +86 -0
  34. package/dist/esm/presets/remove-token-fallbacks/utils/get-team-info.js +44 -0
  35. package/dist/esm/presets/remove-token-fallbacks/utils/normalize-values.js +107 -0
  36. package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-imports.js +55 -0
  37. package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-variables.js +31 -0
  38. package/dist/esm/presets/remove-token-fallbacks/utils/reporter.js +302 -0
  39. package/dist/esm/presets/remove-token-fallbacks/utils/token-processor.js +625 -0
  40. package/dist/esm/presets/remove-token-fallbacks/utils/update-comments.js +51 -0
  41. package/dist/types/presets/index.d.ts +1 -0
  42. package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +29 -0
  43. package/dist/types/presets/remove-token-fallbacks/types.d.ts +39 -0
  44. package/dist/types/presets/remove-token-fallbacks/utils/all-tokens.d.ts +1 -0
  45. package/dist/types/presets/remove-token-fallbacks/utils/color-utils.d.ts +3 -0
  46. package/dist/types/presets/remove-token-fallbacks/utils/get-team-info.d.ts +8 -0
  47. package/dist/types/presets/remove-token-fallbacks/utils/normalize-values.d.ts +8 -0
  48. package/dist/types/presets/remove-token-fallbacks/utils/remove-unused-imports.d.ts +2 -0
  49. package/dist/types/presets/remove-token-fallbacks/utils/remove-unused-variables.d.ts +2 -0
  50. package/dist/types/presets/remove-token-fallbacks/utils/reporter.d.ts +4 -0
  51. package/dist/types/presets/remove-token-fallbacks/utils/token-processor.d.ts +30 -0
  52. package/dist/types/presets/remove-token-fallbacks/utils/update-comments.d.ts +2 -0
  53. package/dist/types-ts4.5/presets/index.d.ts +1 -0
  54. package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +29 -0
  55. package/dist/types-ts4.5/presets/remove-token-fallbacks/types.d.ts +39 -0
  56. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/all-tokens.d.ts +1 -0
  57. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/color-utils.d.ts +3 -0
  58. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/get-team-info.d.ts +8 -0
  59. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/normalize-values.d.ts +8 -0
  60. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/remove-unused-imports.d.ts +2 -0
  61. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/remove-unused-variables.d.ts +2 -0
  62. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/reporter.d.ts +4 -0
  63. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/token-processor.d.ts +30 -0
  64. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/update-comments.d.ts +2 -0
  65. package/package.json +8 -3
@@ -0,0 +1,107 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import chalk from 'chalk';
3
+ import { colorToHex, compareHex, isValidColor } from './color-utils';
4
+
5
+ // so far allowing to remove only exact matches in values. Can be increased to auto-remove fallbacks with similar values
6
+ var ACCEPTABLE_COLOR_DIFFERENCE = 0;
7
+ var ACCEPTABLE_SPACE_DIFFERENCE = 0;
8
+ var ACCEPTABLE_NUMERIC_DIFFERENCE = 0;
9
+ export function normalizeValues(tokenKey, tokenValue, fallbackValue) {
10
+ var tokenLogValue;
11
+ var fallbackLogValue;
12
+ var normalizedTokenValue = tokenValue;
13
+ var normalizedFallbackValue = fallbackValue;
14
+ var lowerCaseTokenKey = tokenKey === null || tokenKey === void 0 ? void 0 : tokenKey.toLowerCase();
15
+ var difference;
16
+ var isAcceptableDifference;
17
+ if (lowerCaseTokenKey.startsWith('color') || lowerCaseTokenKey.startsWith('elevation')) {
18
+ if (tokenValue && isValidColor(tokenValue)) {
19
+ var normalizedHex = colorToHex(tokenValue);
20
+ tokenLogValue = chalk.bgHex(normalizedHex)(tokenValue);
21
+ normalizedTokenValue = normalizedHex;
22
+ }
23
+ if (fallbackValue && isValidColor(fallbackValue)) {
24
+ var _normalizedHex = colorToHex(fallbackValue);
25
+ fallbackLogValue = chalk.bgHex(_normalizedHex)(fallbackValue);
26
+ normalizedFallbackValue = _normalizedHex;
27
+ }
28
+ if (normalizedTokenValue && normalizedFallbackValue) {
29
+ difference = compareHex(normalizedTokenValue, normalizedFallbackValue);
30
+ isAcceptableDifference = difference <= ACCEPTABLE_COLOR_DIFFERENCE;
31
+ }
32
+ } else if (lowerCaseTokenKey.startsWith('space')) {
33
+ var tokenValueInPx = tokenValue ? convertToPx(tokenValue) : undefined;
34
+ var fallbackValueInPx = fallbackValue ? convertToPx(fallbackValue) : undefined;
35
+ if (tokenValueInPx !== undefined && fallbackValueInPx !== undefined) {
36
+ var maxVal = Math.max(tokenValueInPx, fallbackValueInPx);
37
+ difference = Math.abs(tokenValueInPx - fallbackValueInPx) / maxVal * 100;
38
+ isAcceptableDifference = difference <= ACCEPTABLE_SPACE_DIFFERENCE;
39
+ }
40
+ // Log the normalized values
41
+ normalizedTokenValue = tokenValue;
42
+ normalizedFallbackValue = fallbackValue;
43
+ tokenLogValue = tokenValue;
44
+ fallbackLogValue = fallbackValue;
45
+ } else {
46
+ // Handle other numeric comparisons
47
+ var tokenValueNumber = parseFloat(tokenValue !== null && tokenValue !== void 0 ? tokenValue : '');
48
+ var fallbackValueNumber = parseFloat(fallbackValue !== null && fallbackValue !== void 0 ? fallbackValue : '');
49
+ if (!isNaN(tokenValueNumber) && !isNaN(fallbackValueNumber)) {
50
+ var _maxVal = Math.max(tokenValueNumber, fallbackValueNumber);
51
+ difference = Math.abs(tokenValueNumber - fallbackValueNumber) / _maxVal * 100;
52
+ isAcceptableDifference = difference <= ACCEPTABLE_NUMERIC_DIFFERENCE;
53
+ }
54
+ // Log the normalized values
55
+ normalizedTokenValue = tokenValue;
56
+ normalizedFallbackValue = fallbackValue;
57
+ tokenLogValue = tokenValue;
58
+ fallbackLogValue = fallbackValue;
59
+ }
60
+ if (tokenLogValue === undefined) {
61
+ tokenLogValue = chalk.magenta(tokenValue || '');
62
+ }
63
+ if (fallbackLogValue === undefined) {
64
+ fallbackLogValue = chalk.yellow(fallbackValue || '');
65
+ }
66
+ return {
67
+ difference: difference,
68
+ isAcceptableDifference: isAcceptableDifference,
69
+ tokenLogValue: tokenLogValue,
70
+ fallbackLogValue: fallbackLogValue,
71
+ normalizedTokenValue: normalizedTokenValue,
72
+ normalizedFallbackValue: normalizedFallbackValue
73
+ };
74
+ }
75
+ function convertToPx(value) {
76
+ // If the value is a number, return it directly
77
+ if (typeof value === 'number') {
78
+ return value;
79
+ }
80
+ // Check if the string is a plain number (without units)
81
+ var plainNumberRegex = /^-?\d+(\.\d+)?$/;
82
+ if (plainNumberRegex.test(value)) {
83
+ return parseFloat(value);
84
+ }
85
+ // Regular expression to match CSS units
86
+ var unitRegex = /^(-?\d+(\.\d+)?)(px|rem|em|%)$/;
87
+ var match = value.match(unitRegex);
88
+ if (!match) {
89
+ return undefined;
90
+ }
91
+ var _match = _slicedToArray(match, 4),
92
+ num = _match[1],
93
+ unit = _match[3];
94
+ var numericValue = parseFloat(num);
95
+ switch (unit) {
96
+ case 'px':
97
+ return numericValue;
98
+ case 'rem':
99
+ return numericValue * 16;
100
+ // Assuming 1rem = 16px
101
+ case 'em':
102
+ return numericValue * 16;
103
+ // Assuming 1em = 16px
104
+ default:
105
+ return undefined;
106
+ }
107
+ }
@@ -0,0 +1,55 @@
1
+ export function removeUnusedImports(importDeclarations, j) {
2
+ var removeIfUnused = function removeIfUnused(importSpecifier, importDeclaration) {
3
+ var _importSpecifier$valu;
4
+ var varName = (_importSpecifier$valu = importSpecifier.value.local) === null || _importSpecifier$valu === void 0 ? void 0 : _importSpecifier$valu.name;
5
+ if (varName === 'React' || varName === 'jsx') {
6
+ return false;
7
+ }
8
+ var isUsedInScopes = function isUsedInScopes() {
9
+ return j(importDeclaration).closestScope().find(j.Identifier, {
10
+ name: varName
11
+ }).filter(function (p) {
12
+ var _importSpecifier$valu2;
13
+ if (p.value.start === ((_importSpecifier$valu2 = importSpecifier.value.local) === null || _importSpecifier$valu2 === void 0 ? void 0 : _importSpecifier$valu2.start)) {
14
+ return false;
15
+ }
16
+ if (p.parentPath.value.type === 'Property' && p.name === 'key') {
17
+ return false;
18
+ }
19
+ if (p.name === 'property') {
20
+ return false;
21
+ }
22
+ return true;
23
+ }).size() > 0;
24
+ };
25
+ if (!isUsedInScopes()) {
26
+ j(importSpecifier).remove();
27
+ return true;
28
+ }
29
+ return false;
30
+ };
31
+ var removeUnusedDefaultImport = function removeUnusedDefaultImport(importDeclaration) {
32
+ return j(importDeclaration).find(j.ImportDefaultSpecifier).filter(function (s) {
33
+ return removeIfUnused(s, importDeclaration);
34
+ }).size() > 0;
35
+ };
36
+ var removeUnusedNonDefaultImports = function removeUnusedNonDefaultImports(importDeclaration) {
37
+ return j(importDeclaration).find(j.ImportSpecifier).filter(function (s) {
38
+ return removeIfUnused(s, importDeclaration);
39
+ }).size() > 0;
40
+ };
41
+ var processImportDeclaration = function processImportDeclaration(importDeclaration) {
42
+ var _importDeclaration$va, _importDeclaration$va2;
43
+ if (((_importDeclaration$va = importDeclaration.value.specifiers) === null || _importDeclaration$va === void 0 ? void 0 : _importDeclaration$va.length) === 0) {
44
+ return false;
45
+ }
46
+ var hadUnusedDefaultImport = removeUnusedDefaultImport(importDeclaration);
47
+ var hadUnusedNonDefaultImports = removeUnusedNonDefaultImports(importDeclaration);
48
+ if (((_importDeclaration$va2 = importDeclaration.value.specifiers) === null || _importDeclaration$va2 === void 0 ? void 0 : _importDeclaration$va2.length) === 0) {
49
+ j(importDeclaration).remove();
50
+ return true;
51
+ }
52
+ return hadUnusedDefaultImport || hadUnusedNonDefaultImports;
53
+ };
54
+ importDeclarations.forEach(processImportDeclaration);
55
+ }
@@ -0,0 +1,31 @@
1
+ export function removeUnusedVariables(variableDeclarations, j) {
2
+ var removeIfUnused = function removeIfUnused(varDeclarator) {
3
+ var _varDeclarator$value;
4
+ if (((_varDeclarator$value = varDeclarator.value) === null || _varDeclarator$value === void 0 ? void 0 : _varDeclarator$value.id.type) !== 'Identifier') {
5
+ return false;
6
+ }
7
+ var varName = varDeclarator.value.id.name;
8
+ var isUsedInScopes = function isUsedInScopes() {
9
+ return j(varDeclarator).closestScope().find(j.Identifier, {
10
+ name: varName
11
+ }).filter(function (p) {
12
+ if (p.value.start === varDeclarator.value.id.start) {
13
+ return false;
14
+ }
15
+ if (p.parentPath.value.type === 'Property' && p.name === 'key') {
16
+ return false;
17
+ }
18
+ if (p.name === 'property') {
19
+ return false;
20
+ }
21
+ return true;
22
+ }).size() > 0;
23
+ };
24
+ if (!isUsedInScopes()) {
25
+ j(varDeclarator).remove();
26
+ return true;
27
+ }
28
+ return false;
29
+ };
30
+ variableDeclarations.forEach(removeIfUnused);
31
+ }
@@ -0,0 +1,302 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
7
+ /* eslint-disable no-console */
8
+ import fs from 'fs/promises';
9
+ import path from 'path';
10
+ import { v4 as uuidv4 } from 'uuid';
11
+ function writeToCsv(_x, _x2) {
12
+ return _writeToCsv.apply(this, arguments);
13
+ }
14
+ function _writeToCsv() {
15
+ _writeToCsv = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(filePath, data) {
16
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
17
+ while (1) switch (_context.prev = _context.next) {
18
+ case 0:
19
+ _context.next = 2;
20
+ return fs.writeFile(filePath, data.join('\n'), 'utf-8');
21
+ case 2:
22
+ case "end":
23
+ return _context.stop();
24
+ }
25
+ }, _callee);
26
+ }));
27
+ return _writeToCsv.apply(this, arguments);
28
+ }
29
+ function readCsv(_x3) {
30
+ return _readCsv.apply(this, arguments);
31
+ }
32
+ function _readCsv() {
33
+ _readCsv = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(filePath) {
34
+ var data;
35
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
36
+ while (1) switch (_context2.prev = _context2.next) {
37
+ case 0:
38
+ _context2.next = 2;
39
+ return fs.readFile(filePath, 'utf-8');
40
+ case 2:
41
+ data = _context2.sent;
42
+ return _context2.abrupt("return", data.split('\n').filter(function (line) {
43
+ return line.trim() !== '';
44
+ }));
45
+ case 4:
46
+ case "end":
47
+ return _context2.stop();
48
+ }
49
+ }, _callee2);
50
+ }));
51
+ return _readCsv.apply(this, arguments);
52
+ }
53
+ function escapeCsvValue(value) {
54
+ if (!value) {
55
+ return value;
56
+ }
57
+ if (value.includes('"')) {
58
+ // Escape double quotes by doubling them
59
+ value = value.replace(/"/g, '""');
60
+ }
61
+ if (value.includes(',') || value.includes('"') || value.includes('\n')) {
62
+ // Surround the value with double quotes if it contains a comma, double quotes, or newlines
63
+ value = "\"".concat(value, "\"");
64
+ }
65
+ return value;
66
+ }
67
+ export function clearFolder(_x4) {
68
+ return _clearFolder.apply(this, arguments);
69
+ }
70
+ function _clearFolder() {
71
+ _clearFolder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(reportFolder) {
72
+ var filesToDelete, _iterator, _step, file, filePath;
73
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
74
+ while (1) switch (_context3.prev = _context3.next) {
75
+ case 0:
76
+ console.log('Clearing report folder:', reportFolder);
77
+ _context3.next = 3;
78
+ return fs.readdir(reportFolder);
79
+ case 3:
80
+ filesToDelete = _context3.sent;
81
+ _iterator = _createForOfIteratorHelper(filesToDelete);
82
+ _context3.prev = 5;
83
+ _iterator.s();
84
+ case 7:
85
+ if ((_step = _iterator.n()).done) {
86
+ _context3.next = 14;
87
+ break;
88
+ }
89
+ file = _step.value;
90
+ filePath = path.join(reportFolder, file);
91
+ _context3.next = 12;
92
+ return fs.unlink(filePath);
93
+ case 12:
94
+ _context3.next = 7;
95
+ break;
96
+ case 14:
97
+ _context3.next = 19;
98
+ break;
99
+ case 16:
100
+ _context3.prev = 16;
101
+ _context3.t0 = _context3["catch"](5);
102
+ _iterator.e(_context3.t0);
103
+ case 19:
104
+ _context3.prev = 19;
105
+ _iterator.f();
106
+ return _context3.finish(19);
107
+ case 22:
108
+ case "end":
109
+ return _context3.stop();
110
+ }
111
+ }, _callee3, null, [[5, 16, 19, 22]]);
112
+ }));
113
+ return _clearFolder.apply(this, arguments);
114
+ }
115
+ function saveFilePaths(_x5, _x6) {
116
+ return _saveFilePaths.apply(this, arguments);
117
+ }
118
+ function _saveFilePaths() {
119
+ _saveFilePaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(reportFolder, files) {
120
+ var filesTxtPath;
121
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
122
+ while (1) switch (_context4.prev = _context4.next) {
123
+ case 0:
124
+ filesTxtPath = path.join(reportFolder, 'files.txt');
125
+ _context4.next = 3;
126
+ return fs.writeFile(filesTxtPath, Array.from(files).map(function (filePath) {
127
+ return "\"".concat(filePath, "\"");
128
+ }).join(' '), 'utf-8');
129
+ case 3:
130
+ case "end":
131
+ return _context4.stop();
132
+ }
133
+ }, _callee4);
134
+ }));
135
+ return _saveFilePaths.apply(this, arguments);
136
+ }
137
+ export function combineReports(_x7) {
138
+ return _combineReports.apply(this, arguments);
139
+ }
140
+ function _combineReports() {
141
+ _combineReports = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(reportFolder) {
142
+ var files, totalReplaced, totalNotReplaced, combinedReplacements, combinedNonReplacements, affectedPaths, _iterator2, _step2, file, filePath, replacements, codeFilePaths, _iterator3, _step3, codeFilePath, nonReplacements, totalTokens, percentageReplaced, combinedSummaryPath, summaryData, sortCsvLines, sortedReplacements, sortedNonReplacements, combinedReplacementsPath, header, combinedNonReplacementsPath;
143
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
144
+ while (1) switch (_context5.prev = _context5.next) {
145
+ case 0:
146
+ console.log('Combining reports in folder:', reportFolder);
147
+ _context5.next = 3;
148
+ return fs.readdir(reportFolder);
149
+ case 3:
150
+ files = _context5.sent;
151
+ totalReplaced = 0;
152
+ totalNotReplaced = 0;
153
+ combinedReplacements = [];
154
+ combinedNonReplacements = [];
155
+ affectedPaths = new Set();
156
+ _iterator2 = _createForOfIteratorHelper(files);
157
+ _context5.prev = 10;
158
+ _iterator2.s();
159
+ case 12:
160
+ if ((_step2 = _iterator2.n()).done) {
161
+ _context5.next = 34;
162
+ break;
163
+ }
164
+ file = _step2.value;
165
+ filePath = path.join(reportFolder, file);
166
+ if (!file.endsWith('_success.csv')) {
167
+ _context5.next = 26;
168
+ break;
169
+ }
170
+ _context5.next = 18;
171
+ return readCsv(filePath);
172
+ case 18:
173
+ replacements = _context5.sent;
174
+ codeFilePaths = replacements.map(function (x) {
175
+ return x.split(',')[2];
176
+ });
177
+ _iterator3 = _createForOfIteratorHelper(codeFilePaths);
178
+ try {
179
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
180
+ codeFilePath = _step3.value;
181
+ affectedPaths.add(codeFilePath);
182
+ }
183
+ } catch (err) {
184
+ _iterator3.e(err);
185
+ } finally {
186
+ _iterator3.f();
187
+ }
188
+ totalReplaced += replacements.length;
189
+ combinedReplacements.push.apply(combinedReplacements, _toConsumableArray(replacements));
190
+ _context5.next = 32;
191
+ break;
192
+ case 26:
193
+ if (!file.endsWith('_failed.csv')) {
194
+ _context5.next = 32;
195
+ break;
196
+ }
197
+ _context5.next = 29;
198
+ return readCsv(filePath);
199
+ case 29:
200
+ nonReplacements = _context5.sent;
201
+ totalNotReplaced += nonReplacements.length;
202
+ combinedNonReplacements.push.apply(combinedNonReplacements, _toConsumableArray(nonReplacements));
203
+ case 32:
204
+ _context5.next = 12;
205
+ break;
206
+ case 34:
207
+ _context5.next = 39;
208
+ break;
209
+ case 36:
210
+ _context5.prev = 36;
211
+ _context5.t0 = _context5["catch"](10);
212
+ _iterator2.e(_context5.t0);
213
+ case 39:
214
+ _context5.prev = 39;
215
+ _iterator2.f();
216
+ return _context5.finish(39);
217
+ case 42:
218
+ totalTokens = totalReplaced + totalNotReplaced;
219
+ percentageReplaced = totalTokens > 0 ? totalReplaced / totalTokens * 100 : 0;
220
+ _context5.next = 46;
221
+ return clearFolder(reportFolder);
222
+ case 46:
223
+ // Write combined summary as JSON
224
+ combinedSummaryPath = path.join(reportFolder, 'summary.json');
225
+ summaryData = {
226
+ totalReplaced: totalReplaced,
227
+ totalNotReplaced: totalNotReplaced,
228
+ percentageReplaced: percentageReplaced
229
+ };
230
+ _context5.next = 50;
231
+ return fs.writeFile(combinedSummaryPath, JSON.stringify(summaryData, null, 2), 'utf-8');
232
+ case 50:
233
+ // Sort the combined arrays
234
+ sortCsvLines = function sortCsvLines(lines) {
235
+ return lines.sort(function (a, b) {
236
+ var aCols = a.split(',');
237
+ var bCols = b.split(',');
238
+ for (var i = 0; i < 4; i++) {
239
+ var comparison = aCols[i].localeCompare(bCols[i]);
240
+ if (comparison !== 0) {
241
+ return comparison;
242
+ }
243
+ }
244
+ return 0;
245
+ });
246
+ };
247
+ sortedReplacements = sortCsvLines(combinedReplacements);
248
+ sortedNonReplacements = sortCsvLines(combinedNonReplacements); // Write combined replacements
249
+ combinedReplacementsPath = path.join(reportFolder, 'success.csv');
250
+ header = 'Team,Package,File,Line Number,Raw Token Key,Raw Fallback Value,Resolved Token Value,Resolved Fallback Value,Difference %';
251
+ _context5.next = 57;
252
+ return fs.writeFile(combinedReplacementsPath, [header].concat(_toConsumableArray(sortedReplacements)).join('\n'), 'utf-8');
253
+ case 57:
254
+ // Write combined non-replacements
255
+ combinedNonReplacementsPath = path.join(reportFolder, 'failed.csv');
256
+ _context5.next = 60;
257
+ return fs.writeFile(combinedNonReplacementsPath, [header].concat(_toConsumableArray(sortedNonReplacements)).join('\n'), 'utf-8');
258
+ case 60:
259
+ _context5.next = 62;
260
+ return saveFilePaths(reportFolder, affectedPaths);
261
+ case 62:
262
+ case "end":
263
+ return _context5.stop();
264
+ }
265
+ }, _callee5, null, [[10, 36, 39, 42]]);
266
+ }));
267
+ return _combineReports.apply(this, arguments);
268
+ }
269
+ function prepareCsvData(items) {
270
+ return items.map(function (item) {
271
+ var _item$difference$toFi, _item$difference;
272
+ return [escapeCsvValue(item.teamInfo.teamName), escapeCsvValue(item.teamInfo.packageName), escapeCsvValue(item.filePath), escapeCsvValue(String(item.lineNumber)), escapeCsvValue(item.tokenKey), escapeCsvValue(item.rawFallbackValue), escapeCsvValue(item.resolvedTokenValue), escapeCsvValue(item.resolvedFallbackValue), escapeCsvValue((_item$difference$toFi = (_item$difference = item.difference) === null || _item$difference === void 0 ? void 0 : _item$difference.toFixed(1)) !== null && _item$difference$toFi !== void 0 ? _item$difference$toFi : '')].join(',');
273
+ });
274
+ }
275
+ export function writeReports(_x8, _x9) {
276
+ return _writeReports.apply(this, arguments);
277
+ }
278
+ function _writeReports() {
279
+ _writeReports = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(details, reportFolder) {
280
+ var replacementsFilePath, nonReplacementsFilePath, replacementData, nonReplacementData;
281
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
282
+ while (1) switch (_context6.prev = _context6.next) {
283
+ case 0:
284
+ replacementsFilePath = path.join(reportFolder, "".concat(uuidv4(), "_success.csv"));
285
+ nonReplacementsFilePath = path.join(reportFolder, "".concat(uuidv4(), "_failed.csv"));
286
+ _context6.next = 4;
287
+ return fs.mkdir(reportFolder, {
288
+ recursive: true
289
+ });
290
+ case 4:
291
+ replacementData = prepareCsvData(details.replaced);
292
+ nonReplacementData = prepareCsvData(details.notReplaced);
293
+ _context6.next = 8;
294
+ return Promise.all([writeToCsv(replacementsFilePath, replacementData), writeToCsv(nonReplacementsFilePath, nonReplacementData)]);
295
+ case 8:
296
+ case "end":
297
+ return _context6.stop();
298
+ }
299
+ }, _callee6);
300
+ }));
301
+ return _writeReports.apply(this, arguments);
302
+ }