| 1 | import fs from 'fs' |
| 2 | import path from 'path' |
| 3 | import type { IpcContext } from '../ipc/context' |
| 4 | |
| 5 | export const INDEX_RUNTIME_MARKER = '@ohmyppt-index-runtim:arcsin1:v2.0.19' |
| 6 | export const PPT_RUNTIME_MARKER = '@ohmyppt-ppt-runtime:arcsin1:v2.0.21' |
| 7 | |
| 8 | const RUNTIME_ASSET_MARKERS = [ |
| 9 | { fileName: 'index-runtime.js', marker: INDEX_RUNTIME_MARKER }, |
| 10 | { fileName: 'ppt-runtime.js', marker: PPT_RUNTIME_MARKER } |
| 11 | ] as const |
| 12 | |
| 13 | async function hasExpectedRuntimeMarker(projectDir: string, fileName: string, marker: string): Promise<boolean> { |
| 14 | try { |
| 15 | const content = await fs.promises.readFile(path.join(projectDir, 'assets', fileName), 'utf-8') |
| 16 | return content.includes(marker) |
| 17 | } catch { |
| 18 | return false |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | export async function ensureSessionRuntimeCompatible( |
| 23 | ctx: IpcContext, |
| 24 | projectDir: string |
| 25 | ): Promise<void> { |
| 26 | for (const { fileName, marker } of RUNTIME_ASSET_MARKERS) { |
| 27 | if (!(await hasExpectedRuntimeMarker(projectDir, fileName, marker))) { |
| 28 | await ctx.ensureSessionAssets(projectDir) |
| 29 | return |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 |