help-file.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 spine_json_path = phaser_path + "/spine-phaser-docs/out.json";
  6. const docsMap = {};
  7. for (const inputJsonFile of [phaser_json_path, spine_json_path]) {
  8. const content = fs.readFileSync(inputJsonFile);
  9. const data = JSON.parse(content.toString());
  10. for (const item of data.docs) {
  11. let longname = item.longname.replace("#", ".");
  12. if (item.meta && item.meta.path
  13. && (item.meta.path.endsWith("spine-phaser-docs/spine-core/dist")
  14. || item.meta.path.endsWith("spine-phaser-docs/spine-phaser/dist"))) {
  15. longname = "spine." + longname;
  16. }
  17. docsMap[longname] = item.description || item.classdesc;
  18. if (item.params) {
  19. for (const param of item.params) {
  20. docsMap[longname + "(" + param.name + ")"] = param.description;
  21. }
  22. } else if (item.properties) {
  23. for (const prop of item.properties) {
  24. docsMap[longname + "." + prop.name] = prop.description;
  25. }
  26. }
  27. }
  28. }
  29. function makeHelpFile(members, outputPath, source) {
  30. console.log(outputPath + ":")
  31. const outputMap = {};
  32. for (const name of members) {
  33. const docs = docsMap[name];
  34. if (docs) {
  35. outputMap[name] = docs;
  36. console.log(name + " -> " + docs.substring(0, Math.min(docs.length, 80)).split("\n").join(" ") + "...")
  37. } else {
  38. console.log("Cannot find name " + name);
  39. throw new Error("Cannot find name: " + name);
  40. }
  41. }
  42. const output = JSON.stringify(outputMap, null, 2);
  43. console.log("---");
  44. fs.writeFileSync(outputPath, output);
  45. }
  46. module.exports = {
  47. makeHelpFile: makeHelpFile
  48. }