Matteo Scandolo | 280dcd3 | 2016-05-16 09:59:38 -0700 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | var _ = require('lodash'), |
| 4 | docdown = require('docdown'), |
| 5 | fs = require('fs-extra'), |
| 6 | path = require('path'); |
| 7 | |
| 8 | var basePath = path.join(__dirname, '..', '..'), |
| 9 | docPath = path.join(basePath, 'doc'), |
| 10 | readmePath = path.join(docPath, 'README.md'); |
| 11 | |
| 12 | var pkg = require('../../package.json'), |
| 13 | version = pkg.version; |
| 14 | |
| 15 | var config = { |
| 16 | 'base': { |
| 17 | 'entryLinks': [ |
| 18 | '<% if (name == "templateSettings" || !/^(?:methods|properties|seq)$/i.test(category)) {' + |
| 19 | 'print("[Ⓝ](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 | |
| 35 | function 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 | |
| 47 | function onComplete(error) { |
| 48 | if (error) { |
| 49 | throw error; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | function build(type) { |
| 54 | var options = _.defaults({}, config.base, config[type]), |
| 55 | markdown = docdown(options); |
| 56 | |
| 57 | fs.writeFile(readmePath, postprocess(markdown), onComplete); |
| 58 | } |
| 59 | |
| 60 | build(_.last(process.argv)); |