2016-05-16 13:33:49 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
const _ = require('lodash');
|
|
|
|
const docdown = require('docdown');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const path = require('path');
|
2016-05-16 13:33:49 +02:00
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
const util = require('../common/util');
|
2016-05-16 13:33:49 +02:00
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
const basePath = path.join(__dirname, '..', '..');
|
|
|
|
const docPath = path.join(basePath, 'doc');
|
|
|
|
const readmePath = path.join(docPath, 'README.md');
|
2016-05-16 13:33:49 +02:00
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
const pkg = require('../../package.json');
|
|
|
|
const version = pkg.version;
|
|
|
|
|
|
|
|
const config = {
|
2016-05-16 13:33:49 +02:00
|
|
|
'base': {
|
|
|
|
'path': path.join(basePath, 'lodash.js'),
|
2017-05-13 13:25:33 +02:00
|
|
|
'title': `<a href="https://lodash.com/">lodash</a> <span>v${ version }</span>`,
|
2016-05-16 13:33:49 +02:00
|
|
|
'toc': 'categories',
|
2017-05-13 13:25:33 +02:00
|
|
|
'url': `https://github.com/lodash/lodash/blob/${ version }/lodash.js`
|
2016-05-16 13:33:49 +02:00
|
|
|
},
|
|
|
|
'github': {
|
2017-05-13 13:25:33 +02:00
|
|
|
'style': 'github',
|
|
|
|
'sublinks': [npmLink('Ⓝ', 'See the npm package')]
|
2016-05-16 13:33:49 +02:00
|
|
|
},
|
|
|
|
'site': {
|
2017-05-13 13:25:33 +02:00
|
|
|
'entryLink': '<a href="${entryHref}" class="fa fa-link"></a>',
|
|
|
|
'sourceLink': '[source](${sourceHref})',
|
|
|
|
'tocHref': '',
|
|
|
|
'tocLink': '',
|
|
|
|
'sublinks': [npmLink('npm package')]
|
2016-05-16 13:33:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
/**
|
|
|
|
* Composes a npm link from `text` and optional `title`.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} text The link text.
|
|
|
|
* @param {string} [title] The link title.
|
|
|
|
* @returns {string} Returns the composed npm link.
|
|
|
|
*/
|
|
|
|
function npmLink(text, title) {
|
|
|
|
return (
|
|
|
|
'<% if (name == "templateSettings" || !/^(?:methods|properties|seq)$/i.test(category)) {' +
|
|
|
|
'print(' +
|
|
|
|
'"[' + text + '](https://www.npmjs.com/package/lodash." + name.toLowerCase() + ' +
|
|
|
|
'"' + (title == null ? '' : ' \\"' + title + '\\"') + ')"' +
|
|
|
|
');' +
|
|
|
|
'} %>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-process `markdown` to make adjustments.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} markdown The markdown to process.
|
|
|
|
* @returns {string} Returns the processed markdown.
|
|
|
|
*/
|
|
|
|
function postprocess(markdown) {
|
2016-06-11 17:57:30 +02:00
|
|
|
// Wrap symbol property identifiers in brackets.
|
2017-05-13 13:25:33 +02:00
|
|
|
return markdown.replace(/\.(Symbol\.(?:[a-z]+[A-Z]?)+)/g, '[$1]');
|
2016-05-16 13:33:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
/**
|
|
|
|
* Creates the documentation markdown formatted for 'github' or 'site'.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} type The format type.
|
|
|
|
*/
|
2016-05-16 13:33:49 +02:00
|
|
|
function build(type) {
|
2017-05-13 13:25:33 +02:00
|
|
|
const options = _.defaults({}, config.base, config[type]);
|
|
|
|
const markdown = docdown(options);
|
2016-05-16 13:33:49 +02:00
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
fs.writeFile(readmePath, postprocess(markdown), util.pitch);
|
2016-05-16 13:33:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
build(_.last(process.argv));
|