dgeni-config.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 gitPackage = require('dgeni-packages/git');
  7. var path = require('path');
  8. var semver = require('semver');
  9. var fs = require('fs');
  10. var _ = require('lodash');
  11. var config = require('../config.json');
  12. // Define the dgeni package for generating the docs
  13. module.exports = function(currentVersion, initialVersionBuild) {
  14. return new Package('ionic-v2-docs',
  15. [jsdocPackage, nunjucksPackage, typescriptPackage,
  16. linksPackage, gitPackage])
  17. .processor(require('./processors/latest-version'))
  18. .processor(require('./processors/index-page'))
  19. .processor(require('./processors/remove-private-members'))
  20. .processor(require('./processors/jekyll'))
  21. .processor(require('./processors/hide-private-api'))
  22. .processor(require('./processors/collect-inputs-outputs'))
  23. .processor(require('./processors/parse-returns-object'))
  24. .processor(require('./processors/parse-optional'))
  25. .processor(require('./processors/parse-sass'))
  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(path.resolve(__dirname, '../../' + config.docsDest + '/'))
  51. .filter(semver.valid)
  52. } catch(e) {
  53. versions = [];
  54. }
  55. // new version, add it to the versions list
  56. if (currentVersion != 'nightly' && !_.includes(versions, currentVersion)){
  57. versions.unshift(currentVersion);
  58. }
  59. // sort by version so we can find latest
  60. versions.sort(semver.rcompare);
  61. // add nightly if it isn't in the list
  62. !_.includes(versions, 'nightly') && versions.unshift('nightly');
  63. //First semver valid version is latest
  64. var latestVersion = _.find(versions, semver.valid);
  65. versions = versions.map(function(version) {
  66. // Set nightly as docs root
  67. //var folder = version == 'nightly' ? '' : version;
  68. //Instead set latest version in docs root if not initial build
  69. var folder = (version == latestVersion) && !initialVersionBuild ? '' : version;
  70. return {
  71. href: path.join('/' + config.v2DocsDir, folder).replace('/content',''),
  72. folder: folder,
  73. name: version
  74. };
  75. });
  76. var versionData = {
  77. list: versions,
  78. current: _.find(versions, { name: currentVersion }),
  79. latest: _.find(versions, {name: latestVersion}) || _.first(versions),
  80. initialVersionBuild: initialVersionBuild
  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.v2DocsDir + '/' + (versionData.current.folder || '') +
  93. '/api/' + docPath;
  94. path = path.replace('/home/ubuntu/ionic/src', '')
  95. .replace(__dirname.replace('ionic/scripts/docs', ''),'')
  96. .replace('/ionic/src','');
  97. return path;
  98. }
  99. }];
  100. })
  101. //configure file reading
  102. .config(function(readFilesProcessor, readTypeScriptModules) {
  103. // Don't run unwanted processors since we are not using the normal file reading processor
  104. readFilesProcessor.$enabled = false;
  105. readFilesProcessor.basePath = path.resolve(__dirname, '../..');
  106. readTypeScriptModules.basePath = path.resolve(path.resolve(__dirname, '../..'));
  107. readTypeScriptModules.sourceFiles = [
  108. 'src/index.ts'
  109. ];
  110. })
  111. .config(function(parseTagsProcessor) {
  112. parseTagsProcessor.tagDefinitions = parseTagsProcessor.tagDefinitions.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 allowedDocTypes
  125. .config(function(extractAccessTransform) {
  126. var allowedDocTypes = ['member'];
  127. allowedDocTypes.forEach(function(docType) {
  128. extractAccessTransform.allowedDocTypes.add(docType);
  129. });
  130. })
  131. // Configure links
  132. .config(function(getLinkInfo) {
  133. getLinkInfo.useFirstAmbiguousLink = false;
  134. })
  135. // Configure file writing
  136. .config(function(writeFilesProcessor) {
  137. writeFilesProcessor.outputFolder = config.sitePath;
  138. })
  139. // Configure rendering
  140. .config(function(templateFinder, templateEngine) {
  141. // Nunjucks and Angular conflict in their template bindings so change the Nunjucks
  142. // Also conflict with Jekyll
  143. templateEngine.config.tags = {
  144. variableStart: '<$',
  145. variableEnd: '$>',
  146. blockStart: '<@',
  147. blockEnd: '@>',
  148. commentStart: '<#',
  149. commentEnd: '#>'
  150. };
  151. // add custom filters to nunjucks
  152. templateEngine.filters.push(
  153. require('./filters/capital'),
  154. require('./filters/code'),
  155. require('./filters/dump'),
  156. require('./filters/platform')
  157. );
  158. templateFinder.templateFolders.unshift(path.resolve(__dirname, 'templates'));
  159. // Specify how to match docs to templates.
  160. templateFinder.templatePatterns = [
  161. '${ doc.template }',
  162. '${ doc.docType }.template.html',
  163. 'common.template.html'
  164. ]
  165. })
  166. }