@ -66,7 +66,7 @@ function writeTopicContent(currTopicUrl) {
prompt = `I am reading a guide about "${roadmapTitle}". I am on the topic "${parentTopic}". I want to know more about "${parentTopic}". Write me a brief summary for that topic. Content should be in markdown. Behave as if you are the author of the guide.`;
prompt = `I am reading a guide about "${roadmapTitle}". I am on the topic "${parentTopic}". I want to know more about "${parentTopic}". Write me a brief summary for that topic. Content should be in markdown. Behave as if you are the author of the guide.`;
}
}
console.log(`Genea rting '${childTopic || parentTopic}'...`);
console.log(`Genera ting '${childTopic || parentTopic}'...`);
return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
openai
openai
@ -90,30 +90,14 @@ function writeTopicContent(currTopicUrl) {
});
});
}
}
async function run() {
async function writeFileForGroup(group, topicUrlToPathMapping) {
const topicUrlToPathMapping = getFilesInFolder(ROADMAP_CONTENT_DIR);
const roadmapJson = require(path.join(ROADMAP_JSON_DIR, `${roadmapId}.json`));
const groups = roadmapJson?.mockup?.controls?.control?.filter(
(control) =>
control.typeID === '__group__' &&
!control.properties?.controlName?.startsWith('ext_link')
);
if (!OPEN_AI_API_KEY) {
console.log('----------------------------------------');
console.log('OPEN_AI_API_KEY not found. Skipping openai api calls...');
console.log('----------------------------------------');
}
for (let group of groups) {
const topicId = group?.properties?.controlName;
const topicId = group?.properties?.controlName;
const topicTitle = group?.children?.controls?.control?.find(
const topicTitle = group?.children?.controls?.control?.find(
(control) => control?.typeID === 'Label'
(control) => control?.typeID === 'Label'
)?.properties?.text;
)?.properties?.text;
const currTopicUrl = topicId?.replace(/^\d+-/g, '/')?.replace(/:/g, '/');
const currTopicUrl = topicId?.replace(/^\d+-/g, '/')?.replace(/:/g, '/');
if (!currTopicUrl) {
if (!currTopicUrl) {
continue ;
return;
}
}
const contentFilePath = topicUrlToPathMapping[currTopicUrl];
const contentFilePath = topicUrlToPathMapping[currTopicUrl];
@ -128,15 +112,16 @@ async function run() {
if (!isFileEmpty) {
if (!isFileEmpty) {
console.log(`Ignoring ${topicId}. Not empty.`);
console.log(`Ignoring ${topicId}. Not empty.`);
continue ;
return ;
}
}
let newFileContent = `# ${topicTitle}`;
let newFileContent = `# ${topicTitle}`;
if (!OPEN_AI_API_KEY) {
if (!OPEN_AI_API_KEY) {
console.log(`Writing ${topicId}..`);
console.log(`Writing ${topicId}..`);
fs.writeFileSync(contentFilePath, newFileContent, 'utf8');
fs.writeFileSync(contentFilePath, newFileContent, 'utf8');
continue ;
return ;
}
}
const topicContent = await writeTopicContent(currTopicUrl);
const topicContent = await writeTopicContent(currTopicUrl);
@ -149,7 +134,31 @@ async function run() {
// console.log(currTopicUrl);
// console.log(currTopicUrl);
// console.log(topicTitle);
// console.log(topicTitle);
// console.log(topicUrlToPathMapping[currTopicUrl]);
// console.log(topicUrlToPathMapping[currTopicUrl]);
}
async function run() {
const topicUrlToPathMapping = getFilesInFolder(ROADMAP_CONTENT_DIR);
const roadmapJson = require(path.join(ROADMAP_JSON_DIR, `${roadmapId}.json`));
const groups = roadmapJson?.mockup?.controls?.control?.filter(
(control) =>
control.typeID === '__group__' &&
!control.properties?.controlName?.startsWith('ext_link')
);
if (!OPEN_AI_API_KEY) {
console.log('----------------------------------------');
console.log('OPEN_AI_API_KEY not found. Skipping openai api calls...');
console.log('----------------------------------------');
}
}
const writePromises = [];
for (let group of groups) {
writePromises.push(writeFileForGroup(group, topicUrlToPathMapping));
}
console.log('Waiting for all files to be written...');
await Promise.all(writePromises);
}
}
run()
run()