react-native-navigation的迁移库

generate-js-doc.js 2.6KB

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