@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Project scratch note: a plain text file at `<project>/.notes.txt`.
|
||||
*
|
||||
* Deliberately not JSON and not part of `.helder/`. It is a note the user
|
||||
* writes by hand, so it must stay readable and editable outside Helder.
|
||||
*/
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { logger } from './logger'
|
||||
|
||||
export const NOTES_FILE = '.notes.txt'
|
||||
|
||||
/** The note's text. Empty string when the project has no note yet. */
|
||||
export async function readNote(root: string): Promise<string> {
|
||||
try {
|
||||
return await readFile(join(root, NOTES_FILE), 'utf8')
|
||||
} catch (err) {
|
||||
// ENOENT is the normal "no note yet" case, anything else is worth knowing.
|
||||
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {
|
||||
logger.warn('notes', 'read failed', { root, err: String(err) })
|
||||
}
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export async function writeNote(root: string, text: string): Promise<void> {
|
||||
await writeFile(join(root, NOTES_FILE), text, 'utf8')
|
||||
}
|
||||
Reference in New Issue
Block a user