import { relative, resolve } from "node:path"; import { fileURLToPath } from "node:url"; export const REPOSITORY_ROOT = fileURLToPath(new URL("../../../../..", import.meta.url)); export function miniappArtifactRoot(configured = process.env.MINIAPP_ARTIFACT_ROOT): string { return configured ? resolve(REPOSITORY_ROOT, configured) : resolve(REPOSITORY_ROOT, "apps/taro/dist"); } export function miniappProjectPath(templatePackageKey: string): string { return resolve(miniappArtifactRoot(), templatePackageKey, "weapp"); } export function miniappReleaseOutputRoot( brandSlug: string, templateKey: string, templateVersion: string, attemptId: string, ): string { for (const [label, value] of [ ["brand slug", brandSlug], ["template key", templateKey], ["template version", templateVersion], ["attempt id", attemptId], ] as const) { if (!/^[a-zA-Z0-9._-]+$/.test(value)) throw new Error(`Invalid ${label} for miniapp artifact path`); } return resolve( miniappArtifactRoot(), "releases", brandSlug, `${templateKey}@${templateVersion}`, attemptId, ); } export function miniappReleaseProjectPath( brandSlug: string, templateKey: string, templateVersion: string, attemptId: string, ): string { return resolve( miniappReleaseOutputRoot(brandSlug, templateKey, templateVersion, attemptId), "weapp", ); } export function miniappTaroOutputRoot(outputRoot: string): string { return relative(resolve(REPOSITORY_ROOT, "apps/taro"), outputRoot); }