import { resolveDotenvProperties } from './chunk-HRPQF34B.js';
import { writeFile } from './chunk-4SEZDGHZ.js';
import { __name } from './chunk-6AXVLTU5.js';
import { LogLevelLabel } from '@storm-software/config-tools/types';
import { removeDirectory, createDirectory } from '@stryke/fs/helpers';
import { existsSync } from '@stryke/path/exists';
import { joinPaths } from '@stryke/path/join-paths';
import * as typedoc from 'typedoc';

async function docsApiReference(log, context, hooks) {
  log(LogLevelLabel.TRACE, "Writing API-Reference documentation for the Storm Stack project artifacts.");
  const outputPath = joinPaths(context.options.projectRoot, "docs", "generated", "api-reference");
  if (existsSync(outputPath)) {
    await removeDirectory(outputPath);
  }
  await createDirectory(outputPath);
  const app = await typedoc.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(context.options.projectRoot, entry.file)),
    tsconfig: context.options.tsconfig,
    exclude: context.tsconfig?.raw?.exclude,
    out: outputPath
  }, [
    new typedoc.TypeDocReader(),
    new typedoc.PackageJsonReader(),
    new typedoc.TSConfigReader()
  ]);
  const project = await app.convert();
  if (project) {
    await app.generateDocs(project, outputPath);
  }
  await hooks.callHook("docs:api-reference", context).catch((error) => {
    log(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
    });
  });
}
__name(docsApiReference, "docsApiReference");
async function docsDotenv(log, context, hooks) {
  log(LogLevelLabel.TRACE, "Writing Dotenv documentation for the Storm Stack project artifacts.");
  const outputPath = joinPaths(context.options.projectRoot, "docs", "generated");
  if (!existsSync(outputPath)) {
    await createDirectory(outputPath);
  }
  const vars = await resolveDotenvProperties(log, context, "variables");
  const dotenvDocFile = joinPaths(outputPath, "dotenv.md");
  log(LogLevelLabel.TRACE, `Documenting environment variables configuration in "${dotenvDocFile}"`);
  await 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(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
    });
  });
}
__name(docsDotenv, "docsDotenv");

// src/docs/index.ts
async function docs(log, context, hooks) {
  await hooks.callHook("docs:begin", context).catch((error) => {
    log(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(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
    });
  });
}
__name(docs, "docs");

export { docs };
//# sourceMappingURL=chunk-S6TMD2NR.js.map
//# sourceMappingURL=chunk-S6TMD2NR.js.map