"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildComposeFile = buildComposeFile;
exports.defaultEnvInput = defaultEnvInput;
exports.ensureProjectFiles = ensureProjectFiles;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const env_loader_1 = require("./env-loader");
const path_helpers_1 = require("./path-helpers");
function buildComposeFile() {
    return `services:
  runestone:
    image: \${RUNESTONE_IMAGE:-cymondez/runestone}:\${RUNESTONE_TAG:-5.2}
    container_name: \${PREFIX:-runestone}
    restart: unless-stopped
    command: |-
      --providers.docker.network="\${PREFIX:-runestone}-network"
    environment:
      HOST_DOMAIN: \${HOST_DOMAIN:-local.developers-homelab.net}
      MAILPIT_HOST: mailpit.\${HOST_DOMAIN:-local.developers-homelab.net}
      TRAEFIK_HOST: traefik.\${HOST_DOMAIN:-local.developers-homelab.net}
      WEB_ENTRYPOINT_NAME: \${WEB_ENTRYPOINT_NAME:-web}
      WEB_ENTRYPOINT_PORT: \${WEB_ENTRYPOINT_PORT:-80}
      WEB_SECURE_ENTRYPOINT_NAME: \${WEB_SECURE_ENTRYPOINT_NAME:-websecure}
      WEB_SECURE_ENTRYPOINT_PORT: \${WEB_SECURE_ENTRYPOINT_PORT:-443}
      PREFIX: \${PREFIX:-runestone}
    ports:
      - "\${WEB_ENTRYPOINT_PORT:-80}:\${WEB_ENTRYPOINT_PORT:-80}"
      - "\${WEB_SECURE_ENTRYPOINT_PORT:-443}:\${WEB_SECURE_ENTRYPOINT_PORT:-443}"
      - "\${SMTP_PORT:-1025}:1025"
    extra_hosts:
      - host.docker.internal:host-gateway
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./certs:/ssl
      - ./configuration:/configuration
      - ssh:/tmp/druid_ssh-agent/

networks:
  default:
    name: \${PREFIX:-runestone}-network
    external: true

volumes:
  ssh:
    name: \${PREFIX:-runestone}-ssh
    external: true
`;
}
function defaultEnvInput() {
    return { ...env_loader_1.DEFAULT_ENV };
}
function ensureProjectFiles(config, options) {
    path_helpers_1.pathHelpers.ensureDir(config.PROJECT_DIR);
    path_helpers_1.pathHelpers.ensureDir(path.join(config.PROJECT_DIR, 'certs'));
    path_helpers_1.pathHelpers.ensureDir(path.join(config.PROJECT_DIR, 'configuration'));
    if (!fs.existsSync(config.ENV_PATH)) {
        env_loader_1.envLoader.write(config.ENV_PATH, defaultEnvInput());
    }
    if (options?.overwriteCompose || !fs.existsSync(config.COMPOSE_FILE_PATH)) {
        fs.writeFileSync(config.COMPOSE_FILE_PATH, buildComposeFile(), 'utf8');
    }
}
//# sourceMappingURL=project-files.js.map