react-native-navigation的迁移库

generate-js-doc.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const jsdoc2md = require('jsdoc-to-markdown');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const BASE_DIR = './lib/src/params/';
  5. const OPTIONS_DIR = BASE_DIR + 'options/';
  6. const CONTAINERS_DIR = BASE_DIR + 'containers/';
  7. const OUTPUT_DIR = './docs/docs/';
  8. const PARAMS_PARTIALS = ['./docs/templates/header.hbs', './docs/templates/sig-name.hbs'];
  9. const PARTIALS = ['./docs/templates/scope.hbs', './docs/templates/docs.hbs'];
  10. const generateMarkdownForFile = ({ file, outputDir, partial, separator }) => {
  11. const templateData = jsdoc2md.getTemplateDataSync({ files: file });
  12. const classNames = getClassesInFile(templateData);
  13. classNames.forEach((className) => createDocFileForClass({ className, templateData, outputDir, partial, separator }));
  14. };
  15. function getClassesInFile(templateData) {
  16. const classNames = templateData.reduce((classNames, identifier) => {
  17. if (identifier.kind === 'class') {
  18. classNames.push(identifier.name);
  19. }
  20. return classNames;
  21. }, []);
  22. return classNames;
  23. }
  24. function createDocFileForClass({ className, templateData, outputDir, partial = [], separator = true }) {
  25. const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`;
  26. const options = {
  27. data: templateData,
  28. template,
  29. separators: separator,
  30. partial: [...PARTIALS, ...partial]
  31. };
  32. console.log(`rendering ${className}`);
  33. const output = jsdoc2md.renderSync(options);
  34. fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output);
  35. }
  36. function inputFiles() {
  37. return [
  38. { file: './lib/src/Navigation.js', outputDir: OUTPUT_DIR },
  39. ...fs.readdirSync(OPTIONS_DIR).map((file) => {
  40. return {
  41. file: OPTIONS_DIR + file,
  42. outputDir: OUTPUT_DIR + 'options/',
  43. partial: PARAMS_PARTIALS,
  44. separator: false
  45. };
  46. }),
  47. ...fs.readdirSync(CONTAINERS_DIR)
  48. .map((file) => {
  49. return {
  50. file: CONTAINERS_DIR + file,
  51. outputDir: OUTPUT_DIR,
  52. partial: PARAMS_PARTIALS,
  53. separator: false
  54. };
  55. }),
  56. ...fs.readdirSync(BASE_DIR)
  57. .filter((file) => fs.statSync(BASE_DIR + file).isFile())
  58. .map((file) => {
  59. return {
  60. file: BASE_DIR + file,
  61. outputDir: OUTPUT_DIR
  62. };
  63. })
  64. ];
  65. }
  66. inputFiles().forEach((inputFile) => generateMarkdownForFile(inputFile));