<commit_before>import childProcess = require("child_process");
import path = require("path");
import fsX = require("fs-extra");
import process = require("process");
// Mine
import core = require("./core");
import coreInit = require("./core-init");
import util = require("./util");


function rootRelative(startDir: string, optionalPath: boolean | string) {
  const targetPath = (typeof optionalPath === "boolean") ? "." : optionalPath;
  const absolutePath = path.resolve(startDir, targetPath);
  // Assume running from root dir
  return path.relative(process.cwd(), absolutePath);
}

export interface ManifestOptions {
  edit?: boolean;
  add?: boolean | string;
  delete?: boolean | string;
  list?: boolean;
}

export function doManifest(options: ManifestOptions) {
  const startDir = process.cwd();
  core.cdRootDirectory();
  const rootObject = core.readRootFile();
  const mainPath = path.resolve(process.cwd(), rootObject.mainPath);
  const manifestPath = core.manifestPath({ mainPath });

  if (options.edit) {
    // Same checks as osenv.editor
    const editor = process.env.EDITOR
      || process.env.VISUAL
      ||((process.platform === "win32") ? "notepad.exe" : "vi");
      childProcess.execFileSync(editor, [manifestPath], { stdio: "inherit" });
  } else if (options.list) {
    const manifestObject = core.readManifest({ mainPath });
    delete manifestObject.tipsForManualEditing;
    console.log(JSON.stringify(manifestObject, undefined, "  "));
  } else if (options.add) {
    const targetPath = rootRelative(startDir, options.add);
    const manifestObject = core.readManifest({ mainPath });
    console.log(`Added dependency for ${path.resolve(process.cwd(), targetPath)}`);
    manifestObject.dependencies[util.normalizeToPosix(targetPath)] = coreInit.makeDependencyEntry({
      repoPath: targetPath,
      mainRepoPath: mainPath,
    });
    fsX.writeJsonSync(manifestPath, manifestObject, { spaces: 2 });
  } else if (options.delete) {
    const targetPath = rootRelative(startDir, options.delete);
    const manifestObject = core.readManifest({ mainPath });
    if (manifestObject.dependencies[targetPath] === undefined) {
      util.terminate(`No manifest dependency for: ${targetPath}`);
    }
    delete manifestObject.dependencies[targetPath];
    fsX.writeJsonSync(manifestPath, manifestObject, { spaces: 2 });
    console.log(`Deleted manifest dependency for ${targetPath}`);
  } else {
    // Do something vaguelu useful, like `fab root` and `fab main`
    console.log(manifestPath);
  }
  process.chdir(startDir);
}

<commit_msg>Use current manifest rather than default<commit_after>import childProcess = require("child_process");
import path = require("path");
import fsX = require("fs-extra");
import process = require("process");
// Mine
import core = require("./core");
import coreInit = require("./core-init");
import util = require("./util");


function rootRelative(startDir: string, optionalPath: boolean | string) {
  const targetPath = (typeof optionalPath === "boolean") ? "." : optionalPath;
  const absolutePath = path.resolve(startDir, targetPath);
  // Assume running from root dir
  return path.relative(process.cwd(), absolutePath);
}

export interface ManifestOptions {
  edit?: boolean;
  add?: boolean | string;
  delete?: boolean | string;
  list?: boolean;
}

export function doManifest(options: ManifestOptions) {
  const startDir = process.cwd();
  core.cdRootDirectory();
  const rootObject = core.readRootFile();
  const mainPath = path.resolve(process.cwd(), rootObject.mainPath);
  const manifestPath = core.manifestPath({ mainPath, manifest: rootObject.manifest });

  if (options.edit) {
    // Same checks as osenv.editor
    const editor = process.env.EDITOR
      || process.env.VISUAL
      ||((process.platform === "win32") ? "notepad.exe" : "vi");
      childProcess.execFileSync(editor, [manifestPath], { stdio: "inherit" });
  } else if (options.list) {
    const manifestObject = core.readManifest({ mainPath, manifest: rootObject.manifest });
    delete manifestObject.tipsForManualEditing;
    console.log(JSON.stringify(manifestObject, undefined, "  "));
  } else if (options.add) {
    const targetPath = rootRelative(startDir, options.add);
    const manifestObject = core.readManifest({ mainPath, manifest: rootObject.manifest });
    console.log(`Adding dependency for ${path.resolve(process.cwd(), targetPath)}`);
    manifestObject.dependencies[util.normalizeToPosix(targetPath)] = coreInit.makeDependencyEntry({
      repoPath: targetPath,
      mainRepoPath: mainPath,
    });
    fsX.writeJsonSync(manifestPath, manifestObject, { spaces: 2 });
  } else if (options.delete) {
    const targetPath = rootRelative(startDir, options.delete);
    const manifestObject = core.readManifest({ mainPath, manifest: rootObject.manifest });
    if (manifestObject.dependencies[targetPath] === undefined) {
      util.terminate(`No manifest dependency for: ${targetPath}`);
    }
    delete manifestObject.dependencies[targetPath];
    fsX.writeJsonSync(manifestPath, manifestObject, { spaces: 2 });
    console.log(`Deleted manifest dependency for ${targetPath}`);
  } else {
    // Do something vaguelu useful, like `fab root` and `fab main`
    console.log(manifestPath);
  }
  process.chdir(startDir);
}


{'fraction_non_alphanumeric': 0.13663890991672975, 'fraction_numerical': 0.001514004542013626, 'mean_word_length': 4.551470588235294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1264859', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1496, 'n_words': 365}