<commit_before>import UpdatedPackagesCollector from "../UpdatedPackagesCollector";
import FileSystemUtilities from "../FileSystemUtilities";
import PromptUtilities from "../PromptUtilities";
import GitUtilities from "../GitUtilities";
import NpmUtilities from "../NpmUtilities";
import Command from "../Command";
import semver from "semver";
import async from "async";
import path from "path";

export default class PublishCommand extends Command {
  initialize(callback) {
    if (this.flags.canary) {
      this.logger.info("Publishing canary build");
    }

    if (!this.repository.isIndependent()) {
      this.globalVersion = this.repository.version;
      this.logger.info("Current version: " + this.globalVersion);
    }

    const updatedPackagesCollector = new UpdatedPackagesCollector(
      this.packages,
      this.packageGraph,
      this.flags,
      this.repository.publishConfig
    );

    try {
      this.updates = updatedPackagesCollector.getUpdates();
    } catch (err) {
      throw err;
    }

    if (!this.updates.length) {
      callback(new Error("No updated packages to publish."));
      return;
    }

    this.getVersionsForUpdates((err, results) => {
      if (err) {
        callback(err);
        return;
      }

      let {version, versions} = results;

      if (!versions) {
        versions = {};
        this.updates.forEach(update => {
          versions[update.package.name] = version;
        });
      }

      this.masterVersion = version;
      this.updatesVersions = versions;

      this.confirmVersions((err, confirmed) => {
        if (err) {
          callback(err);
          return;
        }

        if (!confirmed) {
          this.logger.info("Okay bye!");
          callback(null, false);
          return;
        }

        callback(null, true);
      });
    });
  }

  execute(callback) {
    try {
      if (!this.repository.isIndependent() && !this.flags.canary) {
        this.updateVersionInLernaJson();
      }

      this.updateUpdatedPackages();
      if (!this.flags.skipGit) {
        this.commitAndTagUpdates();
      }
    } catch (err) {
      callback(err);
      return;
    }

    this.logger.newLine();
    this.logger.info("Publishing packages to npm...");

    this.npmPublishAsPrerelease(err => {
      if (err) {
        callback(err);
        return;
      }

      if (this.flags.canary) {
        this.logger.info("Reseting git state");
        // reset since the package.json files are changed
        GitUtilities.checkoutChanges("packages/*/package.json");
      }

      this.npmUpdateAsLatest(err => {
        if (err) {
          callback(err);
          return;
        }

        if (!(this.flags.canary || this.flags.skipGit)) {
          this.logger.info("Pushing tags to git...");
          this.logger.newLine();
          GitUtilities.pushWithTags(this.tags);
        }

        let message = "Successfully published:";

        this.updates.forEach(update => {
          message += `\n - ${update.package.name}@${update.package.version}`;
        });

        this.logger.success(message);
        callback(null, true);<commit_msg>Fix spelling of Resetting (#137)<commit_after>import UpdatedPackagesCollector from "../UpdatedPackagesCollector";
import FileSystemUtilities from "../FileSystemUtilities";
import PromptUtilities from "../PromptUtilities";
import GitUtilities from "../GitUtilities";
import NpmUtilities from "../NpmUtilities";
import Command from "../Command";
import semver from "semver";
import async from "async";
import path from "path";

export default class PublishCommand extends Command {
  initialize(callback) {
    if (this.flags.canary) {
      this.logger.info("Publishing canary build");
    }

    if (!this.repository.isIndependent()) {
      this.globalVersion = this.repository.version;
      this.logger.info("Current version: " + this.globalVersion);
    }

    const updatedPackagesCollector = new UpdatedPackagesCollector(
      this.packages,
      this.packageGraph,
      this.flags,
      this.repository.publishConfig
    );

    try {
      this.updates = updatedPackagesCollector.getUpdates();
    } catch (err) {
      throw err;
    }

    if (!this.updates.length) {
      callback(new Error("No updated packages to publish."));
      return;
    }

    this.getVersionsForUpdates((err, results) => {
      if (err) {
        callback(err);
        return;
      }

      let {version, versions} = results;

      if (!versions) {
        versions = {};
        this.updates.forEach(update => {
          versions[update.package.name] = version;
        });
      }

      this.masterVersion = version;
      this.updatesVersions = versions;

      this.confirmVersions((err, confirmed) => {
        if (err) {
          callback(err);
          return;
        }

        if (!confirmed) {
          this.logger.info("Okay bye!");
          callback(null, false);
          return;
        }

        callback(null, true);
      });
    });
  }

  execute(callback) {
    try {
      if (!this.repository.isIndependent() && !this.flags.canary) {
        this.updateVersionInLernaJson();
      }

      this.updateUpdatedPackages();
      if (!this.flags.skipGit) {
        this.commitAndTagUpdates();
      }
    } catch (err) {
      callback(err);
      return;
    }

    this.logger.newLine();
    this.logger.info("Publishing packages to npm...");

    this.npmPublishAsPrerelease(err => {
      if (err) {
        callback(err);
        return;
      }

      if (this.flags.canary) {
        this.logger.info("Resetting git state");
        // reset since the package.json files are changed
        GitUtilities.checkoutChanges("packages/*/package.json");
      }

      this.npmUpdateAsLatest(err => {
        if (err) {
          callback(err);
          return;
        }

        if (!(this.flags.canary || this.flags.skipGit)) {
          this.logger.info("Pushing tags to git...");
          this.logger.newLine();
          GitUtilities.pushWithTags(this.tags);
        }

        let message = "Successfully published:";

        this.updates.forEach(update => {
          message += `\n - ${update.package.name}@${update.package.version}`;
        });

        this.logger.success(message);
        callback(null, true);
{'fraction_non_alphanumeric': 0.13192234245703374, 'fraction_numerical': 0.00047740292807129216, 'mean_word_length': 2.221424910302409, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4529501', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1778, 'n_words': 355}