'use strict';

var chunkD5HE46WD_cjs = require('./chunk-D5HE46WD.cjs');
var chunk4UERBOUH_cjs = require('./chunk-4UERBOUH.cjs');
var chunkAF3E2D32_cjs = require('./chunk-AF3E2D32.cjs');
var types = require('@storm-software/config-tools/types');
var helpers = require('@stryke/fs/helpers');
var exists = require('@stryke/path/exists');
var joinPaths = require('@stryke/path/join-paths');
var typedoc = require('typedoc');

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var typedoc__namespace = /*#__PURE__*/_interopNamespace(typedoc);

async function docsApiReference(log, context, hooks) {
  log(types.LogLevelLabel.TRACE, "Writing API-Reference documentation for the Storm Stack project artifacts.");
  const outputPath = joinPaths.joinPaths(context.options.projectRoot, "docs", "generated", "api-reference");
  if (exists.existsSync(outputPath)) {
    await helpers.removeDirectory(outputPath);
  }
  await helpers.createDirectory(outputPath);
  const app = await typedoc__namespace.Application.bootstrapWithPlugins({
    plugin: [
      "typedoc-plugin-markdown",
      "typedoc-plugin-frontmatter",
      "@storm-stack/core/helpers/typedoc"
    ],
    theme: "storm-stack",
    hideGenerator: true,
    readme: "none",
    excludePrivate: true,
    gitRevision: context.workspaceConfig.branch || "main",
    entryPoints: context.entry.map((entry) => joinPaths.joinPaths(context.options.projectRoot, entry.file)),
    tsconfig: context.options.tsconfig,
    exclude: context.tsconfig?.raw?.exclude,
    out: outputPath
  }, [
    new typedoc__namespace.TypeDocReader(),
    new typedoc__namespace.PackageJsonReader(),
    new typedoc__namespace.TSConfigReader()
  ]);
  const project = await app.convert();
  if (project) {
    await app.generateDocs(project, outputPath);
  }
  await hooks.callHook("docs:api-reference", context).catch((error) => {
    log(types.LogLevelLabel.ERROR, `An error occured while writing the API-Reference documentation for the Storm Stack project artifacts: ${error.message} 
${error.stack ?? ""}`);
    throw new Error("An error occured while writing the API-Reference documentation for the Storm Stack project artifacts", {
      cause: error
    });
  });
}
chunkAF3E2D32_cjs.__name(docsApiReference, "docsApiReference");
async function docsDotenv(log, context, hooks) {
  log(types.LogLevelLabel.TRACE, "Writing Dotenv documentation for the Storm Stack project artifacts.");
  const outputPath = joinPaths.joinPaths(context.options.projectRoot, "docs", "generated");
  if (!exists.existsSync(outputPath)) {
    await helpers.createDirectory(outputPath);
  }
  const vars = await chunkD5HE46WD_cjs.resolveDotenvProperties(log, context, "variables");
  const dotenvDocFile = joinPaths.joinPaths(outputPath, "dotenv.md");
  log(types.LogLevelLabel.TRACE, `Documenting environment variables configuration in "${dotenvDocFile}"`);
  await chunk4UERBOUH_cjs.writeFile(log, dotenvDocFile, `<!-- Generated by Storm Stack -->

# Environment variables configuration

Below is a list of environment variables used by the [${context.packageJson.name}](https://www.npmjs.com/package/${context.packageJson.name}) package. These values can be updated in the \`.env\` file in the root of the project.

## Variables

The below list of environment variables are used as configuration parameters to drive the processing of the application. The data contained in these variables are **not** considered sensitive or confidential. Any values provided in these variables will be available in plain text to the public.

| Name | Description | Type | Default Value | Required |
| ---- | ----------- | ---- | ------------- | :------: |
${vars.filter((property) => property.getNameAsString() !== "__STORM_INJECTED__").sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())).map((reflectionProperty) => {
    return `| ${reflectionProperty.getNameAsString().trim()} | ${(reflectionProperty.getDescription()?.replaceAll("\r", "")?.replaceAll("\n", "") ?? "").trim()} | ${(void 0)(reflectionProperty.getType()).trim().replaceAll(" | ", ", or ")} | ${reflectionProperty.hasDefault() ? String(reflectionProperty.getDefaultValue())?.includes('"') ? reflectionProperty.getDefaultValue() : `\`${reflectionProperty.getDefaultValue()}\`` : ""} | ${reflectionProperty.isValueRequired() ? "" : "\u2714"} |`;
  }).join("\n")}
`);
  await hooks.callHook("docs:dotenv", context).catch((error) => {
    log(types.LogLevelLabel.ERROR, `An error occured while writing the Dotenv documentation for the Storm Stack project artifacts: ${error.message} 
${error.stack ?? ""}`);
    throw new Error("An error occured while writing the Dotenv documentation for the Storm Stack project artifacts", {
      cause: error
    });
  });
}
chunkAF3E2D32_cjs.__name(docsDotenv, "docsDotenv");

// src/docs/index.ts
async function docs(log, context, hooks) {
  await hooks.callHook("docs:begin", context).catch((error) => {
    log(types.LogLevelLabel.ERROR, `An error occured while starting to generate documentation for the Storm Stack project: ${error.message} 
${error.stack ?? ""}`);
    throw new Error("An error occured while starting to generate documentation for the Storm Stack project", {
      cause: error
    });
  });
  await docsDotenv(log, context, hooks);
  await docsApiReference(log, context, hooks);
  await hooks.callHook("docs:complete", context).catch((error) => {
    log(types.LogLevelLabel.ERROR, `An error occured while finishing generation of documentation for the Storm Stack project: ${error.message} 
${error.stack ?? ""}`);
    throw new Error("An error occured while finishing generation of documentation for the Storm Stack project", {
      cause: error
    });
  });
}
chunkAF3E2D32_cjs.__name(docs, "docs");

exports.docs = docs;
//# sourceMappingURL=chunk-5S276M22.cjs.map
//# sourceMappingURL=chunk-5S276M22.cjs.map