|
1 | 1 | import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler"; |
2 | 2 | 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"; |
4 | 6 |
|
5 | 7 | const REVALIDATE_SECONDS = 60 * 60; |
6 | 8 |
|
@@ -72,10 +74,9 @@ function parseRootChangelog(markdown: string): ChangelogEntry[] { |
72 | 74 |
|
73 | 75 | const heading = versionMatch[1].trim(); |
74 | 76 | 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 |
77 | 78 |
|
78 | | - if (!isUnreleased && !isSemver && !isCalVer) { |
| 79 | + if (!isUnreleased && !isUsDate) { |
79 | 80 | continue; |
80 | 81 | } |
81 | 82 |
|
@@ -138,6 +139,25 @@ export const GET = createSmartRouteHandler({ |
138 | 139 | }).defined(), |
139 | 140 | }), |
140 | 141 | 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 | + |
141 | 161 | const changelogUrl = getEnvVariable("STACK_CHANGELOG_URL", ""); |
142 | 162 |
|
143 | 163 | if (!changelogUrl) { |
|
0 commit comments