<commit_before>module.exports = function (grunt) {
  "use strict";

  var log = require("../gruntLogHelper.js")(grunt);
  var fs = require("fs");
  var _ = require("lodash");
  _.defaultsDeep = require("merge-defaults"); // Add deep defaults capabilities to lodash

  var npmPath = "./node_modules/";
  var packageName = "patternpack";
  var packagePath = npmPath + packageName;
  var gruntTaskName = "patternpack";
  var gruntTaskDescription = "Creates a pattern library from structured markdown and styles.";
  var optionDefaults = {
    // Paths for input and output
    release: "./dist",
    build: "./html",
    src: "./src",
    assets: "./src/assets",
    theme: npmPath + "patternpack-example-theme",

    // Operation to run (default|build|release)
    // TODO: consider using a flag for the "MODE" of operation (dev|build|release)
    // task: "build",

    // TODO: Implement the ability to only publish certain resources (css|library|patterns)
    publish: {
      library: true,
      patterns: false
    },
    patternStructure: [
      { name: "Atoms", path: "atoms" },
      { name: "Molecules", path: "molecules" },
      { name: "Pages", path: "pages" }
    ]
  };

  function getPackagePathOrFallbackPath(path) {
    var validatedPath;
    var pathOfPackage = npmPath + path;

    if (fs.existsSync(pathOfPackage)) {
      validatedPath = pathOfPackage;
    } else if (fs.existsSync(path)) {
      validatedPath = path;
    } else {
      throw new Error("Could not be find: " + pathOfPackage + " or " + path);
    }
    return validatedPath;
  }

  function setupOptions(context) {
    var path = require("path");
    var optionOverrides = context.options();

    // If the task is named build or release then use it as the default value.
    // Otherwise leave the task blank, which will result in "default" being called
    if (context.target === "build" || context.target === "release") {
      optionDefaults.task = context.target;
    }

    // Override the defaults with any user specified options
    var options = _.defaultsDeep(_.cloneDeep(optionOverrides), optionDefaults);

    // Add the relative path to the root of the calling pattern library
    options.root = path.relative(packagePath, "");

    // Massage any paths to be relative to the child process
    options.release = path.relative(packagePath, options.release);
    options.build = path.relative(packagePath, options.build);
    options.src = path.relative(packagePath, options.src);
    options.assets = path.relative(packagePath, options.assets);

    // Resolve the theme path either from a path or from a package name
    if (optionOverrides.theme) {
      optionOverrides.theme = getPackagePathOrFallbackPath(optionOverrides.theme);
    }
    log.verbose("Theme paths");
    log.verbose("Default: " + optionDefaults.theme);
    log.verbose("Override: " + optionOverrides.theme);

    // If the pattern is specified by the user then get the relative path,
    // otherwise use the path inside pattern pack to provide the default patterns.
    options.theme = optionOverrides.theme ? path.relative(packagePath, optionOverrides.theme) : optionDefaults.theme;
    log.verbose("Resolved: " + options.theme);

    return options;
  }

  function saveOptions(options) {
    var file = packagePath + "/gruntfileConfig.json";
    var contents = JSON.stringify(options);
    grunt.file.write(file, contents);
  }

  function gruntPatternPackTask() {
    var done = this.async();

    // Ensure that the packagePath exists.
    // TODO: Figure out how to abstract this path creation.  It is also used in the gruntRunner.js
    if (!fs.existsSync(packagePath)) {
      throw new Error("The path to the pattern pack dependency does not exists at: " + packagePath);
    }

    // Get the options
    var options = setupOptions(this);
    log.verbose("PatternPack options:");
    log.verbose(options);

    // Ensure the task is set properly
    if (options.task && options.task !== "" && options.task !== "default" && options.task !== "build" && options.task !== "release") {
      log.log(options);
      throw new Error('When specified options.task must be one of the following values: "", "default", "build", "release"');
    }

    // Save the options
    // Since I haven"t figured out how to pass the options from the command
    // save the options to a file that can then be used by the child grunt task.
    saveOptions(options);
    // TODO: FIX THIS.  Pass the options to the command!

    // Create the options required to run the child grunt process
    var gruntRunner = require("../gruntRunner.js")(grunt);
    var gruntRunnerOptions = {
      name: packageName,
      tasks: options.task,
      flags: grunt.option.flags()
    };

    log.verbose("PatternPack configured to run:");
    log.verbose(gruntRunnerOptions);
    log.verbose("PatternPack running...");
    gruntRunner.run(gruntRunnerOptions, done);
  }

  grunt.registerMultiTask(gruntTaskName, gruntTaskDescription, gruntPatternPackTask);
};
<commit_msg>Updated list of allowed tasks<commit_after>module.exports = function (grunt) {
  "use strict";

  var log = require("../gruntLogHelper.js")(grunt);
  var fs = require("fs");
  var _ = require("lodash");
  _.defaultsDeep = require("merge-defaults"); // Add deep defaults capabilities to lodash

  var npmPath = "./node_modules/";
  var packageName = "patternpack";
  var packagePath = npmPath + packageName;
  var allowedTasks = ["", "default", "build", "release", "release-patch", "release-minor", "release-major"];
  var gruntTaskName = "patternpack";
  var gruntTaskDescription = "Creates a pattern library from structured markdown and styles.";
  var optionDefaults = {
    // Paths for input and output
    release: "./dist",
    build: "./html",
    src: "./src",
    assets: "./src/assets",
    theme: npmPath + "patternpack-example-theme",

    // Operation to run (default|build|release)
    // TODO: consider using a flag for the "MODE" of operation (dev|build|release)
    // task: "build",

    // TODO: Implement the ability to only publish certain resources (css|library|patterns)
    publish: {
      library: true,
      patterns: false
    },
    patternStructure: [
      { name: "Atoms", path: "atoms" },
      { name: "Molecules", path: "molecules" },
      { name: "Pages", path: "pages" }
    ]
  };

  function getPackagePathOrFallbackPath(path) {
    var validatedPath;
    var pathOfPackage = npmPath + path;

    if (fs.existsSync(pathOfPackage)) {
      validatedPath = pathOfPackage;
    } else if (fs.existsSync(path)) {
      validatedPath = path;
    } else {
      throw new Error("Could not be find: " + pathOfPackage + " or " + path);
    }
    return validatedPath;
  }

  function setupOptions(context) {
    var path = require("path");
    var optionOverrides = context.options();

    // If the task is allowed then use it as the default value.
    // Otherwise leave the task blank, which will result in "default" being called
    if (_.contains(allowedTasks, context.target)) {
      optionDefaults.task = context.target;
    }

    // Override the defaults with any user specified options
    var options = _.defaultsDeep(_.cloneDeep(optionOverrides), optionDefaults);

    // Add the relative path to the root of the calling pattern library
    options.root = path.relative(packagePath, "");

    // Massage any paths to be relative to the child process
    options.release = path.relative(packagePath, options.release);
    options.build = path.relative(packagePath, options.build);
    options.src = path.relative(packagePath, options.src);
    options.assets = path.relative(packagePath, options.assets);

    // Resolve the theme path either from a path or from a package name
    if (optionOverrides.theme) {
      optionOverrides.theme = getPackagePathOrFallbackPath(optionOverrides.theme);
    }
    log.verbose("Theme paths");
    log.verbose("Default: " + optionDefaults.theme);
    log.verbose("Override: " + optionOverrides.theme);

    // If the pattern is specified by the user then get the relative path,
    // otherwise use the path inside pattern pack to provide the default patterns.
    options.theme = optionOverrides.theme ? path.relative(packagePath, optionOverrides.theme) : optionDefaults.theme;
    log.verbose("Resolved: " + options.theme);

    return options;
  }

  function saveOptions(options) {
    var file = packagePath + "/gruntfileConfig.json";
    var contents = JSON.stringify(options);
    grunt.file.write(file, contents);
  }

  function gruntPatternPackTask() {
    var done = this.async();

    // Ensure that the packagePath exists.
    // TODO: Figure out how to abstract this path creation.  It is also used in the gruntRunner.js
    if (!fs.existsSync(packagePath)) {
      throw new Error("The path to the pattern pack dependency does not exists at: " + packagePath);
    }

    // Get the options
    var options = setupOptions(this);
    log.verbose("PatternPack options:");
    log.verbose(options);

    // Ensure the task is set properly
    if(!_.contains(allowedTasks, options.task || "")) {
      log.log(options);
      log.log("Allowed tasks:");
      log.log(allowedTasks);
      throw new Error("When specified options.task must be an allowed task.");
    }

    // Save the options
    // Since I haven"t figured out how to pass the options from the command
    // save the options to a file that can then be used by the child grunt task.
    saveOptions(options);
    // TODO: FIX THIS.  Pass the options to the command!

    // Create the options required to run the child grunt process
    var gruntRunner = require("../gruntRunner.js")(grunt);
    var gruntRunnerOptions = {
      name: packageName,
      tasks: options.task,
      flags: grunt.option.flags()
    };

    log.verbose("PatternPack configured to run:");
    log.verbose(gruntRunnerOptions);
    log.verbose("PatternPack running...");
    gruntRunner.run(gruntRunnerOptions, done);
  }

  grunt.registerMultiTask(gruntTaskName, gruntTaskDescription, gruntPatternPackTask);
};

{'fraction_non_alphanumeric': 0.1163437655240934, 'fraction_numerical': 0.0, 'mean_word_length': 3.2311895754518707, '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': '3266276', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2804, 'n_words': 902}