From 8c8d153bd6604e9651dfee3f6455a11c547b9f4e Mon Sep 17 00:00:00 2001 From: jorismertz <35079666+jorismertz@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:27:15 +0200 Subject: [PATCH] fix: check if readme.md exists to prevent crash --- source/utils/update-readme-version.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/utils/update-readme-version.ts b/source/utils/update-readme-version.ts index 56cc405..d583189 100644 --- a/source/utils/update-readme-version.ts +++ b/source/utils/update-readme-version.ts @@ -3,9 +3,10 @@ import process from "node:process"; import { type UserOptions } from "../config.js"; export const updateReadmeVersion = (version: string, flags?: UserOptions) => { - const readme = fs - .readFileSync(process.cwd() + "/readme.md", "utf8") - .toString(); + const readmePath = process.cwd() + "/readme.md"; + if (!fs.existsSync(readmePath)) return; + + const readme = fs.readFileSync(readmePath, "utf8").toString(); const t = flags?.template ? ` -t ${flags.template}` : ""; const o = flags?.output ? ` -o ${flags.output}` : ""; @@ -33,5 +34,5 @@ _Generated by [@rose-pine/build@${version}](https://github.com/rose-pine/build)_ ? readme.replace(searchFor, replaceWith) : readme + `\n${replaceWith}`; - fs.writeFileSync(process.cwd() + "/readme.md", readmeWithVersion, "utf8"); + fs.writeFileSync(readmePath, readmeWithVersion, "utf8"); };