Skip to content

Commit 2f63838

Browse files
committed
Update to simplified us dates, added local development file reading
1 parent 4eb861b commit 2f63838

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

  • apps/backend/src/app/api/latest/internal/changelog

apps/backend/src/app/api/latest/internal/changelog/route.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler";
22
import { yupArray, yupBoolean, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields";
3-
import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env";
3+
import { getEnvVariable, getNodeEnvironment } from "@stackframe/stack-shared/dist/utils/env";
4+
import * as fs from "fs/promises";
5+
import * as path from "path";
46

57
const REVALIDATE_SECONDS = 60 * 60;
68

@@ -72,10 +74,9 @@ function parseRootChangelog(markdown: string): ChangelogEntry[] {
7274

7375
const heading = versionMatch[1].trim();
7476
const { version, releasedAt, isUnreleased } = parseVersionHeading(heading);
75-
const isSemver = /^\d+\.\d+\.\d+$/.test(version);
76-
const isCalVer = /^\d{4}\.\d{2}\.\d{2}$/.test(version);
77+
const isUsDate = /^\d{1,2}\/\d{1,2}\/\d{2}$/.test(version); // US date format: M/D/YY
7778

78-
if (!isUnreleased && !isSemver && !isCalVer) {
79+
if (!isUnreleased && !isUsDate) {
7980
continue;
8081
}
8182

@@ -138,6 +139,25 @@ export const GET = createSmartRouteHandler({
138139
}).defined(),
139140
}),
140141
handler: async () => {
142+
const isDevelopment = getNodeEnvironment() === "development";
143+
144+
// In development mode, read from local CHANGELOG.md file
145+
if (isDevelopment) {
146+
const changelogPath = path.resolve(process.cwd(), "../../CHANGELOG.md");
147+
const fileExists = await fs.access(changelogPath).then(() => true, () => false);
148+
149+
if (fileExists) {
150+
const content = await fs.readFile(changelogPath, "utf-8");
151+
const entries = parseRootChangelog(content).slice(0, 8);
152+
153+
return {
154+
statusCode: 200,
155+
bodyType: "json",
156+
body: { entries },
157+
} as const;
158+
}
159+
}
160+
141161
const changelogUrl = getEnvVariable("STACK_CHANGELOG_URL", "");
142162

143163
if (!changelogUrl) {

0 commit comments

Comments
 (0)