Automate the title creation in new roadmap content

pull/3723/head
Kamran Ahmed 2 years ago
parent 907f820778
commit 66bdbd7458
  1. 81
      bin/roadmap-content.cjs
  2. 1
      package.json
  3. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/100-changing-user-behavior/100-help-user-think-about-their-action.md
  4. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/100-changing-user-behavior/101-educate-and-encourage-user.md
  5. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/100-changing-user-behavior/index.md
  6. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/101-cheating/101-make-it-incidental.md
  7. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/101-cheating/102-automate-act-of-repition.md
  8. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/102-make-or-change-habbits/existing-behavior/100-help-user-avoiding-the-cue.md
  9. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/102-make-or-change-habbits/existing-behavior/101-replace-the-routine.md
  10. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/102-make-or-change-habbits/existing-behavior/102-use-consciousness-to-interfere.md
  11. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/102-make-or-change-habbits/existing-behavior/103-mindfulness-to-avoid-acting-on-the-cue.md
  12. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/102-make-or-change-habbits/existing-behavior/104-crowd-out-old-habit-with-new-behavior.md
  13. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/102-make-or-change-habbits/index.md
  14. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/classifying-behavior/100-bj-frogg-behavior-grid.md
  15. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/making-users-addicted/100-nir-eyal-hook-model.md
  16. 2
      src/data/roadmaps/ux-design/content/101-behavior-change-strategies/making-users-addicted/101-cue-routine-reward-model.md
  17. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/clarify-product/100-target-outcome.md
  18. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/clarify-product/101-target-actor.md
  19. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/clarify-product/102-target-action.md
  20. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/define-target-users/100-create-user-personas.md
  21. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/existing-business-model/100-business-model-canvas.md
  22. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/existing-business-model/101-lean-canvas.md
  23. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/index.md
  24. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/new-business-model/100-business-model-inspirator.md
  25. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/new-business-model/101-competitor-analysis.md
  26. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/new-business-model/102-five-forces-model.md
  27. 2
      src/data/roadmaps/ux-design/content/102-understand-the-product/new-business-model/103-swot-analysis.md
  28. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/create-product-backlog/100-user-stories.md
  29. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/deliverables/100-custom-experience-map.md
  30. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/deliverables/101-simple-flowchart.md
  31. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/deliverables/102-event-driven-process-chain-model.md
  32. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/deliverables/103-business-process-model-and-notation.md
  33. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/index.md
  34. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/things-to-lookout-for/100-keep-it-short-simple.md
  35. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/things-to-lookout-for/101-make-it-easy.md
  36. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/things-to-lookout-for/102-make-progress-visible.md
  37. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/things-to-lookout-for/103-make-progress-meaningful-reward-user.md
  38. 2
      src/data/roadmaps/ux-design/content/103-conceptual-design/things-to-lookout-for/104-make-successful-completion-clearly-visible.md
  39. 2
      src/data/roadmaps/ux-design/content/104-prototyping/100-good-layout-rules.md
  40. 2
      src/data/roadmaps/ux-design/content/104-prototyping/index.md
  41. 2
      src/data/roadmaps/ux-design/content/104-prototyping/ux-patterns/100-call-to-action.md
  42. 2
      src/data/roadmaps/ux-design/content/104-prototyping/ux-patterns/101-status-reports.md
  43. 2
      src/data/roadmaps/ux-design/content/104-prototyping/ux-patterns/102-how-to-tips.md
  44. 2
      src/data/roadmaps/ux-design/content/104-prototyping/ux-patterns/103-reminders-planning-prompts.md
  45. 2
      src/data/roadmaps/ux-design/content/104-prototyping/ux-patterns/104-decision-making-support.md
  46. 2
      src/data/roadmaps/ux-design/content/104-prototyping/ux-patterns/105-behavior-change-games.md
  47. 2
      src/data/roadmaps/ux-design/content/104-prototyping/ux-patterns/109-social-sharing.md
  48. 2
      src/data/roadmaps/ux-design/content/104-prototyping/ux-patterns/110-goal-trackers.md
  49. 2
      src/data/roadmaps/ux-design/content/104-prototyping/wireframing/101-adobe-xd.md
  50. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/create-urgency/100-avoid-temporal-myopia.md
  51. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/create-urgency/101-remind-of-prior-commitment-to-act.md
  52. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/create-urgency/102-make-commitment-to-friends.md
  53. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/create-urgency/103-make-reward-scarce.md
  54. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-attention/100-tell-user-and-ask.md
  55. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-attention/101-make-it-clear-where-to-act.md
  56. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-attention/102-clear-the-page-of-distractions.md
  57. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-favorable-conscious-evaluation/100-prime-user-relevant-associations.md
  58. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-favorable-conscious-evaluation/101-leverage-loss-aversion.md
  59. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-favorable-conscious-evaluation/102-use-peer-comparisons.md
  60. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-favorable-conscious-evaluation/103-use-competition.md
  61. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-favorable-conscious-evaluation/104-avoid-cognitive-overhead.md
  62. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-favorable-conscious-evaluation/105-avoid-choice-overload.md
  63. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/getting-favorable-conscious-evaluation/106-avoid-direct-payments.md
  64. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/index.md
  65. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/make-it-easy-for-users/100-elicit-implementation-intentions.md
  66. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/make-it-easy-for-users/101-default-everything.md
  67. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/make-it-easy-for-users/102-lessen-the-burden-of-action-info.md
  68. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/make-it-easy-for-users/103-deploy-peer-comparisons.md
  69. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/positive-intuitive-reaction/100-make-ui-professional-and-beautiful.md
  70. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/positive-intuitive-reaction/101-deploy-social-proof.md
  71. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/positive-intuitive-reaction/102-deploy-strong-subject-authority.md
  72. 2
      src/data/roadmaps/ux-design/content/105-ux-best-practices/positive-intuitive-reaction/103-be-authentic-and-personal.md
  73. 2
      src/data/roadmaps/ux-design/content/106-measuring-the-impact/100-gather-lessons-prioritize-integrate.md
  74. 2
      src/data/roadmaps/ux-design/content/106-measuring-the-impact/index.md
  75. 2
      src/data/roadmaps/ux-design/content/106-measuring-the-impact/testing/100-incremental-ab-testing.md
  76. 2
      src/data/roadmaps/ux-design/content/106-measuring-the-impact/testing/101-multivariate-testing.md

@ -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]);
});

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

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

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

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

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

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

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

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

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

@ -1 +1 @@
# Measuring the impact
# Measuring the Impact
Loading…
Cancel
Save