( files: ImportFile[], )
| 80 | } |
| 81 | |
| 82 | export function parseRaycastSnippetFiles( |
| 83 | files: ImportFile[], |
| 84 | ): SnippetImportParseResult { |
| 85 | const snippets: SnippetImportCandidate[] = [] |
| 86 | const warnings: SnippetImportParseResult['warnings'] = [] |
| 87 | |
| 88 | for (const file of files) { |
| 89 | const parsed = parseJsonFile(file) |
| 90 | const records = getSnippetRecords(parsed) |
| 91 | |
| 92 | if (!records) { |
| 93 | warnings.push({ |
| 94 | code: 'raycast.invalidExport', |
| 95 | source: file.name, |
| 96 | }) |
| 97 | continue |
| 98 | } |
| 99 | |
| 100 | records.forEach((record, index) => { |
| 101 | const content = readString(record, ['text', 'content', 'snippet']) |
| 102 | if (!content) { |
| 103 | warnings.push({ |
| 104 | code: 'raycast.emptyText', |
| 105 | source: `${file.name}/${index + 1}`, |
| 106 | }) |
| 107 | return |
| 108 | } |
| 109 | |
| 110 | snippets.push({ |
| 111 | contents: [ |
| 112 | { |
| 113 | label: 'Fragment 1', |
| 114 | language: 'plain_text', |
| 115 | value: content, |
| 116 | }, |
| 117 | ], |
| 118 | description: readString(record, ['description']) ?? null, |
| 119 | folderPath: getFolderPath(record), |
| 120 | name: normalizeImportEntryName( |
| 121 | readString(record, ['name', 'title']), |
| 122 | `Raycast snippet ${index + 1}`, |
| 123 | ), |
| 124 | sourceId: readString(record, ['id']) ?? `${file.name}:${index + 1}`, |
| 125 | tags: getTags(record), |
| 126 | }) |
| 127 | }) |
| 128 | } |
| 129 | |
| 130 | return { snippets, warnings } |
| 131 | } |
no test coverage detected