MCPcopy Index your code
hub / github.com/deepnote/deepnote / convertDirectory

Function convertDirectory

packages/convert/src/cli.ts:230–266  ·  view source on GitHub ↗

* Converts every notebook in a directory to its own single-notebook `.deepnote` file — * one file per source notebook (the recommended layout). * * All notebooks are converted together as ONE project, so every output file shares the same * `project.id`, name, settings, and integrations; each is

(options: ConvertDirectoryOptions)

Source from the content-addressed store, hash-verified

228 * directory name). The output directory defaults to the input directory; the directory is returned.
229 */
230async function convertDirectory(options: ConvertDirectoryOptions): Promise<string> {
231 const { dirPath, files, format, customOutputPath, cwd, customProjectName, singleFile } = options
232
233 const outputDir = customOutputPath ? resolve(cwd, customOutputPath) : dirPath
234 await fs.mkdir(outputDir, { recursive: true })
235
236 const projectName = customProjectName ?? basename(dirPath)
237 const plural = files.length === 1 ? '' : 's'
238 const spinner = ora(
239 `Converting ${files.length} ${DIRECTORY_FORMAT_NAMES[format]}${plural} to Deepnote files...`
240 ).start()
241
242 const projectId = randomUUID()
243
244 try {
245 const createdFiles: string[] = []
246 for (const file of files) {
247 const inputFilePath = resolve(dirPath, file)
248 const outputName = basename(file, extname(file))
249 const outputPath = resolve(outputDir, `${outputName}.deepnote`)
250 // Same projectId across every file ⇒ all outputs belong to one project.
251 const deepnoteFile = await readAndConvertOne(format, inputFilePath, { projectName, projectId })
252 // writeDeepnoteFile handles snapshot splitting in memory.
253 await writeDeepnoteFile({ file: deepnoteFile, outputPath, projectName, singleFile })
254 createdFiles.push(outputPath)
255 }
256
257 spinner.succeed(
258 `${createdFiles.length} Deepnote file${createdFiles.length === 1 ? '' : 's'} saved to ${chalk.bold(outputDir)}`
259 )
260
261 return outputDir
262 } catch (error) {
263 spinner.fail('Conversion failed')
264 throw error
265 }
266}
267
268interface ConvertSingleFileOptions {
269 absolutePath: string

Callers 1

convertFunction · 0.85

Calls 3

writeDeepnoteFileFunction · 0.90
readAndConvertOneFunction · 0.85
startMethod · 0.80

Tested by

no test coverage detected