1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-01-17 14:18:17 +01:00

Automate the title creation in new roadmap content

This commit is contained in:
Kamran Ahmed 2023-03-27 03:44:54 +01:00
parent 907f820778
commit 66bdbd7458
76 changed files with 156 additions and 74 deletions

81
bin/roadmap-content.cjs Normal file
View File

@ -0,0 +1,81 @@
const fs = require('fs');
const path = require('path');
const OPEN_AI_API_KEY = process.env.OPEN_AI_API_KEY;
const ALL_ROADMAPS_DIR = path.join(__dirname, '../src/data/roadmaps');
const ROADMAP_JSON_DIR = path.join(__dirname, '../public/jsons/roadmaps');
const roadmapId = process.argv[2];
const allowedRoadmapIds = fs.readdirSync(ALL_ROADMAPS_DIR);
if (!roadmapId) {
console.error('roadmapId is required');
process.exit(1);
}
if (!allowedRoadmapIds.includes(roadmapId)) {
console.error(`Invalid roadmap key ${roadmapId}`);
console.error(`Allowed keys are ${allowedRoadmapIds.join(', ')}`);
process.exit(1);
}
const ROADMAP_CONTENT_DIR = path.join(ALL_ROADMAPS_DIR, roadmapId, 'content');
function getFilesInFolder(folderPath, fileList = {}) {
const files = fs.readdirSync(folderPath);
files.forEach((file) => {
const filePath = path.join(folderPath, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
getFilesInFolder(filePath, fileList);
} else if (stats.isFile()) {
const fileUrl = filePath
.replace(ROADMAP_CONTENT_DIR, '') // Remove the content folder
.replace(/\/\d+-/g, '/') // Remove ordering info `/101-ecosystem`
.replace(/\/index\.md$/, '') // Make the `/index.md` to become the parent folder only
.replace(/\.md$/, ''); // Remove `.md` from the end of file
fileList[fileUrl] = filePath;
}
});
return fileList;
}
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')
);
groups.forEach((group) => {
const topicId = group?.properties?.controlName;
const topicTitle = group?.children?.controls?.control?.find((control) => control?.typeID === 'Label')?.properties
?.text;
const currTopicUrl = topicId.replace(/^\d+-/g, '/').replace(/:/g, '/');
const contentFilePath = topicUrlToPathMapping[currTopicUrl];
const currentFileContent = fs.readFileSync(contentFilePath, 'utf8');
const isFileEmpty = currentFileContent.replace(/^#.+/, ``).trim() == '';
if (!isFileEmpty) {
console.log(`${topicId} not empty. Ignoring...`);
return;
}
let newFileContent = `# ${topicTitle}`;
if (!OPEN_AI_API_KEY) {
console.log(`OPEN_AI_API_KEY not set. Only adding title to ${topicId}..`);
fs.writeFileSync(contentFilePath, newFileContent, 'utf8');
return;
}
// console.log(currentFileContent);
// console.log(currTopicUrl);
// console.log(topicTitle);
// console.log(topicUrlToPathMapping[currTopicUrl]);
});

View File

@ -14,6 +14,7 @@
"upgrade": "ncu -u", "upgrade": "ncu -u",
"roadmap-links": "node bin/roadmap-links.cjs", "roadmap-links": "node bin/roadmap-links.cjs",
"roadmap-dirs": "node bin/roadmap-dirs.cjs", "roadmap-dirs": "node bin/roadmap-dirs.cjs",
"roadmap-content": "node bin/roadmap-content.cjs",
"best-practice-dirs": "node bin/best-practice-dirs.cjs", "best-practice-dirs": "node bin/best-practice-dirs.cjs",
"test:e2e": "playwright test" "test:e2e": "playwright test"
}, },

View File

@ -1 +1 @@
# Help user think about their action # Help User think about Their Action

View File

@ -1 +1 @@
# Changing user behavior # Support Conscious Action

View File

@ -1 +1 @@
# Automate act of repition # Automate the Act of Repetition

View File

@ -1 +1 @@
# Mindfulness to avoid acting on the cue # Mindfulness to Avoid Acting on the Cue

View File

@ -1 +1 @@
# Crowd out old habit with new behavior # Crowd Out Old Habit with New Behavior

View File

@ -1 +1 @@
# Make or change habbits # Make or Change Habbits

View File

@ -1 +1 @@
# BJ Fogg's Behavior Model # BJ Foggs Behavior Grid

View File

@ -1 +1 @@
# Cue routine reward model # Cue Routine Reward Model

View File

@ -1 +1 @@
# Understand the product # Understanding the Product

View File

@ -1 +1 @@
# Business model inspirator # Business Model Inspirator

View File

@ -1 +1 @@
# Custom experience map # Customer Experience Map by Mel Edwards

View File

@ -1 +1 @@
# Simple flowchart # Simple Flowchart

View File

@ -1 +1 @@
# Event driven process chain model # Event-Driven Process Chain Model (EPC)

View File

@ -1 +1 @@
# Business process model and notation # Business Process Model and Notation (BPMN)

View File

@ -1 +1 @@
# Conceptual design # Conceptual Design

View File

@ -1 +1 @@
# Keep it short simple # In general, Keep it Short and Simple

View File

@ -1 +1 @@
# Make it easy # Make it Easy to Understand, Easy to Complete

View File

@ -1 +1 @@
# Make progress visible # Make Progress Visible to User

View File

@ -1 +1 @@
# Make progress meaningful reward user # Make Progress Meaningful in order to Reward User

View File

@ -1 +1 @@
# Make successful completion clearly visible # Make Successful Completion Clearly Visible

View File

@ -1 +1 @@
# Good layout rules # Good Layout Rules

View File

@ -1 +1 @@
# Prototyping # ProtoTyping

View File

@ -1 +1 @@
# Call to action # Call to Action

View File

@ -1 +1 @@
# Status reports # Status Reports

View File

@ -1 +1 @@
# Reminders planning prompts # Simple Reminders and Planning Prompts

View File

@ -1 +1 @@
# Decision making support # Decision-Making Support

View File

@ -1 +1 @@
# Behavior change games # Behavior Change Games

View File

@ -1 +1 @@
# Social sharing # Social Sharing

View File

@ -1 +1 @@
# Goal trackers # Goal Trackers

View File

@ -1 +1 @@
# Avoid temporal myopia # Frame Text to Avoid Temporal Myopia

View File

@ -1 +1 @@
# Remind of prior commitment to act # Remind of Prior Commitment to Act

View File

@ -1 +1 @@
# Make commitment to friends # Make Commitment to Friends

View File

@ -1 +1 @@
# Make reward scarce # Make Reward Scarce

View File

@ -1 +1 @@
# Tell user and ask # Tell User What the Action is and Ask for it

View File

@ -1 +1 @@
# Make it clear where to act # Make it Clear, Where to Act

View File

@ -1 +1 @@
# Clear the page of distractions # Clear the Page of Distractions

View File

@ -1 +1 @@
# Prime user relevant associations # Prime User-Relevant Associations

View File

@ -1 +1 @@
# Ux best practices # UX Best Practices

View File

@ -1 +1 @@
# Elicit implementation intentions # Elicit Implementation Intentions

View File

@ -1 +1 @@
# Lessen the burden of action info # Lessen the Burden of Action/Info.

View File

@ -1 +1 @@
# Deploy peer comparisons # Deploy Peer Comparisons

View File

@ -1 +1 @@
# Make ui professional and beautiful # Make UI Professional and Beautiful

View File

@ -1 +1 @@
# Deploy strong subject authority # Deploy Strong Authority on Subject

View File

@ -1 +1 @@
# Be authentic and personal # Be Authentic and Personal

View File

@ -1 +1 @@
# Gather lessons prioritize integrate # Gather Lessons Learned,

View File

@ -1 +1 @@
# Measuring the impact # Measuring the Impact

View File

@ -1 +1 @@
# Incremental ab testing # Incremental A/B Testing

View File

@ -1 +1 @@
# Multivariate testing # Multivariate Testing