Repository: denoland/fresh
File: update/src/update.ts (TypeScript)

Code before:
  const modifiedFilesList: string[] = [];

  // process files sequentially to show proper pro
  await Promise.all(sfs.map(async (sourceFile) => {
    try {
      const wasModified = await updateFile(sourceFile);
      completedFiles++;
      if (wasModified) {
        modifiedFilesList.push(sourceFile.getFilePath());
      }

      // update progress bar
      const progress = createProgressBar(completedFiles, sfs.length);
      Deno.stdout.writeSync(
        new TextEncoder().encode(`\r${colors.blue(progress)} Complete!`),
      );

      return wasModified;
    } catch (err) {
      completedFiles++;

      // update progress bar (even on failure)
      const progress = createProgressBar(completedFiles, sfs.length);
      Deno.stdout.writeSync(
        new TextEncoder().encode(`\r${colors.blue(progress)} Complete!`),
      );

      // deno-lint-ignore no-console
      console.error(`Could not process ${sourceFile.getFilePath()}`);
      throw err;
    }
  }));

  // add completion log
  // deno-lint-ignore no-console
  console.log("");

  // add migration summary
  // deno-lint-ignore no-console
  console.log("\n" + colors.bold("📊 Migration Summary:"));
  // deno-lint-ignore no-console
  console.log(`   Total files processed: ${sfs.length}`);
  // deno-lint-ignore no-console
  console.log(`   Successfully modified: ${modifiedFilesList.length}`);
  // deno-lint-ignore no-console
  console.log(
    `   Unmodified (no changes needed): ${
      sfs.length - modifiedFilesList.length
    }`,
  );


Review comment (refactor):
Nit: Move this into a `finally` block. That way we don't need to duplicate the code to clear the progress bar twice.

Code after:
  const modifiedFilesList: string[] = [];

  // process files sequentially to show proper pro
  await Promise.all(sfs.map(async (sourceFile) => {
    try {
      const wasModified = await updateFile(sourceFile);
      if (wasModified) {
        modifiedFilesList.push(sourceFile.getFilePath());
      }

      return wasModified;
    } catch (err) {
      // deno-lint-ignore no-console
      console.error(`Could not process ${sourceFile.getFilePath()}`);
      throw err;
    } finally {
      completedFiles++;

      // update progress bar
      const progress = createProgressBar(completedFiles, sfs.length);
      Deno.stdout.writeSync(
        new TextEncoder().encode(`\r${colors.blue(progress)} Complete!`),
      );
    }
  }));

  // add completion log
  // deno-lint-ignore no-console
  console.log("");

  // add migration summary
  // deno-lint-ignore no-console
  console.log("\n" + colors.bold("📊 Migration Summary:"));
  // deno-lint-ignore no-console
  console.log(`   Total files processed: ${sfs.length}`);
  // deno-lint-ignore no-console
  console.log(`   Successfully modified: ${modifiedFilesList.length}`);
  // deno-lint-ignore no-console
  console.log(
    `   Unmodified (no changes needed): ${
      sfs.length - modifiedFilesList.length
    }`,
  );

  // Display modified files list
  if (modifiedFilesList.length > 0) {
    // deno-lint-ignore no-console
    console.log("\n" + colors.bold("📝 Modified Files:"));
    modifiedFilesList.forEach((filePath) => {
      // show relative path
      const relativePath = path.relative(dir, filePath);