help-file.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const fs = require("fs");
  2. const process = require("process")
  3. const phaser_path = process.env.PHASER_PATH;
  4. const phaser_json_path = phaser_path + "/phaser3-docs/json/phaser.json";
  5. const content = fs.readFileSync(phaser_json_path);
  6. const data = JSON.parse(content.toString());
  7. const docsMap = {};
  8. for(const item of data.docs) {
  9. const longname = item.longname.replace("#", ".");
  10. docsMap[longname] = item.description || item.classdesc;
  11. if (item.params) {
  12. for(const param of item.params) {
  13. docsMap[longname + "(" + param.name + ")"] = param.description;
  14. }
  15. } else if (item.properties) {
  16. for(const prop of item.properties) {
  17. docsMap[longname + "." + prop.name] = prop.description;
  18. }
  19. }
  20. }
  21. function makeHelpFile(members, outputPath) {
  22. console.log(outputPath + ":")
  23. const outputMap = {};
  24. for(const name of members) {
  25. const docs = docsMap[name];
  26. if (docs) {
  27. outputMap[name] = docs;
  28. console.log(name + " -> " + docs.substring(0, Math.min(docs.length, 80)).split("\n").join(" ") + "...")
  29. } else {
  30. console.log("Cannot find name " + name);
  31. throw new Error("Cannot find name: " + name);
  32. }
  33. }
  34. const output = JSON.stringify(outputMap, null, 2);
  35. console.log("---");
  36. fs.writeFileSync(outputPath, output);
  37. }
  38. module.exports = {
  39. makeHelpFile: makeHelpFile
  40. }