Add npm scripts to build docs.

This commit is contained in:
Jeroen Engels
2016-01-26 22:48:23 +01:00
committed by John-David Dalton
parent c86754afde
commit b97a05b7f2
2 changed files with 56 additions and 0 deletions

54
lib/doc/build.js Normal file
View File

@@ -0,0 +1,54 @@
'use strict';
var _ = require('lodash'),
docdown = require('docdown'),
fs = require('fs-extra'),
path = require('path');
var basePath = path.join(__dirname, '..', '..'),
docPath = path.join(basePath, 'doc'),
readmePath = path.join(docPath, 'README.md');
var pkg = require('../../package.json'),
version = pkg.version;
var config = {
'base': {
'entryLinks': [
'<% if (name == "templateSettings" || !/^(?:methods|properties|seq)$/i.test(category)) {' +
'print("[&#x24C3;](https://www.npmjs.com/package/lodash." + name.toLowerCase() + " \\"See the npm package\\")")' +
'} %>'
],
'path': path.join(basePath, 'lodash.js'),
'title': '<a href="https://lodash.com/">lodash</a> <span>v' + version + '</span>',
'toc': 'categories',
'url': 'https://github.com/lodash/lodash/blob/' + version + '/lodash.js'
},
'github': {
'hash': 'github'
},
'site': {
'tocLink': '#docs'
}
};
function postprocess(string) {
return string.replace(/\.(Symbol\.iterator)\b/g, '[$1]');
}
/*----------------------------------------------------------------------------*/
function onComplete(error) {
if (error) {
throw error;
}
}
function build(type) {
var options = _.defaults({}, config.base, config[type]),
markdown = docdown(options);
fs.writeFile(readmePath, postprocess(markdown), onComplete);
}
build(_.last(process.argv));

View File

@@ -32,6 +32,8 @@
"build:fp": "node lib/fp/build-dist.js",
"build:fp-modules": "node lib/fp/build-modules.js",
"build:main": "node lib/main/build-dist.js",
"doc": "node lib/doc/build github",
"doc:site": "node lib/doc/build site",
"style": "npm run style:main & npm run style:fp & npm run style:perf & npm run style:test",
"style:fp": "jscs fp/*.js lib/**/*.js",
"style:main": "jscs lodash.js",