@androbinco/prompts-cli
Version:
Robin CLI for importing generative AI prompts
129 lines (109 loc) âĸ 4.23 kB
JavaScript
/* eslint-disable no-console */
import path from 'node:path';
import 'dotenv/config';
import { fetchGistContent } from './gists/gists.js';
import { ensureDirectoryExists, writeFileContent } from './utils/fileUtils.js';
const GISTS = [
{
name: 'COLORS_FOUNDATIONS.md',
id: 'f5b2b63b1b4f15eb3733b02037ab0586',
},
{
name: 'COLORS_SEMANTIC_TOKENS.md',
id: '47e7863e691a880cfcefbcdd9028adc5',
},
{
name: 'COLORS_DESIGN_SEMANTIC_TOKENS.md',
id: '6077f9e4aff3a45c732b00ce8394cfb1',
},
{
name: 'FONTS_SEMANTIC_TOKENS.md',
id: 'bb28da69948c9116e3373bce850b353c',
},
{
name: 'FONTS_VARIANTS.md',
id: 'a97930de6800f304ad310d8ae82d4e8c',
},
];
const OUTPUT_FOLDER_NAME = 'z-prompts';
async function main() {
console.log('đ Starting Gist transcription process...');
const outputFolderPath = path.resolve(process.cwd(), OUTPUT_FOLDER_NAME);
try {
await ensureDirectoryExists(outputFolderPath);
console.log(`â
Output folder "${outputFolderPath}" ensured.`);
} catch (error) {
console.error(
`â Critical Error: Failed to create base output directory "${outputFolderPath}". Aborting.`,
error.message,
);
process.exit(1);
}
let allOperationsSuccessful = true;
for (const gistDefinition of GISTS) {
const { name: outputFileName, id: gistId } = gistDefinition;
console.log(`\nProcessing Gist ID: ${gistId} for output file: ${outputFileName}`);
try {
const gistFilesObject = await fetchGistContent(gistId);
if (gistFilesObject && Object.keys(gistFilesObject).length > 0) {
let combinedContentForCurrentGist = '';
combinedContentForCurrentGist += `\n`;
combinedContentForCurrentGist += `\n\n`;
for (const actualFileNameInGist in gistFilesObject) {
if (Object.prototype.hasOwnProperty.call(gistFilesObject, actualFileNameInGist)) {
const fileData = gistFilesObject[actualFileNameInGist];
if (fileData && typeof fileData.content === 'string') {
combinedContentForCurrentGist += `\n`;
combinedContentForCurrentGist += fileData.content + '\n\n';
} else {
console.warn(
`â ī¸ Warning: No content or invalid format for file "${actualFileNameInGist}" in Gist ${gistId}`,
);
}
}
}
combinedContentForCurrentGist = combinedContentForCurrentGist.trim();
if (combinedContentForCurrentGist) {
const targetFilePath = path.join(outputFolderPath, outputFileName);
await writeFileContent(targetFilePath, combinedContentForCurrentGist);
console.log(`đ Successfully transcribed Gist ${gistId} to: ${targetFilePath}`);
} else {
console.log(`âšī¸ No text content was extracted from files for Gist ID: ${gistId}`);
}
} else {
console.log(
`âšī¸ No files found or fetch seemed to succeed but returned no files for Gist ID: ${gistId}`,
);
}
} catch (error) {
allOperationsSuccessful = false;
console.error(
`â Error processing Gist ID ${gistId} (intended for output ${outputFileName}): ${error.message}`,
);
if (error.status === 401) {
console.error(
' UNAUTHORIZED: Please check your GITHUB_PAT. It might be missing, incorrect, or lack the "gist" scope.',
);
} else if (error.status === 404) {
console.error(
' NOT FOUND: The Gist ID might be incorrect, or the Gist could be private and inaccessible with the current PAT.',
);
} else if (error.status) {
console.error(` API Error Status: ${error.status}`);
}
}
}
console.log('\n----------------------------------------');
if (!allOperationsSuccessful) {
console.log('â ī¸ Process completed, but some Gists encountered errors.');
} else {
if (GISTS.length === 0) {
console.log('â
Process completed. No Gists were defined to process.');
} else {
console.log('â
All defined Gists processed successfully!');
}
}
console.log('----------------------------------------');
}
main();