UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

100 lines (98 loc) 3.77 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="080a27aa-4d10-5da7-b0a3-3a84ded63190")}catch(e){}}(); import fs from "node:fs"; import path from "node:path"; import { describeSetupState } from "../orchestrator.js"; import { promptConfirmation } from "../prompts.js"; import { getPreviousSetupState } from "../state.js"; import { SetupSessionSchema } from "./types.js"; const persistedContextKeys = [ "componentPackages", "contextName", "createdFeatureId", "createdProjectId", "customPrompt", "dependencyPackageNames", "dependencyMode", "privateDependencyEntries", "projectUrl", "selectedPromptPreset", "repoPaths", "scanSourcePath", "sharedContextId", "shouldRunScan", "shouldUploadScanResults", "templateDestinationPath", "templateFramework", "workspaceId", ]; function setupSessionDirectoryPath() { return path.resolve(".supernova"); } function setupSessionFilePath() { return path.join(setupSessionDirectoryPath(), "setup-session.json"); } function readPersistedSetupSession() { const sessionFilePath = setupSessionFilePath(); if (!fs.existsSync(sessionFilePath)) { return null; } try { const sessionString = fs.readFileSync(sessionFilePath, "utf8"); const sessionJson = JSON.parse(sessionString); const sessionParseResult = SetupSessionSchema.safeParse(sessionJson); return sessionParseResult.success ? sessionParseResult.data : null; } catch { return null; } } export async function resolveInitialSetupState(input) { if (input.restart) { clearPersistedSetupSession(); return "INIT"; } const persistedSession = readPersistedSetupSession(); if (!persistedSession || persistedSession.status !== "InProgress") { return "INIT"; } if (persistedSession.lastState === "INIT" || persistedSession.lastState === "SELECT_DESIGN_SYSTEM") { clearPersistedSetupSession(); return "INIT"; } const shouldResume = await promptConfirmation(`Found unfinished setup while ${describeSetupState(persistedSession.lastState).toLowerCase()}. Resume?`); if (!shouldResume) { clearPersistedSetupSession(); return "INIT"; } return getPreviousSetupState(persistedSession.lastState); } export function resolveInitialSetupContext(config) { const setup = readPersistedSetupSession(); const context = Object.fromEntries(persistedContextKeys.map(key => [key, setup?.[key]])); return { ...context, designSystemId: setup?.designSystemId ?? config?.designSystemId, }; } export function persistSetupSession(input) { const now = new Date().toISOString(); const existingSession = readPersistedSetupSession(); const startedAt = existingSession?.startedAt ?? now; const persistedContext = Object.fromEntries(persistedContextKeys.map(key => [key, input.context[key]])); const sessionDirectoryPath = setupSessionDirectoryPath(); const sessionFilePath = setupSessionFilePath(); fs.mkdirSync(sessionDirectoryPath, { recursive: true }); fs.writeFileSync(sessionFilePath, `${JSON.stringify({ ...persistedContext, designSystemId: input.context.designSystemId, lastState: input.state, startedAt, status: input.status, updatedAt: now, }, null, 2)}\n`); } export function clearPersistedSetupSession() { fs.rmSync(setupSessionFilePath(), { force: true }); } //# sourceMappingURL=session.js.map //# debugId=080a27aa-4d10-5da7-b0a3-3a84ded63190