import { getDotenvReflectionsPath, getDotenvPath } from './chunk-HRPQF34B.js';
import { writeFile } from './chunk-4SEZDGHZ.js';
import { __name } from './chunk-6AXVLTU5.js';
import { readJsonFile } from '@stryke/fs/read-file';
import { StormJSON } from '@stryke/json/storm-json';
import { existsSync } from '@stryke/path/exists';

async function writeDotenvReflection(log, context, reflection, name) {
  let reflectionObjectLiteral = (void 0).from({
    kind: (void 0).objectLiteral,
    description: `An object containing the dotenv variables used by the ${context.options.name ? `${context.options.name} application` : "application"}.`,
    types: []
  });
  const varsFilePath = getDotenvReflectionsPath(context, name);
  if (existsSync(varsFilePath)) {
    reflectionObjectLiteral = (void 0)((void 0)(await readJsonFile(varsFilePath)));
  }
  reflection.getProperties().map((prop) => {
    if (!reflectionObjectLiteral.hasProperty(prop.getName())) {
      reflectionObjectLiteral.addProperty(prop.property);
    }
  });
  const serialized = reflectionObjectLiteral.serializeType();
  return writeFile(log, getDotenvReflectionsPath(context, name), StormJSON.stringify(serialized));
}
__name(writeDotenvReflection, "writeDotenvReflection");
async function writeDotenvProperties(log, context, name, properties) {
  const varsFilePath = getDotenvPath(context, name);
  let reflectionObjectLiteral = (void 0).from({
    kind: (void 0).objectLiteral,
    description: `An object containing the dotenv variables used by the ${context.options.name ? `${context.options.name} application` : "application"}.`,
    types: []
  });
  if (existsSync(varsFilePath)) {
    reflectionObjectLiteral = (void 0)((void 0)(await readJsonFile(varsFilePath)));
  }
  properties.map((prop) => {
    if (!reflectionObjectLiteral.hasProperty(prop.getName())) {
      reflectionObjectLiteral.addProperty(prop.property);
    }
  });
  await writeFile(log, varsFilePath, StormJSON.stringify(reflectionObjectLiteral.serializeType()));
}
__name(writeDotenvProperties, "writeDotenvProperties");

export { writeDotenvProperties, writeDotenvReflection };
//# sourceMappingURL=chunk-CBI6CPYK.js.map
//# sourceMappingURL=chunk-CBI6CPYK.js.map