(path: string, options: CatOptions)
| 64 | } |
| 65 | |
| 66 | async function catDeepnoteFile(path: string, options: CatOptions): Promise<void> { |
| 67 | const { absolutePath } = await resolvePathToDeepnoteFile(path) |
| 68 | |
| 69 | debug('Reading file contents...') |
| 70 | const rawBytes = await fs.readFile(absolutePath) |
| 71 | const yamlContent = decodeUtf8NoBom(rawBytes) |
| 72 | |
| 73 | debug('Parsing .deepnote file...') |
| 74 | const deepnoteFile = deserializeDeepnoteFile(yamlContent) |
| 75 | |
| 76 | // Filter notebooks if --notebook option is provided |
| 77 | let notebooks = deepnoteFile.project.notebooks |
| 78 | if (options.notebook) { |
| 79 | notebooks = notebooks.filter(nb => nb.name === options.notebook) |
| 80 | if (notebooks.length === 0) { |
| 81 | throw new NotFoundInProjectError(`Notebook "${options.notebook}" not found in project`) |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if (options.output === 'json') { |
| 86 | outputCatJson(absolutePath, deepnoteFile, notebooks, options) |
| 87 | } else { |
| 88 | await printBlocks(absolutePath, notebooks, options) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | type BlockSummary = Pick<DeepnoteBlock, 'id' | 'type'> & { label: string; content?: string } |
| 93 | type NotebookSummary = Pick<DeepnoteFile['project']['notebooks'][number], 'name' | 'id'> & { blocks: BlockSummary[] } |
no test coverage detected