* Output cat results as JSON for scripting.
( absolutePath: string, deepnoteFile: ReturnType<typeof deserializeDeepnoteFile>, notebooks: DeepnoteFile['project']['notebooks'], options: CatOptions )
| 104 | * Output cat results as JSON for scripting. |
| 105 | */ |
| 106 | function outputCatJson( |
| 107 | absolutePath: string, |
| 108 | deepnoteFile: ReturnType<typeof deserializeDeepnoteFile>, |
| 109 | notebooks: DeepnoteFile['project']['notebooks'], |
| 110 | options: CatOptions |
| 111 | ): void { |
| 112 | const result: CatResult = { |
| 113 | success: true, |
| 114 | path: absolutePath, |
| 115 | project: { |
| 116 | name: deepnoteFile.project.name, |
| 117 | id: deepnoteFile.project.id, |
| 118 | }, |
| 119 | notebooks: [], |
| 120 | } |
| 121 | |
| 122 | for (const notebook of notebooks) { |
| 123 | const filteredBlocks = filterBlocks(notebook.blocks, options) |
| 124 | const notebookResult: NotebookSummary = { |
| 125 | name: notebook.name, |
| 126 | id: notebook.id, |
| 127 | blocks: [], |
| 128 | } |
| 129 | |
| 130 | for (const block of filteredBlocks) { |
| 131 | const blockResult: BlockSummary = { |
| 132 | id: block.id, |
| 133 | type: block.type, |
| 134 | label: getBlockLabel(block), |
| 135 | } |
| 136 | |
| 137 | // Include content unless --tree mode |
| 138 | if (!options.tree) { |
| 139 | const content = getBlockContent(block) |
| 140 | if (content !== undefined) { |
| 141 | blockResult.content = content |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | notebookResult.blocks.push(blockResult) |
| 146 | } |
| 147 | |
| 148 | result.notebooks.push(notebookResult) |
| 149 | } |
| 150 | |
| 151 | outputJson(result) |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Print blocks to stdout with formatting. |
no test coverage detected