"use strict";

const panther = require("panther-engine");
const config = require("./config");

const availableCommands = ["build-local", "build-staging", "build-production", "serve", "launch", "test-sass", "print-font-data"];

// Determine which CLI command was run and perform the appropriate action

if (process.argv) {
  const args = process.argv.slice(2);
  if (!args[0] || !availableCommands.includes(args[0])) {
    process.exit();
  }
  // Modify some of the Panther Engine configuration settings when
  // doing a staging or production build of the pattern library website
  if (args[0] === "build-staging") {
    config.environment = "staging";
    config.basePath = "/ux-pattern-library-staging";
  }
  if (args[0] === "build-production") {
    config.environment = "production";
    config.basePath = "/ux-pattern-library";
  }
  panther.init(config);

  switch (args[0]) {
    case "build-local":
    case "build-staging":
    case "build-production":
      panther.build();
      break;
    case "serve":
      panther.serve();
      break;
    case "launch":
      panther.launch();
      break;
    case "test-sass":
      panther.testSASS()
        .then(() => {
          process.exit(0);
        })
        .catch(() => {
          process.exit(1);
        });
      break;
    case "print-font-data":
      // Print font metadata (for debugging purposes)
      panther.printFontData();
      break;
  }
}
