( root: string, rel: string, comments: NoteCommentInput[] )
| 2727 | } |
| 2728 | |
| 2729 | export async function writeNoteComments( |
| 2730 | root: string, |
| 2731 | rel: string, |
| 2732 | comments: NoteCommentInput[] |
| 2733 | ): Promise<NoteComment[]> { |
| 2734 | const notePath = toPosix(rel) |
| 2735 | const normalized = normalizeNoteComments(comments, notePath) |
| 2736 | const abs = noteCommentsPath(root, notePath) |
| 2737 | if (normalized.length === 0) { |
| 2738 | await fs.rm(abs, { force: true }) |
| 2739 | return [] |
| 2740 | } |
| 2741 | await fs.mkdir(path.dirname(abs), { recursive: true }) |
| 2742 | await fs.writeFile(abs, JSON.stringify({ version: 1, comments: normalized }, null, 2), 'utf8') |
| 2743 | return normalized |
| 2744 | } |
| 2745 | |
| 2746 | async function removeNoteComments(root: string, rel: string): Promise<void> { |
| 2747 | await fs.rm(noteCommentsPath(root, rel), { force: true }) |
no test coverage detected