3 const _ = require('lodash');
4 const docdown = require('docdown');
5 const fs = require('fs-extra');
6 const path = require('path');
8 const util = require('../common/util');
10 const basePath = path.join(__dirname, '..', '..');
11 const docPath = path.join(basePath, 'doc');
12 const readmePath = path.join(docPath, 'README.md');
14 const pkg = require('../../package.json');
15 const version = pkg.version;
19 'path': path.join(basePath, 'lodash.js'),
20 'title': `<a href="https://lodash.com/">lodash</a> <span>v${ version }</span>`,
22 'url': `https://github.com/lodash/lodash/blob/${ version }/lodash.js`
26 'sublinks': [npmLink('Ⓝ', 'See the npm package')]
29 'entryLink': '<a href="${entryHref}" class="fa fa-link"></a>',
30 'sourceLink': '[source](${sourceHref})',
33 'sublinks': [npmLink('npm package')]
38 * Composes a npm link from `text` and optional `title`.
41 * @param {string} text The link text.
42 * @param {string} [title] The link title.
43 * @returns {string} Returns the composed npm link.
45 function npmLink(text, title) {
47 '<% if (name == "templateSettings" || !/^(?:methods|properties|seq)$/i.test(category)) {' +
49 '"[' + text + '](https://www.npmjs.com/package/lodash." + name.toLowerCase() + ' +
50 '"' + (title == null ? '' : ' \\"' + title + '\\"') + ')"' +
57 * Post-process `markdown` to make adjustments.
60 * @param {string} markdown The markdown to process.
61 * @returns {string} Returns the processed markdown.
63 function postprocess(markdown) {
64 // Wrap symbol property identifiers in brackets.
65 return markdown.replace(/\.(Symbol\.(?:[a-z]+[A-Z]?)+)/g, '[$1]');
68 /*----------------------------------------------------------------------------*/
71 * Creates the documentation markdown formatted for 'github' or 'site'.
74 * @param {string} type The format type.
76 function build(type) {
77 const options = _.defaults({}, config.base, config[type]);
78 const markdown = docdown(options);
80 fs.writeFile(readmePath, postprocess(markdown), util.pitch);
83 build(_.last(process.argv));