blob: 97569549c0350fccc728bd060019cfe393d6d7f5 [file] [log] [blame]
Matteo Scandolo280dcd32016-05-16 09:59:38 -07001'use strict';
2
3var _ = require('lodash'),
4 docdown = require('docdown'),
5 fs = require('fs-extra'),
6 path = require('path');
7
8var basePath = path.join(__dirname, '..', '..'),
9 docPath = path.join(basePath, 'doc'),
10 readmePath = path.join(docPath, 'README.md');
11
12var pkg = require('../../package.json'),
13 version = pkg.version;
14
15var config = {
16 'base': {
17 'entryLinks': [
18 '<% if (name == "templateSettings" || !/^(?:methods|properties|seq)$/i.test(category)) {' +
19 'print("[&#x24C3;](https://www.npmjs.com/package/lodash." + name.toLowerCase() + " \\"See the npm package\\")")' +
20 '} %>'
21 ],
22 'path': path.join(basePath, 'lodash.js'),
23 'title': '<a href="https://lodash.com/">lodash</a> <span>v' + version + '</span>',
24 'toc': 'categories',
25 'url': 'https://github.com/lodash/lodash/blob/' + version + '/lodash.js'
26 },
27 'github': {
28 'hash': 'github'
29 },
30 'site': {
31 'tocLink': '#docs'
32 }
33};
34
35function postprocess(string) {
36 // Fix docdown bugs.
37 return string
38 // Repair the default value of `chars`.
39 // See https://github.com/eslint/doctrine/issues/157 for more details.
40 .replace(/\bchars=''/g, "chars=' '")
41 // Wrap symbol property identifiers in brackets.
42 .replace(/\.(Symbol\.(?:[a-z]+[A-Z]?)+)/g, '[$1]');
43}
44
45/*----------------------------------------------------------------------------*/
46
47function onComplete(error) {
48 if (error) {
49 throw error;
50 }
51}
52
53function build(type) {
54 var options = _.defaults({}, config.base, config[type]),
55 markdown = docdown(options);
56
57 fs.writeFile(readmePath, postprocess(markdown), onComplete);
58}
59
60build(_.last(process.argv));