(options: ConvertOptions)
| 33 | } |
| 34 | |
| 35 | export async function convert(options: ConvertOptions): Promise<string> { |
| 36 | const { |
| 37 | inputPath, |
| 38 | projectName: customProjectName, |
| 39 | outputPath: customOutputPath, |
| 40 | cwd = process.cwd(), |
| 41 | outputFormat = 'jupyter', |
| 42 | singleFile = false, |
| 43 | } = options |
| 44 | |
| 45 | const resolveProjectName = (possibleName?: string): string => { |
| 46 | if (customProjectName) { |
| 47 | return customProjectName |
| 48 | } |
| 49 | |
| 50 | if (possibleName) { |
| 51 | return possibleName |
| 52 | } |
| 53 | |
| 54 | return 'Untitled project' |
| 55 | } |
| 56 | |
| 57 | const resolveOutputPath = async (outputFilename: string): Promise<string> => { |
| 58 | if (customOutputPath) { |
| 59 | const absoluteOutputPath = resolve(cwd, customOutputPath) |
| 60 | const stat = await fs.stat(absoluteOutputPath).catch(() => null) |
| 61 | |
| 62 | if (stat?.isDirectory()) { |
| 63 | return resolve(absoluteOutputPath, outputFilename) |
| 64 | } |
| 65 | |
| 66 | return absoluteOutputPath |
| 67 | } |
| 68 | |
| 69 | return resolve(cwd, outputFilename) |
| 70 | } |
| 71 | |
| 72 | const absolutePath = resolve(cwd, inputPath) |
| 73 | |
| 74 | const stat = await fs.stat(absolutePath) |
| 75 | |
| 76 | if (stat.isDirectory()) { |
| 77 | const entries = await fs.readdir(absolutePath, { withFileTypes: true }) |
| 78 | |
| 79 | const ipynbFiles = entries |
| 80 | .filter(entry => entry.isFile() && entry.name.toLowerCase().endsWith('.ipynb')) |
| 81 | .map(entry => entry.name) |
| 82 | .sort((a, b) => a.localeCompare(b)) |
| 83 | |
| 84 | const quartoFiles = entries |
| 85 | .filter(entry => entry.isFile() && entry.name.toLowerCase().endsWith('.qmd')) |
| 86 | .map(entry => entry.name) |
| 87 | .sort((a, b) => a.localeCompare(b)) |
| 88 | |
| 89 | // For .py files, we need to check content to distinguish between percent and marimo formats |
| 90 | const pyFiles = entries |
| 91 | .filter(entry => entry.isFile() && entry.name.toLowerCase().endsWith('.py')) |
| 92 | .map(entry => entry.name) |
no test coverage detected