(options: WriteDeepnoteFileOptions)
| 36 | * @returns Object containing paths to the written files |
| 37 | */ |
| 38 | export async function writeDeepnoteFile(options: WriteDeepnoteFileOptions): Promise<WriteDeepnoteFileResult> { |
| 39 | const { file, outputPath, projectName, singleFile = false } = options |
| 40 | |
| 41 | // Ensure parent directory exists |
| 42 | const parentDir = dirname(outputPath) |
| 43 | await fs.mkdir(parentDir, { recursive: true }) |
| 44 | |
| 45 | // If singleFile mode or no outputs, write complete file |
| 46 | if (singleFile || !hasOutputs(file)) { |
| 47 | const yamlContent = serializeDeepnoteFile(file) |
| 48 | await fs.writeFile(outputPath, yamlContent, 'utf-8') |
| 49 | return { sourcePath: outputPath } |
| 50 | } |
| 51 | |
| 52 | // Split into source and snapshot in memory |
| 53 | const { source, snapshot } = splitDeepnoteFile(file) |
| 54 | |
| 55 | const snapshotDir = getSnapshotDir(outputPath) |
| 56 | const snapshotPath = getSnapshotPath(outputPath, file, { projectName }) |
| 57 | |
| 58 | // Serialize both files |
| 59 | const sourceYaml = serializeDeepnoteFile(source) |
| 60 | const snapshotYaml = serializeDeepnoteSnapshot(snapshot) |
| 61 | |
| 62 | // Create snapshot directory and write both files in parallel |
| 63 | await fs.mkdir(snapshotDir, { recursive: true }) |
| 64 | await Promise.all([fs.writeFile(outputPath, sourceYaml, 'utf-8'), fs.writeFile(snapshotPath, snapshotYaml, 'utf-8')]) |
| 65 | |
| 66 | return { sourcePath: outputPath, snapshotPath } |
| 67 | } |
no test coverage detected