1 | 1 | var fs = require('fs'); |
|
2 | 1 | var mkdirp = require('mkdirp').sync; |
|
3 | 1 | var path = require('path'); |
|
4 | 1 | var through = new require('through2'); |
|
5 | 1 | var vfs = new require('vinyl-fs'); |
|
6 | 1 | var glob = require('glob'); |
|
7 | 1 | var globAll = require('glob-all'); |
|
8 | 1 | var extend = require('extend'); |
|
9 | 1 | var resolvePath = require('../util/module-or-process-path'); |
|
10 | 1 | var relativeRootUrl = require('../util/relative-root-url'); |
|
11 | |||
12 | /** |
||
13 | * run doc page building |
||
14 | * - either by given 'src' option |
||
15 | * - or through vinyl/gulp filestream |
||
16 | * |
||
17 | * @returns {stream} |
||
18 | */ |
||
19 | function buildDocs() { |
||
20 | 20 | var dirs = this.options; |
|
21 | |||
22 | // the main selector are the pattern doc files |
||
23 | // default: [partial-path]/**/*.{md,markdown} |
||
24 | // |
||
25 | // ...but first, (re)set layout and page template |
||
26 | // just to be sure ^^ |
||
27 | 20 | this.layout = this.options.gui.layout; |
|
28 | 20 | this.pagetemplate = this.options.gui.docpage; |
|
29 | 20 | if (dirs.partials) { |
|
30 | 20 | var patternDirs = dirs.pattern.dirs, |
|
31 | 20 | key = 'readme', |
|
32 | 20 | streamBase = path.join((dirs.partials), ''), |
|
33 | 20 | vfs_glob = globAll.sync(path.join(streamBase, dirs.pattern.searchpath, dirs.pattern[key])), |
|
34 | //x = console.log(vfs_glob), |
||
35 | 20 | stream = vfs_glob.length ? vfs.src(vfs_glob, { base: this.options.base, allowEmpty: true }) |
|
36 | .pipe(transformPatternDocs.apply(this)) : false |
||
37 | //.on('finish', function (done) { console.log(done); }) |
||
38 | ; |
||
39 | |||
40 | 20 | return stream; |
|
41 | } else { |
||
42 | return transformPatternDocs.apply(this); |
||
43 | } |
||
44 | |||
45 | function transformPatternDocs(file, enc, cb) { |
||
46 | return through.obj(function(file, enc, cb) { |
||
47 | this.parsedocs(file, function(err, data) { |
||
48 | // parsing is done... |
||
49 | |||
50 | // prepare rendering the doc page... |
||
51 | var fileName = path.basename(file.path); |
||
52 | var ext = path.extname(file.path); |
||
53 | var newName = this.options.pattern.target; |
||
54 | |||
55 | // new file-name |
||
56 | file.path = file.path.replace(fileName, newName); |
||
57 | |||
58 | var filePath = path.join( |
||
59 | this.options.dest, this.options.basepath, this.options.patternspath, |
||
60 | path.relative(path.join(process.cwd(), this.options.partials), file.path) |
||
61 | ); |
||
62 | // ensure dirs... |
||
63 | mkdirp(path.dirname(filePath)); |
||
64 | |||
65 | // assemble and assign root paths |
||
66 | var rootpath = path.join(this.options.dest, ''); |
||
67 | var basepath = path.join(this.options.dest, this.options.basepath); |
||
68 | var patternspath = path.join(this.options.dest, this.options.basepath, this.options.patternspath); |
||
69 | var categoriespath = path.join(this.options.dest, this.options.basepath, this.options.categoriespath); |
||
70 | data = this.renderdata(extend({ |
||
71 | page : path.basename(filePath, path.extname(filePath)), |
||
72 | layout : this.layoutname, |
||
73 | root : relativeRootUrl(filePath, rootpath), |
||
74 | baseroot : relativeRootUrl(filePath, basepath), |
||
75 | patternsroot : relativeRootUrl(filePath, patternspath), |
||
76 | categoriesroot : relativeRootUrl(filePath, categoriespath) |
||
77 | }, data)); |
||
78 | |||
79 | // Add special ad-hoc partials for #ifpage and #unlesspage |
||
80 | this.handlebars.registerHelper('ifpage', require('../handlebars/ifPage')(data.page)); |
||
81 | this.handlebars.registerHelper('unlesspage', require('../handlebars/unlessPage')(data.page)); |
||
82 | |||
83 | // build the doc page... |
||
84 | var pageSource = this.renderdocs(data); |
||
85 | /** global: Buffer */ |
||
86 | file.contents = new Buffer(pageSource); |
||
0 ignored issues
–
show
|
|||
87 | |||
88 | // Write new file to disk if necessary |
||
89 | 2 | if (this.options.dest) { |
|
90 | fs.writeFileSync(filePath, file.contents.toString()); |
||
91 | } |
||
92 | this.updatedatafiles(); |
||
93 | |||
94 | // Log page name, processing time, and adapters used to console |
||
95 | var name2log = path.dirname(path.relative(path.join(process.cwd(), this.options.partials), file.path)); |
||
96 | this.log.process(name2log, data, process.hrtime(this.time)); |
||
97 | |||
98 | cb(null, file); |
||
99 | |||
100 | }.bind(this)); |
||
101 | |||
102 | }.bind(this)); |
||
103 | }; |
||
104 | } |
||
105 | |||
106 | module.exports = buildDocs; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.