"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// ../config-tools/src/logger/console.ts
var _formatDistanceToNow = require('date-fns/formatDistanceToNow');

// ../config-tools/src/types.ts
var LogLevel = {
  SILENT: 0,
  FATAL: 10,
  ERROR: 20,
  WARN: 30,
  SUCCESS: 35,
  INFO: 40,
  PERFORMANCE: 50,
  DEBUG: 60,
  TRACE: 70,
  ALL: 100
};
var LogLevelLabel = {
  SILENT: "silent",
  FATAL: "fatal",
  ERROR: "error",
  WARN: "warn",
  SUCCESS: "success",
  INFO: "info",
  PERFORMANCE: "performance",
  DEBUG: "debug",
  TRACE: "trace",
  ALL: "all"
};

// ../config-tools/src/utilities/colors.ts
var DEFAULT_COLOR_CONFIG = {
  light: {
    background: "#fafafa",
    foreground: "#1d1e22",
    brand: "#1fb2a6",
    alternate: "#db2777",
    help: "#5C4EE5",
    success: "#087f5b",
    info: "#0550ae",
    debug: "#8afafc",
    warning: "#e3b341",
    danger: "#D8314A",
    fatal: "#51070f",
    performance: "#13c302",
    link: "#3fa6ff",
    positive: "#22c55e",
    negative: "#dc2626",
    gradient: ["#1fb2a6", "#db2777", "#5C4EE5"]
  },
  dark: {
    background: "#1d1e22",
    foreground: "#cbd5e1",
    brand: "#2dd4bf",
    alternate: "#db2777",
    help: "#818cf8",
    success: "#10b981",
    info: "#58a6ff",
    debug: "#8afafc",
    warning: "#f3d371",
    danger: "#D8314A",
    fatal: "#a40e26",
    performance: "#80fd74",
    link: "#3fa6ff",
    positive: "#22c55e",
    negative: "#dc2626",
    gradient: ["#1fb2a6", "#db2777", "#818cf8"]
  }
};
function getColors(config) {
  if (!_optionalChain([config, 'optionalAccess', _2 => _2.colors]) || typeof config.colors !== "object" || !config.colors["dark"] && (!config.colors["base"] || typeof config.colors !== "object" || !_optionalChain([config, 'access', _3 => _3.colors, 'access', _4 => _4["base"], 'optionalAccess', _5 => _5["dark"]]))) {
    return DEFAULT_COLOR_CONFIG;
  }
  if (config.colors["base"]) {
    if (typeof config.colors["base"]["dark"] === "object") {
      return config.colors["base"]["dark"];
    } else if (config.colors["base"]["dark"] === "string") {
      return config.colors["base"];
    }
  }
  if (typeof config.colors["dark"] === "object") {
    return config.colors["dark"];
  }
  return _nullishCoalesce(config.colors, () => ( DEFAULT_COLOR_CONFIG));
}
function getColor(key, config) {
  const colors = getColors(config);
  const result = (typeof colors["dark"] === "object" ? colors["dark"][key] : colors[key]) || DEFAULT_COLOR_CONFIG["dark"][key] || DEFAULT_COLOR_CONFIG[key];
  if (result) {
    return result;
  }
  if (key === "link" || key === "debug") {
    return getColor("info", config);
  } else if (key === "fatal") {
    return getColor("danger", config);
  }
  return getColor("brand", config);
}

// ../config-tools/src/logger/chalk.ts
var _chalk2 = require('chalk'); var _chalk3 = _interopRequireDefault(_chalk2);
var chalkDefault = {
  hex: (_) => (message) => message,
  bgHex: (_) => ({
    whiteBright: (message) => message,
    white: (message) => message
  }),
  white: (message) => message,
  whiteBright: (message) => message,
  gray: (message) => message,
  bold: {
    hex: (_) => (message) => message,
    bgHex: (_) => ({
      whiteBright: (message) => message,
      white: (message) => message
    }),
    whiteBright: (message) => message,
    white: (message) => message
  },
  dim: {
    hex: (_) => (message) => message,
    gray: (message) => message
  }
};
var getChalk = () => {
  let _chalk = _chalk3.default;
  if (!_optionalChain([_chalk, 'optionalAccess', _6 => _6.hex]) || !_optionalChain([_chalk, 'optionalAccess', _7 => _7.bold, 'optionalAccess', _8 => _8.hex]) || !_optionalChain([_chalk, 'optionalAccess', _9 => _9.bgHex]) || !_optionalChain([_chalk, 'optionalAccess', _10 => _10.whiteBright]) || !_optionalChain([_chalk, 'optionalAccess', _11 => _11.white])) {
    _chalk = chalkDefault;
  }
  return _chalk;
};

// ../config-tools/src/logger/is-unicode-supported.ts
function isUnicodeSupported() {
  if (process.platform !== "win32") {
    return process.env.TERM !== "linux";
  }
  return Boolean(process.env.WT_SESSION) || // Windows Terminal
  Boolean(process.env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
  process.env.ConEmuTask === "{cmd::Cmder}" || // ConEmu and cmder
  process.env.TERM_PROGRAM === "Terminus-Sublime" || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty" || process.env.TERM === "rxvt-unicode" || process.env.TERM === "rxvt-unicode-256color" || process.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
}

// ../config-tools/src/logger/console-icons.ts
var useIcon = (c, fallback) => isUnicodeSupported() ? c : fallback;
var CONSOLE_ICONS = {
  [LogLevelLabel.ERROR]: useIcon("\u2718", "\xD7"),
  [LogLevelLabel.FATAL]: useIcon("\u{1F571}", "\xD7"),
  [LogLevelLabel.WARN]: useIcon("\u26A0", "\u203C"),
  [LogLevelLabel.INFO]: useIcon("\u2139", "i"),
  [LogLevelLabel.PERFORMANCE]: useIcon("\u23F1", "\u23F1"),
  [LogLevelLabel.SUCCESS]: useIcon("\u2714", "\u221A"),
  [LogLevelLabel.DEBUG]: useIcon("\u{1F6E0}", "D"),
  [LogLevelLabel.TRACE]: useIcon("\u2699", "T"),
  [LogLevelLabel.ALL]: useIcon("\u2709", "\u2192")
};

// ../config-tools/src/logger/format-timestamp.ts
var formatTimestamp = (fullDateTime = false, date = /* @__PURE__ */ new Date()) => {
  return fullDateTime ? `${date.toLocaleDateString()} ${date.toLocaleTimeString()}` : `${date.toLocaleTimeString()}`;
};

// ../config-tools/src/logger/get-log-level.ts
var getLogLevel = (label) => {
  switch (label) {
    case "all":
      return LogLevel.ALL;
    case "trace":
      return LogLevel.TRACE;
    case "debug":
      return LogLevel.DEBUG;
    case "performance":
      return LogLevel.PERFORMANCE;
    case "info":
      return LogLevel.INFO;
    case "warn":
      return LogLevel.WARN;
    case "error":
      return LogLevel.ERROR;
    case "fatal":
      return LogLevel.FATAL;
    case "silent":
      return LogLevel.SILENT;
    default:
      return LogLevel.INFO;
  }
};
var getLogLevelLabel = (logLevel = LogLevel.INFO) => {
  if (logLevel >= LogLevel.ALL) {
    return LogLevelLabel.ALL;
  }
  if (logLevel >= LogLevel.TRACE) {
    return LogLevelLabel.TRACE;
  }
  if (logLevel >= LogLevel.DEBUG) {
    return LogLevelLabel.DEBUG;
  }
  if (logLevel >= LogLevel.PERFORMANCE) {
    return LogLevelLabel.PERFORMANCE;
  }
  if (logLevel >= LogLevel.INFO) {
    return LogLevelLabel.INFO;
  }
  if (logLevel >= LogLevel.WARN) {
    return LogLevelLabel.WARN;
  }
  if (logLevel >= LogLevel.ERROR) {
    return LogLevelLabel.ERROR;
  }
  if (logLevel >= LogLevel.FATAL) {
    return LogLevelLabel.FATAL;
  }
  if (logLevel <= LogLevel.SILENT) {
    return LogLevelLabel.SILENT;
  }
  return LogLevelLabel.INFO;
};

// ../config-tools/src/logger/console.ts
var getLogFn = (logLevel = LogLevel.INFO, config = {}, options = {}) => {
  const {
    chalk: _chalk = getChalk(),
    fullDateTime = false,
    hideDateTime = false
  } = options;
  const colors = !_optionalChain([config, 'access', _12 => _12.colors, 'optionalAccess', _13 => _13.dark]) && !_optionalChain([config, 'access', _14 => _14.colors, 'optionalAccess', _15 => _15["base"]]) && !_optionalChain([config, 'access', _16 => _16.colors, 'optionalAccess', _17 => _17["base"], 'optionalAccess', _18 => _18.dark]) ? DEFAULT_COLOR_CONFIG : _optionalChain([config, 'access', _19 => _19.colors, 'optionalAccess', _20 => _20.dark]) && typeof config.colors.dark === "string" ? config.colors : _optionalChain([config, 'access', _21 => _21.colors, 'optionalAccess', _22 => _22["base"], 'optionalAccess', _23 => _23.dark]) && typeof config.colors["base"].dark === "string" ? config.colors["base"].dark : _optionalChain([config, 'access', _24 => _24.colors, 'optionalAccess', _25 => _25["base"]]) ? _optionalChain([config, 'access', _26 => _26.colors, 'optionalAccess', _27 => _27["base"]]) : DEFAULT_COLOR_CONFIG;
  const configLogLevel = config.logLevel || process.env.STORM_LOG_LEVEL || LogLevelLabel.INFO;
  if (logLevel > getLogLevel(configLogLevel) || logLevel <= LogLevel.SILENT || getLogLevel(configLogLevel) <= LogLevel.SILENT) {
    return (_) => {
    };
  }
  if (typeof logLevel === "number" && LogLevel.FATAL >= logLevel) {
    return (message) => {
      console.error(
        `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex(_nullishCoalesce(colors.fatal, () => ( DEFAULT_COLOR_CONFIG.dark.fatal)))(
          `[${CONSOLE_ICONS[LogLevelLabel.FATAL]} Fatal] `
        )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
      );
    };
  }
  if (typeof logLevel === "number" && LogLevel.ERROR >= logLevel) {
    return (message) => {
      console.error(
        `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex(_nullishCoalesce(colors.danger, () => ( DEFAULT_COLOR_CONFIG.dark.danger)))(
          `[${CONSOLE_ICONS[LogLevelLabel.ERROR]} Error] `
        )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
      );
    };
  }
  if (typeof logLevel === "number" && LogLevel.WARN >= logLevel) {
    return (message) => {
      console.warn(
        `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex(_nullishCoalesce(colors.warning, () => ( DEFAULT_COLOR_CONFIG.dark.warning)))(
          `[${CONSOLE_ICONS[LogLevelLabel.WARN]} Warn] `
        )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
      );
    };
  }
  if (typeof logLevel === "number" && LogLevel.SUCCESS >= logLevel) {
    return (message) => {
      console.info(
        `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex(_nullishCoalesce(colors.success, () => ( DEFAULT_COLOR_CONFIG.dark.success)))(
          `[${CONSOLE_ICONS[LogLevelLabel.SUCCESS]} Success] `
        )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
      );
    };
  }
  if (typeof logLevel === "number" && LogLevel.INFO >= logLevel) {
    return (message) => {
      console.info(
        `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex(_nullishCoalesce(colors.info, () => ( DEFAULT_COLOR_CONFIG.dark.info)))(
          `[${CONSOLE_ICONS[LogLevelLabel.INFO]} Info] `
        )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
      );
    };
  }
  if (typeof logLevel === "number" && LogLevel.PERFORMANCE >= logLevel) {
    return (message) => {
      console.debug(
        `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex(_nullishCoalesce(colors.performance, () => ( DEFAULT_COLOR_CONFIG.dark.performance)))(
          `[${CONSOLE_ICONS[LogLevelLabel.PERFORMANCE]} Performance] `
        )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
      );
    };
  }
  if (typeof logLevel === "number" && LogLevel.DEBUG >= logLevel) {
    return (message) => {
      console.debug(
        `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex(_nullishCoalesce(colors.debug, () => ( DEFAULT_COLOR_CONFIG.dark.debug)))(
          `[${CONSOLE_ICONS[LogLevelLabel.DEBUG]} Debug] `
        )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
      );
    };
  }
  if (typeof logLevel === "number" && LogLevel.TRACE >= logLevel) {
    return (message) => {
      console.debug(
        `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex("#bbbbbb")(
          `[${CONSOLE_ICONS[LogLevelLabel.TRACE]} Trace] `
        )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
      );
    };
  }
  return (message) => {
    console.log(
      `
${hideDateTime ? "" : `${_chalk.gray(formatTimestamp(fullDateTime))} `}${_chalk.hex(_nullishCoalesce(colors.brand, () => ( DEFAULT_COLOR_CONFIG.dark.brand)))(
        `[${CONSOLE_ICONS[LogLevelLabel.ALL]} System] `
      )}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
    );
  };
};
var writeFatal = (message, config) => getLogFn(LogLevel.FATAL, config)(message);
var writeWarning = (message, config) => getLogFn(LogLevel.WARN, config)(message);
var writeSuccess = (message, config) => getLogFn(LogLevel.SUCCESS, config)(message);
var writePerformance = (message, config) => getLogFn(LogLevel.PERFORMANCE, config)(message);
var writeDebug = (message, config) => getLogFn(LogLevel.DEBUG, config)(message);
var writeTrace = (message, config) => getLogFn(LogLevel.TRACE, config)(message);
var getStopwatch = (name) => {
  const start = /* @__PURE__ */ new Date();
  return () => {
    writePerformance(
      `The${name ? ` ${name}` : ""} process took ${_formatDistanceToNow.formatDistanceToNow.call(void 0, start, {
        includeSeconds: true
      })} to complete`
    );
  };
};
var MAX_DEPTH = 6;
var formatLogMessage = (message, options = {}, depth = 0) => {
  if (depth > MAX_DEPTH) {
    return "<max depth>";
  }
  const prefix = _nullishCoalesce(options.prefix, () => ( "-"));
  const skip = _nullishCoalesce(options.skip, () => ( []));
  return typeof message === "undefined" || message === null || !message && typeof message !== "boolean" ? "<none>" : typeof message === "string" ? message : Array.isArray(message) ? `
${message.map((item, index) => ` ${prefix}> #${index} = ${formatLogMessage(item, { prefix: `${prefix}-`, skip }, depth + 1)}`).join("\n")}` : typeof message === "object" ? `
${Object.keys(message).filter((key) => !skip.includes(key)).map(
    (key) => ` ${prefix}> ${key} = ${_isFunction(message[key]) ? "<function>" : typeof message[key] === "object" ? formatLogMessage(
      message[key],
      { prefix: `${prefix}-`, skip },
      depth + 1
    ) : message[key]}`
  ).join("\n")}` : message;
};
var _isFunction = (value) => {
  try {
    return value instanceof Function || typeof value === "function" || !!(_optionalChain([value, 'optionalAccess', _28 => _28.constructor]) && _optionalChain([value, 'optionalAccess', _29 => _29.call]) && _optionalChain([value, 'optionalAccess', _30 => _30.apply]));
  } catch (e) {
    return false;
  }
};
var brandIcon = (config = {}, _chalk = getChalk()) => _chalk.hex(getColor("brand", config))("\u{1F5F2}");

// src/clean.ts
var _promises = require('fs/promises');
async function clean(name = "TSDown", directory, config) {
  writeDebug(` \u{1F9F9}  Cleaning ${name} output path: ${directory}`, config);
  const stopwatch = getStopwatch(`${name} output clean`);
  await cleanDirectories(name, directory, config);
  stopwatch();
}
async function cleanDirectories(name = "TSDown", directory, config) {
  await _promises.rm.call(void 0, directory, { recursive: true, force: true });
}















exports.LogLevel = LogLevel; exports.getLogLevel = getLogLevel; exports.getLogLevelLabel = getLogLevelLabel; exports.writeFatal = writeFatal; exports.writeWarning = writeWarning; exports.writeSuccess = writeSuccess; exports.writeDebug = writeDebug; exports.writeTrace = writeTrace; exports.getStopwatch = getStopwatch; exports.formatLogMessage = formatLogMessage; exports.brandIcon = brandIcon; exports.clean = clean; exports.cleanDirectories = cleanDirectories;
