1
1
var _ = require ( 'lodash' ) ;
2
2
var path = require ( 'path' ) ;
3
- var packagePath = __dirname ;
4
- var basePackage = require ( 'dgeni-packages/jsdoc' ) ;
3
+ var Package = require ( 'dgeni' ) . Package ;
5
4
6
- module . exports = function ( config ) {
5
+ var jsDocProcessor = require ( 'dgeni-packages/jsdoc' ) ;
7
6
8
- config = basePackage ( config ) ;
9
-
10
- // Use the jsdoc extractor instead of the default to parse the function name.
11
- config . set ( 'source.extractors' , [
12
- require ( 'dgeni-packages/jsdoc/extractors/jsdoc.js' )
13
- ] ) ;
14
-
15
- /*
16
- * Add a couple of processors to the pipe to do extra parsing and rendering.
17
- *
18
- * tag-fixer: Get the name of the function, format the @param and @return
19
- * annotations to prepare them for rendering.
20
- * filter-jsdoc: Filter the functions that will not be part of the output
21
- * documentation and generate a unique name for the output partial file.
22
- * set-file-name: Add a file name that can be sorted alphabetically.
23
- * add-links: Add links to the source code for protractor.js, locators.js,
24
- * and webdriver.js.
25
- * add-toc: Add the table of contents.
26
- */
27
- config . append ( 'processing.processors' , [
28
- require ( './processors/tag-fixer' ) ,
29
- require ( './processors/filter-jsdoc' ) ,
30
- require ( './processors/set-file-name' ) ,
31
- require ( './processors/add-links' ) ,
32
- require ( './processors/add-toc' )
33
- ] ) ;
34
-
35
- /*
36
- * Add custom filters.
37
- */
38
- config . append ( 'rendering.filters' , [
39
- require ( './filters/link-slugify' )
40
- ] ) ;
41
-
42
- // Configure the tags that will be parsed from the jsDoc.
43
- var tagDefs = require ( 'dgeni-packages/jsdoc/tag-defs' ) ;
7
+ // Configure the tags that will be parsed from the jsDoc.
8
+ jsDocProcessor . config ( function ( parseTagsProcessor ) {
9
+ var tagDefs = parseTagsProcessor . tagDefinitions ;
44
10
45
11
// Parse the following annotations.
46
12
tagDefs . push ( { name : 'alias' } ) ;
@@ -56,36 +22,50 @@ module.exports = function(config) {
56
22
// The name tag should not be required.
57
23
var nameTag = _ . find ( tagDefs , { name : 'name' } ) ;
58
24
nameTag . required = false ;
59
-
60
- config . set ( 'processing.tagDefinitions' , tagDefs ) ;
61
-
62
- // OutputPath for docs that do not already have them.
63
- config . set ( 'rendering.contentsFolder' ,
64
- path . resolve ( config . basePath , 'build' ) ) ;
65
-
66
- // Base path is the protractor root dir.
67
- var basePath = path . resolve ( packagePath , '../..' ) ;
68
-
69
- // Generate documentation for protractor, locators, and webdriver.
70
- config . set ( 'source.files' , [
71
- { pattern : 'lib/**/protractor.js' , basePath : basePath } ,
72
- { pattern : 'lib/**/locators.js' , basePath : basePath } ,
73
- { pattern : 'node_modules/selenium-webdriver/lib/webdriver/webdriver.js' ,
74
- basePath : basePath }
75
- ] ) ;
76
-
77
- // TODO(andres): Add ability to link to previous versions.
78
- config . set ( 'linksHash' , 'master' ) ;
79
- config . set ( 'source.projectPath' , basePath ) ;
80
- config . set ( 'rendering.outputFolder' , 'build' ) ;
81
- config . set ( 'logging.level' , 'debug' ) ;
82
-
83
- var docsPath = path . resolve ( 'docgen/templates' ) ;
84
- config . set ( 'rendering.templateFolders' , [ docsPath ] ) ;
85
-
86
- config . set ( 'rendering.templatePatterns' , [
87
- '${ doc.template }-template.txt'
88
- ] ) ;
89
-
90
- return config ;
91
- } ;
25
+ } ) ;
26
+
27
+ var myPackage = new Package ( 'myPackage' , [
28
+ jsDocProcessor ,
29
+ require ( 'dgeni-packages/nunjucks' )
30
+ ] ) ;
31
+
32
+ /*
33
+ * Add a couple of processors to the pipe to do extra parsing and rendering.
34
+ *
35
+ * tag-fixer: Get the name of the function, format the @param and @return
36
+ * annotations to prepare them for rendering.
37
+ * filter-jsdoc: Filter the functions that will not be part of the output
38
+ * documentation and generate a unique name for the output partial file.
39
+ * add-links: Add links to the source code for protractor.js, locators.js,
40
+ * and webdriver.js.
41
+ * add-toc: Add the table of contents.
42
+ */
43
+ myPackage . processor ( require ( './processors/tag-fixer' ) ) ;
44
+ myPackage . processor ( require ( './processors/filter-jsdoc' ) ) ;
45
+ myPackage . processor ( require ( './processors/set-file-name' ) ) ;
46
+ myPackage . processor ( require ( './processors/add-links' ) ) ;
47
+ myPackage . processor ( require ( './processors/add-toc' ) ) ;
48
+
49
+ myPackage . config ( function ( readFilesProcessor , templateFinder , writeFilesProcessor ) {
50
+
51
+ // Go to the protractor project root.
52
+ readFilesProcessor . basePath = path . resolve ( __dirname , '../..' ) ;
53
+
54
+ readFilesProcessor . sourceFiles = [
55
+ { include : 'lib/**/protractor.js' } ,
56
+ { include : 'lib/**/locators.js' } ,
57
+ { include : 'node_modules/selenium-webdriver/lib/webdriver/webdriver.js' }
58
+ ] ;
59
+
60
+ // Add a folder to search for our own templates to use when rendering docs
61
+ templateFinder . templateFolders . unshift ( path . resolve ( 'docgen/templates' ) ) ;
62
+
63
+ // Specify how to match docs to templates.
64
+ // In this case we just use the same static template for all docs
65
+ templateFinder . templatePatterns . unshift ( 'toc-template.txt' ) ;
66
+
67
+ // Specify where the writeFilesProcessor will write our generated doc files
68
+ writeFilesProcessor . outputFolder = 'website/docgen/build' ;
69
+ } ) ;
70
+
71
+ module . exports = myPackage ;
0 commit comments