From 4e0ce8b2fa43dd2a6fc2c781d71970ec1d730e4c Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Fri, 14 Apr 2023 18:30:26 -0400 Subject: [PATCH] cache list of generated filenames Signed-off-by: Xe Iaso --- index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index ecec982..18219e7 100644 --- a/index.ts +++ b/index.ts @@ -150,6 +150,10 @@ program console.error(`plot summary does not exist in ${dir}, run genChapterScenes?`); process.exit(1); } + if (fileExists(`${dir}/fnames.json`)) { + console.error(`file name list already exists in ${dir}`); + process.exit(1); + } await fs.mkdir(`${dir}/src`, { recursive: true }); @@ -162,7 +166,9 @@ program for (let [chNum, ch] of chapters.entries()) { chNum = chNum + 1; - await fs.writeFile(`${dir}/src/ch-${chNum}-sc-00.md`, `# ${ch.title}\n\n`); + const fname = `ch-${chNum}-sc-00.md`; + fnames.push(fname); + await fs.writeFile(`${dir}/src/${fname}`, `# ${ch.title}\n\n`); for (let [sceneNum, scene] of ch.sceneDescriptions.entries()) { sceneNum = sceneNum + 1; fnames.push(await book.writeChapterScene(dir, openai, summary, ch, chNum, sceneNum, scene)); @@ -170,6 +176,7 @@ program } console.log(fnames); + await fs.writeFile(`${dir}/fnames.json`, JSON.stringify(fnames, undefined, " ")); }); program.parse();