Skip to content

Commit

Permalink
feat(INTERNAL-1361): show last written whatsnew
Browse files Browse the repository at this point in the history
  • Loading branch information
tsumo committed Nov 15, 2024
1 parent 09b969b commit 1ec24bb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions trpc/router/whatsnew.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { z } from 'zod';
import path from 'path';
import fs from 'fs';

import { prisma } from '../../src/utils/prisma';
import { protectedProcedure, router } from '../trpcBackend';
Expand All @@ -17,12 +19,19 @@ export const whatsnew = router({
let delayed = false;
let read = false;
let createdAt: Date | undefined;
let version: string | undefined;

const rawReleaseVersion = await fetch(`${process.env.PUBLIC_URL}/version.txt`).then((res) => res.text());
const version = rawReleaseVersion.replace(/\n/g, '');
const whatsnewDir = path.join(process.cwd(), 'src/pages/whatsnew');
try {
const versionsWithNotes = fs.readdirSync(whatsnewDir).filter((f) => /^\d+\.\d+\.\d+$/.test(f));
version = versionsWithNotes.at(-1);
} catch (e) {
console.log(e);
}

const releaseNotesExists =
(await fetch(`${process.env.PUBLIC_URL}${routes.whatsnew(version, locale)}`)).status === 200;
const releaseNotesExists = version
? (await fetch(`${process.env.PUBLIC_URL}${routes.whatsnew(version, locale)}`)).status === 200
: undefined;

if (version && releaseNotesExists) {
let release = await prisma.release.findFirst({
Expand Down

0 comments on commit 1ec24bb

Please sign in to comment.