Skip to content

Commit fd445d3

Browse files
fix: ensure directory exists when writing an Asset
It's possible that assets get written before the actual markdown files. In that case, the target directory may not exist yet and has to be created first.
1 parent f80ab1b commit fd445d3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/AssetWriter.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ export class AssetWriter {
1313
constructor(readonly dir: string) {}
1414

1515
async store(name: string, buffer: Buffer) {
16+
await fs.mkdir(this.dir, { recursive: true });
1617
await fs.writeFile(`${this.dir}/${name}`, buffer);
1718
}
1819

19-
async download(url: string, fileName: string, context: RenderingLoggingContext) {
20+
async download(
21+
url: string,
22+
fileName: string,
23+
context: RenderingLoggingContext
24+
) {
2025
// the got http lib promises to do proper user-agent compliant http caching
2126
// see https://github.com/sindresorhus/got/blob/main/documentation/cache.md
2227

@@ -29,9 +34,8 @@ export class AssetWriter {
2934
);
3035
const imageFile = fileName + "." + ext;
3136

32-
context.info(
33-
`downloading (cached: ${response.isFromCache}): ${imageFile}`
34-
);
37+
const cacheInfo = response.isFromCache ? " (from cache)" : "";
38+
context.info(`downloading ${imageFile}` + cacheInfo);
3539
await this.store(imageFile, response.rawBody);
3640

3741
return imageFile;

0 commit comments

Comments
 (0)