@elliemae/ds-codemods 3.27.0-next.7 → 3.27.0-next.8

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.
@@ -18,6 +18,8 @@ function parseArgumentsIntoOptions(rawArgs) {
18
18
  // it's impossible to determine if the user has passed the flag or not because
19
19
  // for arg Boolean are either true or undefined.
20
20
  '--debug': Boolean,
21
+ '--append': Boolean,
22
+ '--codebaseName': String,
21
23
  '--fileExtensions': String,
22
24
  },
23
25
  {
@@ -35,6 +37,8 @@ function parseArgumentsIntoOptions(rawArgs) {
35
37
  startingDirPath: args['--startingDirPath'],
36
38
  debug: args['--debug'], // CLI flag, not available as a question.
37
39
  fileExtensions: args['--fileExtensions'], // CLI flag, not available as a question.
40
+ append: args['--append'], // CLI flag, not available as a question.
41
+ codebaseName: args['--codebaseName'], // CLI flag, not available as a question.
38
42
  gitIgnorePath: args['--gitIgnorePath'],
39
43
  script: args._[0],
40
44
  };
@@ -26,6 +26,8 @@ export const getDeprecatedUsageReportQuestions = (originalOptions) => {
26
26
  });
27
27
  }
28
28
  // --debug is a CLI flag, not available as a question.
29
+ // --append is a CLI flag, not available as a question.
30
+ // --codebaseName is a CLI flag, not available as a question.
29
31
 
30
32
  return extraOptions;
31
33
  };
@@ -8,29 +8,49 @@ import { generateCsvRows, checkFileForDeprecatedComponents } from './utils.mjs';
8
8
  * @param {string} options.outputPath - path to the .csv file to write the report to
9
9
  * @param {string} options.startingDirPath - path to the project root directory (where node_modules folder lives)
10
10
  * @param {string} options.gitIgnorePath - path to the .gitignore file
11
+ * @param {string} options.codebaseName - optional codebaseName, if present an extra column will be added to the report
11
12
  * @param {boolean} options.debug - debug flag
13
+ * @param {boolean} options.append - whether to append to the file or override it
12
14
  *
13
15
  * @returns {void}
14
16
  */
15
17
  export const deprecatedComponentsUsageReport = (options) => {
16
- const { outputPath } = options;
18
+ const { outputPath, append } = options;
17
19
 
18
20
  const filesToParse = filePathsWithGitIgnore(options);
19
21
  // we have a lot more info than the one we use in the csv,
20
22
  // in case we want to expand it in the future we can store it in the map...
21
23
  // const problematicFiles = new Map();
22
24
 
23
- const csvRows = ['Legacy Component,Legacy Package,Filename,File Path'];
25
+ let csvRows = [`${options.codebaseName ? 'Codebase Name,' : ''}Legacy Component,Legacy Package,Filename,File Path`];
24
26
  filesToParse.forEach((filePath) => {
25
27
  const fileReport = checkFileForDeprecatedComponents(filePath);
26
28
  if (fileReport.isFileProblematic) {
27
29
  // we have a lot more info than the one we use in the csv,
28
30
  // in case we want to expand it in the future we can store it in the map...
29
31
  // problematicFiles.set(filePath, fileReport);
30
- csvRows.push(...generateCsvRows(fileReport, filePath));
32
+ csvRows.push(...generateCsvRows(fileReport, filePath, options.codebaseName));
31
33
  }
32
34
  });
33
- fs.writeFileSync(outputPath, csvRows.join('\n'));
35
+ if (!append) {
36
+ fs.writeFileSync(outputPath, csvRows.join('\n'));
37
+ } else {
38
+ // when we append we do not want to repeat the header
39
+ // we check if the file exists and if it does we check if the first line is the header
40
+ const fileExists = fs.existsSync(outputPath);
41
+ let shouldAddHeader = true;
42
+ if (fileExists) {
43
+ const fileContent = fs.readFileSync(outputPath, 'utf8');
44
+ const firstLine = fileContent.split('\n')[0];
45
+ if (firstLine === csvRows[0]) {
46
+ shouldAddHeader = false;
47
+ }
48
+ }
49
+ if (!shouldAddHeader) {
50
+ csvRows.shift();
51
+ }
52
+ fs.appendFileSync(outputPath, csvRows.join('\n'));
53
+ }
34
54
  };
35
55
 
36
56
  export default deprecatedComponentsUsageReport;
@@ -206,9 +206,10 @@ export const checkFileForDeprecatedComponents = (filePath) => {
206
206
  * Helper function to generate a csv row from a "matched effort" object
207
207
  * @param {matchedEffortMapValue} matchedEffort
208
208
  * @param {string} filePath
209
+ * @param {string} codebaseName - optional, if present an extra column will be added to the report
209
210
  * @returns {string} - csv row
210
211
  */
211
- const generateCsvRowFromMatchedEffort = (matchedEffort, filePath) => {
212
+ const generateCsvRowFromMatchedEffort = (matchedEffort, filePath, codebaseName) => {
212
213
  const { matchingEffortMetainfo } = matchedEffort;
213
214
  // matchingEffortMetainfo type is deprecatedEffortMapEntry | dismissedWithExampleEntry
214
215
  // they share 'component' and 'oldPackage' properties and for the current use case we only care about those
@@ -220,15 +221,16 @@ const generateCsvRowFromMatchedEffort = (matchedEffort, filePath) => {
220
221
  const latestMatchingFolderIndx = pathFolders.findIndex((folder, indx) => folder !== cwdFolders[indx]);
221
222
  const filePathFolders = pathFolders.slice(latestMatchingFolderIndx);
222
223
  const reducedFilePath = filePathFolders.join('/');
223
- return `${component},${oldPackage},${filename},${reducedFilePath}`;
224
+ return `${codebaseName ? `${codebaseName},` : ''}${component},${oldPackage},${filename},${reducedFilePath}`;
224
225
  };
225
226
  /**
226
227
  * Helper function to generate a list of csv rows from a given file report
227
228
  * @param {fileReport} fileReport
228
229
  * @param {string} filePath
230
+ * @param {string} codebaseName - optional, if present an extra column will be added to the report
229
231
  * @returns {string[]} - list of csv rows
230
232
  */
231
- export const generateCsvRows = (fileReport, filePath) => {
233
+ export const generateCsvRows = (fileReport, filePath, codebaseName) => {
232
234
  const { deprecatedSmallEffort, deprecatedMediumEffort, deprecatedLargeEffort, deprecatedDismissed } = fileReport;
233
235
  // csv structure = 'Legacy Component,Legacy Package,Filename,File Path'
234
236
  // Legacy Component -> matchingEffortMetainfo.component
@@ -239,17 +241,17 @@ export const generateCsvRows = (fileReport, filePath) => {
239
241
  // this is not a perfect "detect the root" solution, but should work in our CI/CD pipeline
240
242
  const csvRows = [];
241
243
  deprecatedSmallEffort.forEach((effort) => {
242
- csvRows.push(generateCsvRowFromMatchedEffort(effort, filePath));
244
+ csvRows.push(generateCsvRowFromMatchedEffort(effort, filePath, codebaseName));
243
245
  });
244
246
  deprecatedMediumEffort.forEach((effort) => {
245
- csvRows.push(generateCsvRowFromMatchedEffort(effort, filePath));
247
+ csvRows.push(generateCsvRowFromMatchedEffort(effort, filePath, codebaseName));
246
248
  });
247
249
  deprecatedLargeEffort.forEach((effort) => {
248
- csvRows.push(generateCsvRowFromMatchedEffort(effort, filePath));
250
+ csvRows.push(generateCsvRowFromMatchedEffort(effort, filePath, codebaseName));
249
251
  });
250
252
 
251
253
  deprecatedDismissed.forEach((effort) => {
252
- csvRows.push(generateCsvRowFromMatchedEffort(effort, filePath));
254
+ csvRows.push(generateCsvRowFromMatchedEffort(effort, filePath, codebaseName));
253
255
  });
254
256
 
255
257
  return csvRows;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-codemods",
3
- "version": "3.27.0-next.7",
3
+ "version": "3.27.0-next.8",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Code Mods",
6
6
  "files": [