Skip to content

Commit

Permalink
chore: use yaml instead of json
Browse files Browse the repository at this point in the history
  • Loading branch information
CristiCanizales committed Jan 30, 2025
1 parent f9b0023 commit 74ba0ce
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import * as fs from 'fs';
import * as path from 'path';
import { parse, stringify } from 'yaml';
import { Prompts } from '../schemas';
import { sourcePrompts } from './prompts';

const PROMPTS_DIR = path.join('.sfdx', 'oas_prompts');
const PROMPTS_FILE = path.join(PROMPTS_DIR, 'prompts.json');
const PROMPTS_FILE = path.join(PROMPTS_DIR, 'prompts.yaml');

const getPromptsFromSource = (): Record<string, any> => {
return sourcePrompts;
Expand All @@ -24,17 +25,17 @@ export const ensurePromptsExist = (): void => {

if (!fs.existsSync(PROMPTS_FILE)) {
const extractedPrompts = getPromptsFromSource();
fs.writeFileSync(PROMPTS_FILE, JSON.stringify(extractedPrompts, null, 2), 'utf8');
fs.writeFileSync(PROMPTS_FILE, stringify(extractedPrompts), 'utf8');
}
};

export const getPrompts = (): Prompts => {
ensurePromptsExist();
const data = fs.readFileSync(PROMPTS_FILE, 'utf8');
return JSON.parse(data) as Prompts;
return parse(data) as Prompts;
};

// For future use cases (if needed)
export const updatePrompts = (newPrompts: Record<string, any>): void => {
fs.writeFileSync(PROMPTS_FILE, JSON.stringify(newPrompts, null, 2), 'utf8');
fs.writeFileSync(PROMPTS_FILE, stringify(newPrompts, null, 2), 'utf8');
};

0 comments on commit 74ba0ce

Please sign in to comment.