|
1 |
| -/* |
2 |
| - * grunt-documentation |
3 |
| - * https://github.com/documentationjs/grunt-documentation |
4 |
| - * |
5 |
| - * Copyright (c) 2015 André Fiedler |
6 |
| - * Licensed under the MIT license. |
7 |
| - */ |
8 |
| -'use strict'; |
9 |
| - |
10 |
| -module.exports = function(grunt) { |
11 |
| - |
12 |
| - var path = require('path'), |
13 |
| - chalk = require('chalk'), |
14 |
| - documentation = require('documentation').build || require('documentation'), |
15 |
| - formats = require('documentation').formats; |
16 |
| - |
17 |
| - grunt.registerMultiTask('documentation', 'Use Grunt with documentation to generate great documentation for your JavaScript projects.', function() { |
18 |
| - var options = this.options({ |
19 |
| - format: 'html', |
20 |
| - shallow: false, |
21 |
| - github: false, |
22 |
| - access: ['public', 'protected', 'undefined'], |
23 |
| - order: [] |
24 |
| - }); |
25 |
| - |
26 |
| - var formatter = formats[options.format]; |
27 |
| - if (!formatter) { |
28 |
| - throw new Error('invalid format given: valid options are ' + Object.keys(formats).join(', ')); |
29 |
| - } |
30 |
| - |
31 |
| - var docOptions = { |
32 |
| - github: options.github, |
33 |
| - shallow: options.shallow, |
34 |
| - access: options.access, |
35 |
| - toc: options.toc || options.order, |
36 |
| - theme: options.theme, |
37 |
| - name: options.name, |
38 |
| - version: options.version |
39 |
| - }; |
40 |
| - |
41 |
| - var done = this.async(), |
42 |
| - waiting = 0; |
43 |
| - |
44 |
| - function await (c) { |
45 |
| - c = c || 1; |
46 |
| - waiting += c; |
47 |
| - } |
48 |
| - |
49 |
| - function release() { |
50 |
| - waiting--; |
51 |
| - if (waiting <= 0) { |
52 |
| - done(); |
53 |
| - grunt.log.writeln(chalk.green('Done, created documentation at ') + path.join(process.cwd(), options.destination)); |
54 |
| - } |
55 |
| - } |
56 |
| - |
57 |
| - function generateDocs(files) { |
58 |
| - await (); |
59 |
| - documentation(files, docOptions, function(err, comments) { |
60 |
| - if (err) { |
61 |
| - grunt.log.error(err.toString()); |
62 |
| - if (err.codeFrame) { |
63 |
| - grunt.log.error(err.codeFrame); |
64 |
| - } |
65 |
| - done(false); |
66 |
| - } else { |
67 |
| - await (); |
68 |
| - formatter(comments, docOptions, function(err, output) { |
69 |
| - if (err) { |
70 |
| - grunt.log.error(err.toString()); |
71 |
| - if (err.codeFrame) { |
72 |
| - grunt.log.error(err.codeFrame); |
73 |
| - } |
74 |
| - done(false); |
75 |
| - } else { |
76 |
| - if (options.format === 'json' || options.format === 'md') { |
77 |
| - var dest = path.join(process.cwd(), options.destination, (options.filename || 'API.' + options.format)); |
78 |
| - grunt.file.write(dest, output); |
79 |
| - grunt.log.writeln('File ' + chalk.cyan(options.filename || 'API.' + options.format) + ' created.'); |
80 |
| - } else if (options.format === 'html') { |
81 |
| - await (output.length); |
82 |
| - output.forEach(function(file) { |
83 |
| - var dest = path.join(process.cwd(), options.destination, file.relative); |
84 |
| - if (file.isDirectory() || grunt.file.isDir(file.path)) { |
85 |
| - grunt.file.mkdir(dest); |
86 |
| - grunt.verbose.writeln('Directory ' + chalk.cyan(file.relative) + ' created.'); |
87 |
| - } else { |
88 |
| - grunt.file.write(dest, file.contents); |
89 |
| - grunt.verbose.writeln('File ' + chalk.cyan(file.relative) + ' created.'); |
90 |
| - } |
91 |
| - release(); |
92 |
| - }); |
93 |
| - } |
94 |
| - } |
95 |
| - release(); |
96 |
| - }); |
97 |
| - } |
98 |
| - release(); |
99 |
| - }); |
100 |
| - } |
101 |
| - |
102 |
| - var files = []; |
103 |
| - |
104 |
| - var filesToProcess = this.files.length; |
105 |
| - |
106 |
| - this.files.forEach(function(f) { |
107 |
| - var src = f.src.filter(function(filepath) { |
108 |
| - // Warn on and remove invalid source files (if nonull was set). |
109 |
| - if (!grunt.file.exists(filepath)) { |
110 |
| - grunt.log.warn('Source file "' + filepath + '" not found.'); |
111 |
| - return false; |
112 |
| - } else { |
113 |
| - return true; |
114 |
| - } |
115 |
| - }); |
116 |
| - files = files.concat(src); |
117 |
| - filesToProcess--; |
118 |
| - if (filesToProcess <= 0) { |
119 |
| - generateDocs(files); |
120 |
| - } |
121 |
| - }.bind(this)); |
122 |
| - }); |
123 |
| - |
124 |
| -}; |
| 1 | +/* |
| 2 | + * grunt-documentation |
| 3 | + * https://github.com/documentationjs/grunt-documentation |
| 4 | + * |
| 5 | + * Copyright (c) 2015 André Fiedler |
| 6 | + * Licensed under the MIT license. |
| 7 | + */ |
| 8 | +'use strict'; |
| 9 | + |
| 10 | +module.exports = function(grunt) { |
| 11 | + var path = require('path'), |
| 12 | + chalk = require('chalk'), |
| 13 | + documentation = require('documentation').build || require('documentation'), |
| 14 | + formats = require('documentation').formats; |
| 15 | + |
| 16 | + grunt.registerMultiTask( |
| 17 | + 'documentation', |
| 18 | + 'Use Grunt with documentation to generate great documentation for your JavaScript projects.', |
| 19 | + function() { |
| 20 | + var options = this.options({ |
| 21 | + format: 'html', |
| 22 | + shallow: false, |
| 23 | + github: false, |
| 24 | + access: ['public', 'protected', 'undefined'], |
| 25 | + order: [] |
| 26 | + }); |
| 27 | + |
| 28 | + var formatter = formats[options.format]; |
| 29 | + if (!formatter) { |
| 30 | + throw new Error( |
| 31 | + 'invalid format given: valid options are ' + |
| 32 | + Object.keys(formats).join(', ') |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + var docOptions = { |
| 37 | + github: options.github, |
| 38 | + shallow: options.shallow, |
| 39 | + access: options.access, |
| 40 | + toc: options.toc || options.order, |
| 41 | + theme: options.theme, |
| 42 | + name: options.name, |
| 43 | + version: options.version |
| 44 | + }; |
| 45 | + |
| 46 | + var done = this.async(), waiting = 0; |
| 47 | + |
| 48 | + function wait(c) { |
| 49 | + c = c || 1; |
| 50 | + waiting += c; |
| 51 | + } |
| 52 | + |
| 53 | + function release() { |
| 54 | + waiting--; |
| 55 | + if (waiting <= 0) { |
| 56 | + done(); |
| 57 | + grunt.log.writeln( |
| 58 | + chalk.green('Done, created documentation at ') + |
| 59 | + path.join(process.cwd(), options.destination) |
| 60 | + ); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + function generateDocs(files) { |
| 65 | + wait(); |
| 66 | + documentation(files, docOptions, function(err, comments) { |
| 67 | + if (err) { |
| 68 | + grunt.log.error(err.toString()); |
| 69 | + if (err.codeFrame) { |
| 70 | + grunt.log.error(err.codeFrame); |
| 71 | + } |
| 72 | + done(false); |
| 73 | + } else { |
| 74 | + wait(); |
| 75 | + formatter(comments, docOptions, function(err, output) { |
| 76 | + if (err) { |
| 77 | + grunt.log.error(err.toString()); |
| 78 | + if (err.codeFrame) { |
| 79 | + grunt.log.error(err.codeFrame); |
| 80 | + } |
| 81 | + done(false); |
| 82 | + } else { |
| 83 | + if (options.format === 'json' || options.format === 'md') { |
| 84 | + var dest = path.join( |
| 85 | + process.cwd(), |
| 86 | + options.destination, |
| 87 | + options.filename || 'API.' + options.format |
| 88 | + ); |
| 89 | + grunt.file.write(dest, output); |
| 90 | + grunt.log.writeln( |
| 91 | + 'File ' + |
| 92 | + chalk.cyan(options.filename || 'API.' + options.format) + |
| 93 | + ' created.' |
| 94 | + ); |
| 95 | + } else if (options.format === 'html') { |
| 96 | + wait(output.length); |
| 97 | + output.forEach(function(file) { |
| 98 | + var dest = path.join( |
| 99 | + process.cwd(), |
| 100 | + options.destination, |
| 101 | + file.relative |
| 102 | + ); |
| 103 | + if (file.isDirectory() || grunt.file.isDir(file.path)) { |
| 104 | + grunt.file.mkdir(dest); |
| 105 | + grunt.verbose.writeln( |
| 106 | + 'Directory ' + chalk.cyan(file.relative) + ' created.' |
| 107 | + ); |
| 108 | + } else { |
| 109 | + grunt.file.write(dest, file.contents); |
| 110 | + grunt.verbose.writeln( |
| 111 | + 'File ' + chalk.cyan(file.relative) + ' created.' |
| 112 | + ); |
| 113 | + } |
| 114 | + release(); |
| 115 | + }); |
| 116 | + } |
| 117 | + } |
| 118 | + release(); |
| 119 | + }); |
| 120 | + } |
| 121 | + release(); |
| 122 | + }); |
| 123 | + } |
| 124 | + |
| 125 | + var files = []; |
| 126 | + |
| 127 | + var filesToProcess = this.files.length; |
| 128 | + |
| 129 | + this.files.forEach( |
| 130 | + function(f) { |
| 131 | + var src = f.src.filter(function(filepath) { |
| 132 | + // Warn on and remove invalid source files (if nonull was set). |
| 133 | + if (!grunt.file.exists(filepath)) { |
| 134 | + grunt.log.warn('Source file "' + filepath + '" not found.'); |
| 135 | + return false; |
| 136 | + } else { |
| 137 | + return true; |
| 138 | + } |
| 139 | + }); |
| 140 | + files = files.concat(src); |
| 141 | + filesToProcess--; |
| 142 | + if (filesToProcess <= 0) { |
| 143 | + generateDocs(files); |
| 144 | + } |
| 145 | + }.bind(this) |
| 146 | + ); |
| 147 | + } |
| 148 | + ); |
| 149 | +}; |
0 commit comments