From f0c4ef68e5131d85da91610a89974d3cb26fc3dd Mon Sep 17 00:00:00 2001 From: Yufan Sheng Date: Wed, 19 Jun 2024 03:46:43 +0800 Subject: [PATCH] fix: correctly remove directory. --- plugins/upyun.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/upyun.ts b/plugins/upyun.ts index 3aabfda..2d1e075 100644 --- a/plugins/upyun.ts +++ b/plugins/upyun.ts @@ -1,6 +1,7 @@ import type { AstroIntegration, AstroIntegrationLogger, RouteData } from 'astro'; import fs from 'node:fs'; import path from 'node:path'; +import { rimrafSync } from 'rimraf'; import up from 'upyun'; export type UpyunOption = { @@ -48,7 +49,7 @@ export const upyun = (opt: UpyunOption): AstroIntegration => ({ for (const dir of option.path) { logger.info(`Start to upload the ${dir} to upyun`); await uploadFile(logger, client, staticRootPath, dir); - fs.rmSync(path.join(staticRootPath, dir)); + rimrafSync(path.join(staticRootPath, dir)); } }, }, @@ -79,6 +80,8 @@ const uploadFile = async (logger: AstroIntegrationLogger, client: up.Client, roo // Upload file. logger.info(`Try to upload file ${filePath} to upyun`); await client.putFile(filePath, fs.readFileSync(fullPath)); + } else { + logger.info(`The file ${filePath} is existed on upyun. Skip by default.`); } return;