dgeni-config.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. var Package = require('dgeni').Package;
  2. var jsdocPackage = require('dgeni-packages/jsdoc');
  3. var nunjucksPackage = require('dgeni-packages/nunjucks');
  4. var typescriptPackage = require('dgeni-packages/typescript');
  5. var linksPackage = require('dgeni-packages/links');
  6. // var typescriptPackage = require('./typescript-package');
  7. // var linksPackage = require('./links-package');
  8. var gitPackage = require('dgeni-packages/git');
  9. var path = require('path');
  10. var semver = require('semver');
  11. var fs = require('fs');
  12. var _ = require('lodash');
  13. var config = require('../config.json');
  14. // Define the dgeni package for generating the docs
  15. module.exports = function(currentVersion) {
  16. return new Package('ionic-storage-docs',
  17. [jsdocPackage, nunjucksPackage, typescriptPackage,
  18. linksPackage, gitPackage])
  19. .processor(require('./processors/remove-private-members'))
  20. .processor(require('./processors/hide-private-api'))
  21. .processor(require('./processors/collect-inputs-outputs'))
  22. .processor(require('./processors/parse-returns-object'))
  23. .processor(require('./processors/latest-version'))
  24. // .processor(require('./processors/index-page'))
  25. .processor(require('./processors/jekyll'))
  26. // for debugging docs
  27. // .processor(function test(){
  28. // return {
  29. //
  30. // $runBefore: ['rendering-docs'],
  31. // $process: function(docs){
  32. // docs.forEach(function(doc){
  33. // if (doc.name == "Searchbar"){
  34. // console.log(doc.input);
  35. // doc.members.forEach(function(method){
  36. // if (method.name === "load") {
  37. // console.log(method);
  38. // }
  39. // })
  40. // }
  41. // })
  42. // }
  43. // }
  44. // })
  45. .config(function(log) {
  46. log.level = 'error'; //'silly', 'debug', 'info', 'warn', 'error'
  47. })
  48. .config(function(renderDocsProcessor, computePathsProcessor, versionInfo) {
  49. try {
  50. versions = fs.readdirSync(
  51. path.resolve(__dirname, '../../' + config.docsDest + '/')
  52. ).filter(semver.valid);
  53. } catch (e) {
  54. versions = [];
  55. }
  56. // new version, add it to the versions list
  57. if (currentVersion != 'nightly' && !_.contains(versions, currentVersion)) {
  58. versions.unshift(currentVersion);
  59. }
  60. // sort by version so we can find latest
  61. versions.sort(semver.rcompare);
  62. // add nightly if it isn't in the list
  63. !_.contains(versions, 'nightly') && versions.unshift('nightly');
  64. //First semver valid version is latest
  65. var latestVersion = _.find(versions, semver.valid);
  66. versions = versions.map(function(version) {
  67. //Latest version is in docs root
  68. //var folder = version == latestVersion ? '' : version;
  69. // Instead set nightly as docs root
  70. var folder = version == 'nightly' ? '' : version;
  71. return {
  72. href: path.join('/' + config.clientDocsDir, folder),
  73. folder: folder,
  74. name: version
  75. };
  76. });
  77. var versionData = {
  78. list: versions,
  79. current: _.find(versions, {name: currentVersion}),
  80. latest: _.find(versions, {name: latestVersion}) || _.first(versions)
  81. };
  82. renderDocsProcessor.extraData.version = versionData;
  83. renderDocsProcessor.extraData.versionInfo = versionInfo;
  84. computePathsProcessor.pathTemplates = [{
  85. docTypes: ['class', 'var', 'function', 'let'],
  86. getOutputPath: function(doc) {
  87. // strip ionic from path root
  88. var docPath = doc.fileInfo.relativePath.replace(/^src\//, '');
  89. // remove filename since we have multiple docTypes per file
  90. docPath = docPath.substring(0, docPath.lastIndexOf('/') + 1);
  91. docPath += doc.name + '/index.md';
  92. var path = config.clientDocsDir + '/' + docPath;
  93. path = path.replace(process.cwd() + '/src', '');
  94. return path;
  95. }
  96. }];
  97. })
  98. //configure file reading
  99. .config(function(readFilesProcessor, readTypeScriptModules) {
  100. // Don't run unwanted processors since we are not using the normal file reading processor
  101. readFilesProcessor.$enabled = false;
  102. readFilesProcessor.basePath = path.resolve(__dirname, '../..');
  103. readTypeScriptModules.basePath = path.resolve(
  104. path.resolve(__dirname, '../..')
  105. );
  106. readTypeScriptModules.sourceFiles = [
  107. 'src/storage.ts'
  108. ];
  109. })
  110. .config(function(parseTagsProcessor) {
  111. parseTagsProcessor.tagDefinitions = parseTagsProcessor.tagDefinitions
  112. .concat(require('./tag-defs/tag-defs'));
  113. })
  114. // .config(function(parseTagsProcessor) {
  115. // // We actually don't want to parse param docs in this package as we are getting the data out using TS
  116. // parseTagsProcessor.tagDefinitions.forEach(function(tagDef) {
  117. // console.log(tagDef);
  118. // if (tagDef.name === 'param') {
  119. // tagDef.docProperty = 'paramData';
  120. // tagDef.transforms = [];
  121. // }
  122. // });
  123. // })
  124. // Configure links
  125. .config(function(getLinkInfo) {
  126. getLinkInfo.useFirstAmbiguousLink = false;
  127. })
  128. // Configure file writing
  129. .config(function(writeFilesProcessor) {
  130. writeFilesProcessor.outputFolder = config.sitePath;
  131. })
  132. // Configure rendering
  133. .config(function(templateFinder, templateEngine) {
  134. // Nunjucks and Angular conflict in their template bindings so change the Nunjucks
  135. // Also conflict with Jekyll
  136. templateEngine.config.tags = {
  137. variableStart: '<$',
  138. variableEnd: '$>',
  139. blockStart: '<@',
  140. blockEnd: '@>',
  141. commentStart: '<#',
  142. commentEnd: '#>'
  143. };
  144. // add custom filters to nunjucks
  145. templateEngine.filters.push(
  146. require('./filters/capital'),
  147. require('./filters/code'),
  148. require('./filters/dump')
  149. );
  150. templateFinder.templateFolders.unshift(
  151. path.resolve(__dirname, 'templates')
  152. );
  153. // Specify how to match docs to templates.
  154. templateFinder.templatePatterns = [
  155. '${ doc.template }',
  156. '${ doc.docType }.template.html',
  157. 'common.template.html'
  158. ];
  159. });
  160. };