-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathensure-ai-cookbook.js
More file actions
37 lines (29 loc) · 1.16 KB
/
ensure-ai-cookbook.js
File metadata and controls
37 lines (29 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const { existsSync, mkdirSync, writeFileSync } = require('fs');
const path = require('path');
const WORKSPACE_ROOT = path.resolve(__dirname, '..');
const outputDirFromEnv = process.env.AI_COOKBOOK_OUTPUT_DIR ?? 'ai-cookbook';
const OUTPUT_DIR = path.resolve(WORKSPACE_ROOT, outputDirFromEnv);
if (OUTPUT_DIR !== WORKSPACE_ROOT && !OUTPUT_DIR.startsWith(`${WORKSPACE_ROOT}${path.sep}`)) {
throw new Error('[ensure-ai-cookbook] AI_COOKBOOK_OUTPUT_DIR must resolve within the repository root');
}
const PLACEHOLDER_PATH = path.join(OUTPUT_DIR, 'recipes-not-synced.mdx');
// Ensure ai-cookbook directory exists with a placeholder file.
// This prevents build errors when the content hasn't been synced yet.
if (!existsSync(OUTPUT_DIR)) {
mkdirSync(OUTPUT_DIR, { recursive: true });
writeFileSync(
PLACEHOLDER_PATH,
`---
id: recipes-not-synced
title: AI Cookbook
description: Recipes and patterns for building AI applications with Temporal.
sidebar_label: AI Cookbook
---
# AI Cookbook
Content has not been synced yet. Run \`yarn sync:ai-cookbook\` to fetch the recipes.
`,
'utf8'
);
console.log('[ensure-ai-cookbook] Created placeholder directory');
}