Update of multiple frontend libs.

This commit is contained in:
baldo 2017-05-13 13:25:33 +02:00
commit a9c6ddc03b
276 changed files with 41257 additions and 19300 deletions

View file

@ -1,30 +1,31 @@
'use strict';
var async = require('async'),
path = require('path');
const async = require('async');
const path = require('path');
var file = require('../common/file');
const file = require('../common/file');
const util = require('../common/util');
var basePath = path.join(__dirname, '..', '..'),
distPath = path.join(basePath, 'dist'),
filename = 'lodash.js';
const basePath = path.join(__dirname, '..', '..');
const distPath = path.join(basePath, 'dist');
const filename = 'lodash.js';
var baseLodash = path.join(basePath, filename),
distLodash = path.join(distPath, filename);
const baseLodash = path.join(basePath, filename);
const distLodash = path.join(distPath, filename);
/*----------------------------------------------------------------------------*/
function onComplete(error) {
if (error) {
throw error;
}
}
/**
* Creates browser builds of Lodash at the `target` path.
*
* @private
* @param {string} target The output directory path.
*/
function build() {
async.series([
file.copy(baseLodash, distLodash),
file.min(distLodash)
], onComplete);
], util.pitch);
}
build();

View file

@ -1,55 +1,83 @@
'use strict';
var _ = require('lodash'),
docdown = require('docdown'),
fs = require('fs-extra'),
path = require('path');
const _ = require('lodash');
const docdown = require('docdown');
const fs = require('fs-extra');
const path = require('path');
var basePath = path.join(__dirname, '..', '..'),
docPath = path.join(basePath, 'doc'),
readmePath = path.join(docPath, 'README.md');
const util = require('../common/util');
var pkg = require('../../package.json'),
version = pkg.version;
const basePath = path.join(__dirname, '..', '..');
const docPath = path.join(basePath, 'doc');
const readmePath = path.join(docPath, 'README.md');
var config = {
const pkg = require('../../package.json');
const version = pkg.version;
const 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>',
'title': `<a href="https://lodash.com/">lodash</a> <span>v${ version }</span>`,
'toc': 'categories',
'url': 'https://github.com/lodash/lodash/blob/' + version + '/lodash.js'
'url': `https://github.com/lodash/lodash/blob/${ version }/lodash.js`
},
'github': {
'hash': 'github'
'style': 'github',
'sublinks': [npmLink('&#x24C3;', 'See the npm package')]
},
'site': {
'tocLink': '#docs'
'entryLink': '<a href="${entryHref}" class="fa fa-link"></a>',
'sourceLink': '[source](${sourceHref})',
'tocHref': '',
'tocLink': '',
'sublinks': [npmLink('npm package')]
}
};
function postprocess(string) {
/**
* 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) {
// Wrap symbol property identifiers in brackets.
return string.replace(/\.(Symbol\.(?:[a-z]+[A-Z]?)+)/g, '[$1]');
return markdown.replace(/\.(Symbol\.(?:[a-z]+[A-Z]?)+)/g, '[$1]');
}
/*----------------------------------------------------------------------------*/
function onComplete(error) {
if (error) {
throw error;
}
}
/**
* Creates the documentation markdown formatted for 'github' or 'site'.
*
* @private
* @param {string} type The format type.
*/
function build(type) {
var options = _.defaults({}, config.base, config[type]),
markdown = docdown(options);
const options = _.defaults({}, config.base, config[type]);
const markdown = docdown(options);
fs.writeFile(readmePath, postprocess(markdown), onComplete);
fs.writeFile(readmePath, postprocess(markdown), util.pitch);
}
build(_.last(process.argv));

View file

@ -1,15 +1,16 @@
'use strict';
var _ = require('lodash'),
async = require('async'),
path = require('path');
const _ = require('lodash');
const async = require('async');
const path = require('path');
var file = require('../common/file');
const file = require('../common/file');
const util = require('../common/util');
var basePath = path.join(__dirname, '..', '..'),
distPath = path.join(basePath, 'dist');
const basePath = path.join(__dirname, '..', '..');
const distPath = path.join(basePath, 'dist');
var filePairs = [
const filePairs = [
[path.join(distPath, 'lodash.core.js'), 'core.js'],
[path.join(distPath, 'lodash.core.min.js'), 'core.min.js'],
[path.join(distPath, 'lodash.min.js'), 'lodash.min.js']
@ -17,18 +18,17 @@ var filePairs = [
/*----------------------------------------------------------------------------*/
function onComplete(error) {
if (error) {
throw error;
}
}
/**
* Creates supplementary Lodash modules at the `target` path.
*
* @private
* @param {string} target The output directory path.
*/
function build(target) {
var actions = _.map(filePairs, function(pair) {
return file.copy(pair[0], path.join(target, pair[1]));
});
const actions = _.map(filePairs, pair =>
file.copy(pair[0], path.join(target, pair[1])));
async.series(actions, onComplete);
async.series(actions, util.pitch);
}
build(_.last(process.argv));

View file

@ -0,0 +1,224 @@
'use strict';
const _ = require('lodash');
const cheerio = require('cheerio');
const fs = require('fs');
const marky = require('marky-markdown');
const path = require('path');
const util = require('../common/util');
const basePath = path.join(__dirname, '..', '..');
const docPath = path.join(basePath, 'doc');
const readmePath = path.join(docPath, 'README.md');
const highlights = {
'html': [
'string'
],
'js': [
'comment',
'console',
'delimiter',
'method',
'modifier',
'name',
'numeric',
'string',
'support',
'type'
]
};
const exts = _.keys(highlights);
/**
* Converts Lodash method references into documentation links.
*
* @private
* @param {Object} $ The Cheerio object.
*/
function autoLink($) {
$('.doc-container code').each(function() {
const $code = $(this);
const html = $code.html();
if (/^_\.\w+$/.test(html)) {
const id = html.split('.')[1];
$code.replaceWith(`<a href="#${ id }"><code>_.${ id }</code></a>`);
}
});
}
/**
* Removes horizontal rules from the document.
*
* @private
* @param {Object} $ The Cheerio object.
*/
function removeHorizontalRules($) {
$('hr').remove();
}
/**
* Removes marky-markdown specific ids and class names.
*
* @private
* @param {Object} $ The Cheerio object.
*/
function removeMarkyAttributes($) {
$('[id^="user-content-"]')
.attr('class', null)
.attr('id', null);
$(':header:not(h3) > a').each(function() {
const $a = $(this);
$a.replaceWith($a.html());
});
}
/**
* Renames "_" id and anchor references to "lodash".
*
* @private
* @param {Object} $ The Cheerio object.
*/
function renameLodashId($) {
$('#_').attr('id', 'lodash');
$('[href="#_"]').attr('href', '#lodash');
}
/**
* Repairs broken marky-markdown headers.
* See https://github.com/npm/marky-markdown/issues/217 for more details.
*
* @private
* @param {Object} $ The Cheerio object.
*/
function repairMarkyHeaders($) {
$('p:empty + h3').prev().remove();
$('h3 ~ p:empty').each(function() {
const $p = $(this);
let node = this.prev;
while ((node = node.prev) && node.name != 'h3' && node.name != 'p') {
$p.prepend(node.next);
}
});
$('h3 code em').parent().each(function() {
const $code = $(this);
$code.html($code.html().replace(/<\/?em>/g, '_'));
});
}
/**
* Cleans up highlights blocks by removing extraneous class names and elements.
*
* @private
* @param {Object} $ The Cheerio object.
*/
function tidyHighlights($) {
$('.highlight').each(function() {
let $spans;
const $parent = $(this);
const classes = $parent.find('.source,.text').first().attr('class').split(' ');
const ext = _(classes).intersection(exts).last();
$parent.addClass(ext);
// Remove line indicators for single line snippets.
$parent.children('pre').each(function() {
const $divs = $(this).children('div');
if ($divs.length == 1) {
$divs.replaceWith($divs.html());
}
});
// Remove extraneous class names.
$parent.find('[class]').each(function() {
const $element = $(this);
const classes = $element.attr('class').split(' ');
const attr = _(classes).intersection(highlights[ext]).join(' ');
$element.attr('class', attr || null);
});
// Collapse nested comment highlights.
$parent.find(`[class~="comment"]`).each(function() {
const $element = $(this);
$element.text($element.text().trim());
});
// Collapse nested string highlights.
$parent.find(`[class~="string"]`).each(function() {
const $element = $(this);
$element.text($element.text());
});
// Collapse nested spans.
while (($spans = $parent.find('span:not([class])')).length) {
$spans.each(function() {
let $span = $(this);
while ($span[0] && $span[0].name == 'span' && !$span.attr('class')) {
const $parent = $span.parent();
$span.replaceWith($span.html());
$span = $parent;
}
});
}
});
}
/*----------------------------------------------------------------------------*/
/**
* Creates the documentation HTML.
*
* @private
*/
function build() {
const markdown = fs
// Load markdown.
.readFileSync(readmePath, 'utf8')
// Uncomment docdown HTML hints.
.replace(/(<)!--\s*|\s*--(>)/g, '$1$2')
// Convert source and npm package links to anchors.
.replace(/\[source\]\(([^)]+)\) \[npm package\]\(([^)]+)\)/g, (match, href1, href2) =>
`<p><a href="${ href1 }">source</a> <a href="${ href2 }">npm package</a></p>`
);
const $ = cheerio.load(marky(markdown, {
'enableHeadingLinkIcons': false,
'sanitize': false
}));
const $header = $('h1').first().remove();
const version = $header.find('span').first().text().trim().slice(1);
// Auto-link Lodash method references.
autoLink($);
// Rename "_" id references to "lodash".
renameLodashId($);
// Remove docdown horizontal rules.
removeHorizontalRules($);
// Remove marky-markdown attribute additions.
removeMarkyAttributes($);
// Repair marky-markdown wrapping around headers.
repairMarkyHeaders($);
// Cleanup highlights.
tidyHighlights($);
const html = [
// Append YAML front matter.
'---',
'id: docs',
'layout: docs',
'title: Lodash Documentation',
'version: ' + (version || null),
'---',
'',
// Wrap in raw tags to avoid Liquid template tag processing.
'{% raw %}',
$.html().trim(),
'{% endraw %}',
''
].join('\n');
fs.writeFile(path.join(docPath, version + '.html'), html, util.pitch);
}
build();