( absolutePath: string, outputFormat: 'jupyter' | 'percent' | 'quarto' | 'marimo', customOutputPath: string | undefined, cwd: string )
| 352 | } |
| 353 | |
| 354 | async function convertDeepnoteToFormat( |
| 355 | absolutePath: string, |
| 356 | outputFormat: 'jupyter' | 'percent' | 'quarto' | 'marimo', |
| 357 | customOutputPath: string | undefined, |
| 358 | cwd: string |
| 359 | ): Promise<string> { |
| 360 | const formatNames = { |
| 361 | jupyter: 'Jupyter Notebooks', |
| 362 | percent: 'percent format files', |
| 363 | quarto: 'Quarto documents', |
| 364 | marimo: 'Marimo notebooks', |
| 365 | } |
| 366 | |
| 367 | const spinner = ora(`Converting Deepnote project to ${formatNames[outputFormat]}...`).start() |
| 368 | |
| 369 | try { |
| 370 | const ext = extname(absolutePath) |
| 371 | const filenameWithoutExtension = basename(absolutePath, ext) |
| 372 | const outputDirName = filenameWithoutExtension |
| 373 | const outputDir = customOutputPath ? resolve(cwd, customOutputPath) : resolve(cwd, outputDirName) |
| 374 | |
| 375 | // Read the source file and try to merge with snapshot |
| 376 | const sourceContent = await fs.readFile(absolutePath, 'utf-8') |
| 377 | let deepnoteFile = deserializeDeepnoteFile(sourceContent) |
| 378 | |
| 379 | // Try to load and merge snapshot |
| 380 | const nbId = resolveSnapshotNotebookId(deepnoteFile) |
| 381 | const snapshot = await loadLatestSnapshot(absolutePath, deepnoteFile.project.id, nbId ? { notebookId: nbId } : {}) |
| 382 | if (snapshot) { |
| 383 | deepnoteFile = mergeSnapshotIntoSource(deepnoteFile, snapshot, { skipMismatched: true }) |
| 384 | } |
| 385 | |
| 386 | // Write merged content to a unique temporary directory for the converters |
| 387 | const tempDir = await fs.mkdtemp(resolve(dirname(absolutePath), '.deepnote-merge-')) |
| 388 | const tempFilename = `${filenameWithoutExtension}.merged.deepnote` |
| 389 | const tempPath = resolve(tempDir, tempFilename) |
| 390 | |
| 391 | try { |
| 392 | const mergedYaml = serializeDeepnoteFile(deepnoteFile) |
| 393 | await fs.writeFile(tempPath, mergedYaml, 'utf-8') |
| 394 | |
| 395 | switch (outputFormat) { |
| 396 | case 'jupyter': |
| 397 | await convertDeepnoteFileToJupyterFiles(tempPath, { outputDir }) |
| 398 | break |
| 399 | case 'percent': |
| 400 | await convertDeepnoteFileToPercentFiles(tempPath, { outputDir }) |
| 401 | break |
| 402 | case 'quarto': |
| 403 | await convertDeepnoteFileToQuartoFiles(tempPath, { outputDir }) |
| 404 | break |
| 405 | case 'marimo': |
| 406 | await convertDeepnoteFileToMarimoFiles(tempPath, { outputDir }) |
| 407 | break |
| 408 | } |
| 409 | } finally { |
| 410 | // Clean up temp directory |
| 411 | await fs.rm(tempDir, { recursive: true, force: true }).catch(() => {}) |
no test coverage detected