react-native-navigation的迁移库

generate-js-doc.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 = [
  10. './docs/templates/scope.hbs',
  11. './docs/templates/docs.hbs',
  12. './docs/templates/param-table-name.hbs',
  13. '/docs/templates/linked-type-list.hbs',
  14. './docs/templates/link.hbs',
  15. './docs/templates/params-table.hbs'
  16. ];
  17. const generateMarkdownForFile = ({ file, outputDir, partial, separator }) => {
  18. const templateData = jsdoc2md.getTemplateDataSync({ files: file });
  19. const classNames = getClassesInFile(templateData);
  20. classNames.forEach((className) => createDocFileForClass({ className, templateData, outputDir, partial, separator }));
  21. };
  22. function getClassesInFile(templateData) {
  23. const classNames = templateData.reduce((classNames, identifier) => {
  24. if (identifier.kind === 'class') {
  25. classNames.push(identifier.name);
  26. }
  27. return classNames;
  28. }, []);
  29. return classNames;
  30. }
  31. function createDocFileForClass({ className, templateData, outputDir, partial = [], separator = true }) {
  32. const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`;
  33. const options = {
  34. data: templateData,
  35. template,
  36. separators: separator,
  37. 'heading-depth': 1,
  38. helper: ['./docs/linkify.js', './docs/stringify.js'],
  39. partial: [...PARTIALS, ...partial]
  40. };
  41. console.log(`rendering ${className}`);
  42. const output = jsdoc2md.renderSync(options);
  43. fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output);
  44. }
  45. function inputFiles() {
  46. return [
  47. { file: './lib/src/Navigation.js', outputDir: OUTPUT_DIR },
  48. ...fs.readdirSync(OPTIONS_DIR).map((file) => {
  49. return {
  50. file: OPTIONS_DIR + file,
  51. outputDir: OUTPUT_DIR + 'options/',
  52. partial: PARAMS_PARTIALS,
  53. separator: false
  54. };
  55. }),
  56. ...fs.readdirSync(CONTAINERS_DIR)
  57. .map((file) => {
  58. return {
  59. file: CONTAINERS_DIR + file,
  60. outputDir: OUTPUT_DIR,
  61. partial: PARAMS_PARTIALS,
  62. separator: false
  63. };
  64. }),
  65. ...fs.readdirSync(BASE_DIR)
  66. .filter((file) => fs.statSync(BASE_DIR + file).isFile())
  67. .map((file) => {
  68. return {
  69. file: BASE_DIR + file,
  70. outputDir: OUTPUT_DIR
  71. };
  72. })
  73. ];
  74. }
  75. inputFiles().forEach((inputFile) => generateMarkdownForFile(inputFile));