<commit_before>const fs = require("fs-extra");
const path = require("path");
const configFile = require("./configFile");

const DEFAULT_MIGRATIONS_DIR_NAME = "migrations";

async function resolveMigrationsDirPath() {
  let migrationsDir;
  try {
    const config = await configFile.read();
    migrationsDir = config.migrationsDir; // eslint-disable-line
    // if config file doesn't have migrationsDir key, assume default 'migrations' dir
    if (!migrationsDir) {
      migrationsDir = DEFAULT_MIGRATIONS_DIR_NAME;
    }
  } catch (err) {
    // config file could not be read, assume default 'migrations' dir
    migrationsDir = DEFAULT_MIGRATIONS_DIR_NAME;
  }

  if (path.isAbsolute(migrationsDir)) {
    return migrationsDir;
  }
  return path.join(process.cwd(), migrationsDir);
}

async function resolveSampleMigrationPath() {
  const migrationsDir = await resolveMigrationsDirPath();
  return path.join(migrationsDir, 'sample-migration.js');
}

module.exports = {
  resolve: resolveMigrationsDirPath,
  resolveSampleMigrationPath,

  async shouldExist() {
    const migrationsDir = await resolveMigrationsDirPath();
    try {
      await fs.stat(migrationsDir);
    } catch (err) {
      throw new Error(`migrations directory does not exist: ${migrationsDir}`);
    }
  },

  async shouldNotExist() {
    const migrationsDir = await resolveMigrationsDirPath();
    const error = new Error(
      `migrations directory already exists: ${migrationsDir}`
    );

    try {
      await fs.stat(migrationsDir);
      throw error;
    } catch (err) {
      if (err.code !== "ENOENT") {
        throw error;
      }
    }
  },

  async getFileNames() {
    const migrationsDir = await resolveMigrationsDirPath();
    const files = await fs.readdir(migrationsDir);
    return files.filter(file => path.extname(file) === ".js");
  },

  async loadMigration(fileName) {
    const migrationsDir = await resolveMigrationsDirPath();
    return require(path.join(migrationsDir, fileName)); // eslint-disable-line
  },

  async doesSampleMigrationExist() {
    const samplePath = await resolveSampleMigrationPath();
    try {<commit_msg>Fix: Ignore sample-migration.js when getting migrations<commit_after>const fs = require("fs-extra");
const path = require("path");
const configFile = require("./configFile");

const DEFAULT_MIGRATIONS_DIR_NAME = "migrations";

async function resolveMigrationsDirPath() {
  let migrationsDir;
  try {
    const config = await configFile.read();
    migrationsDir = config.migrationsDir; // eslint-disable-line
    // if config file doesn't have migrationsDir key, assume default 'migrations' dir
    if (!migrationsDir) {
      migrationsDir = DEFAULT_MIGRATIONS_DIR_NAME;
    }
  } catch (err) {
    // config file could not be read, assume default 'migrations' dir
    migrationsDir = DEFAULT_MIGRATIONS_DIR_NAME;
  }

  if (path.isAbsolute(migrationsDir)) {
    return migrationsDir;
  }
  return path.join(process.cwd(), migrationsDir);
}

async function resolveSampleMigrationPath() {
  const migrationsDir = await resolveMigrationsDirPath();
  return path.join(migrationsDir, 'sample-migration.js');
}

module.exports = {
  resolve: resolveMigrationsDirPath,
  resolveSampleMigrationPath,

  async shouldExist() {
    const migrationsDir = await resolveMigrationsDirPath();
    try {
      await fs.stat(migrationsDir);
    } catch (err) {
      throw new Error(`migrations directory does not exist: ${migrationsDir}`);
    }
  },

  async shouldNotExist() {
    const migrationsDir = await resolveMigrationsDirPath();
    const error = new Error(
      `migrations directory already exists: ${migrationsDir}`
    );

    try {
      await fs.stat(migrationsDir);
      throw error;
    } catch (err) {
      if (err.code !== "ENOENT") {
        throw error;
      }
    }
  },

  async getFileNames() {
    const migrationsDir = await resolveMigrationsDirPath();
    const files = await fs.readdir(migrationsDir);
    return files.filter(file => path.extname(file) === ".js" && path.basename(file) !== 'sample-migration.js');
  },

  async loadMigration(fileName) {
    const migrationsDir = await resolveMigrationsDirPath();
    return require(path.join(migrationsDir, fileName)); // eslint-disable-line
  },

  async doesSampleMigrationExist() {
    const samplePath = await resolveSampleMigrationPath();
    try {
{'fraction_non_alphanumeric': 0.11187686652883069, 'fraction_numerical': 0.0, 'mean_word_length': 3.7793633369923163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1844499', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1340, 'n_words': 311}