Skip to content

Commit

Permalink
Removed extra logs from stdOut
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLitt committed Jun 26, 2016
1 parent f76b8a6 commit c2b8a47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
16 changes: 7 additions & 9 deletions doctoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ function cleanPath(path) {
}

function transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPrefix, stdOut) {
console.log('\n==================\n');
console.error('\n==================\n');

var transformed = files
.map(function (x) {
var content = fs.readFileSync(x.path, 'utf8')
, result = transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix);
, result = transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix, stdOut);
result.path = x.path;
return result;
});
Expand All @@ -37,13 +37,11 @@ function transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPref
}

unchanged.forEach(function (x) {
console.log('"%s" is up to date.', x.path);
console.error('"%s" is up to date.', x.path);
});

changed.forEach(function (x) {
if (stdOut) {
console.log('==================\n\n"%s" was not updated.', x.path)
} else {
if (!stdOut) {
console.log('"%s" will be updated.', x.path);
fs.writeFileSync(x.path, x.data, 'utf8');
}
Expand Down Expand Up @@ -107,14 +105,14 @@ for (var i = 0; i < argv._.length; i++) {
, stat = fs.statSync(target)

if (stat.isDirectory()) {
console.log ('\nDocToccing "%s" and its sub directories for %s.', target, mode);
console.error('\nDocToccing "%s" and its sub directories for %s.', target, mode);
files = file.findMarkdownFiles(target);
} else {
console.log ('\nDocToccing single file "%s" for %s.', target, mode);
console.error('\nDocToccing single file "%s" for %s.', target, mode);
files = [{ path: target }];
}

transformAndSave(files, mode, maxHeaderLevel, title, notitle, entryPrefix, stdOut);

console.log('\nEverything is OK.');
console.error('\nEverything is OK.');
}
19 changes: 9 additions & 10 deletions lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ function getLinesToToc (lines, currentToc, info) {
}

// Use document context as well as command line args to infer the title
function determineTitle(title, notitle, lines, info) {
function determineTitle(title, notitle, lines, info, stdOut) {
var defaultTitle = '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*';

if (notitle) return '';
if (notitle || stdOut) return '';
if (title) return title;
return info.hasStart ? lines[info.startIdx + 2] : defaultTitle;
}

exports = module.exports = function transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix) {
exports = module.exports = function transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix, stdOut) {
mode = mode || 'github.com';
entryPrefix = entryPrefix || '-';

Expand All @@ -116,7 +116,7 @@ exports = module.exports = function transform(content, mode, maxHeaderLevel, tit
var lines = content.split('\n')
, info = updateSection.parse(lines, matchesStart, matchesEnd)

var inferredTitle = determineTitle(title, notitle, lines, info);
var inferredTitle = determineTitle(title, notitle, lines, info, stdOut);

var currentToc = info.hasStart && lines.slice(info.startIdx, info.endIdx + 1).join('\n')
, linesToToc = getLinesToToc(lines, currentToc, info);
Expand All @@ -137,18 +137,17 @@ exports = module.exports = function transform(content, mode, maxHeaderLevel, tit
// 4 spaces required for proper indention on Bitbucket
var indentation = (mode === 'bitbucket.org' || mode === 'gitlab.com') ? ' ' : ' ';

var toc =
inferredTitle
+ '\n\n'
+ linkedHeaders
.map(function (x) {
var toc = linkedHeaders.map(function (x) {
var indent = _(_.range(x.rank - lowestRank))
.reduce(function (acc, x) { return acc + indentation; }, '');

return indent + entryPrefix + ' ' + x.anchor;
})
.join('\n')
+ '\n';

if (!stdOut) {
toc = inferredTitle + '\n\n' + toc + '\n';
}

var wrappedToc = start + '\n' + toc + '\n' + end;

Expand Down

0 comments on commit c2b8a47

Please sign in to comment.