Create the dir if it doesn't exist

This commit is contained in:
bl-ue 2025-11-19 10:22:45 -07:00
parent 41eba70cfa
commit 73d2b5bf0c

View File

@ -1,6 +1,4 @@
#!/usr/bin/env node import { readFileSync, writeFileSync, readdirSync, unlinkSync, mkdirSync, existsSync } from 'fs';
import { readFileSync, writeFileSync, readdirSync, unlinkSync } from 'fs';
import { join, dirname } from 'path'; import { join, dirname } from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
@ -10,6 +8,11 @@ const ROOT_DIR = join(__dirname, '..');
const SYSTEM_PROMPTS_DIR = join(ROOT_DIR, 'system-prompts'); const SYSTEM_PROMPTS_DIR = join(ROOT_DIR, 'system-prompts');
const README_PATH = join(ROOT_DIR, 'README.md'); const README_PATH = join(ROOT_DIR, 'README.md');
// Ensure system-prompts directory exists
if (!existsSync(SYSTEM_PROMPTS_DIR)) {
mkdirSync(SYSTEM_PROMPTS_DIR, { recursive: true });
}
// Get API key from environment // Get API key from environment
const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY; const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
if (!ANTHROPIC_API_KEY) { if (!ANTHROPIC_API_KEY) {
@ -276,13 +279,13 @@ async function updateFromJSON(jsonPath) {
if (existingFile) { if (existingFile) {
// Compare content // Compare content
if (existingFile.fullContent.trim() !== newMarkdownContent.trim()) { if (existingFile.fullContent.trim() !== newMarkdownContent.trim()) {
console.log(`⚠️ Changed: ${filename}`); console.log(`\x1b[33mChanged: ${filename}\x1b[0m`);
unlinkSync(filepath); // Delete old file unlinkSync(filepath); // Delete old file
writeFileSync(filepath, newMarkdownContent); writeFileSync(filepath, newMarkdownContent);
changedPrompts.add(filename); changedPrompts.add(filename);
} }
} else { } else {
console.log(`✨ New: ${filename}`); console.log(`\x1b[31mNew: ${filename}\x1b[0m`);
writeFileSync(filepath, newMarkdownContent); writeFileSync(filepath, newMarkdownContent);
newPrompts.add(filename); newPrompts.add(filename);
} }
@ -292,7 +295,7 @@ async function updateFromJSON(jsonPath) {
} }
// Batch count tokens for all prompts // Batch count tokens for all prompts
console.log('\n🔢 Counting tokens...'); console.log(`\x1b[34mCounting tokens for ${promptsToCount.length} prompts...\x1b[0m`);
const tokenCounts = await countTokensBatch(promptsToCount); const tokenCounts = await countTokensBatch(promptsToCount);
// Store prompt info for README updates // Store prompt info for README updates
@ -314,13 +317,13 @@ async function updateFromJSON(jsonPath) {
} }
// Update README // Update README
console.log('\n📝 Updating README.md...'); console.log('\x1b[34mUpdating README.md...\x1b[0m');
updateReadme(promptsByFilename, jsonData.version); updateReadme(promptsByFilename, jsonData.version);
console.log('\n✅ Update complete!'); console.log('\x1b[32;1mUpdate complete!\x1b[0m');
console.log(` New: ${newPrompts.size}`); console.log(` New: \x1b[1m${newPrompts.size}\x1b[0m`);
console.log(` Changed: ${changedPrompts.size}`); console.log(` Changed: \x1b[1m${changedPrompts.size}\x1b[0m`);
console.log(` Deleted: ${deletedFiles.length}`); console.log(` Deleted: \x1b[1m${deletedFiles.length}\x1b[0m`);
} }
/** /**