Skip to content

Commit

Permalink
fix adr#28
Browse files Browse the repository at this point in the history
  • Loading branch information
Fetz committed Nov 15, 2019
1 parent bac32e6 commit 3b908f5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
5 changes: 3 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ var adrLogDir = args.d || defaultAdrLogDir;

var defaultAdrLogFile = 'index.md';
var adrLogFile = args._[0] || adrLogDir + '/' + defaultAdrLogFile;
var adrLogFileName = require('path').parse(adrLogFile).base;
var adrLogFileName = path.parse(adrLogFile).base;
var tocDir = path.dirname(adrLogFile);

console.log("adr log file:", adrLogFile);
console.log("adr log dir:", adrLogDir);
Expand All @@ -78,7 +79,7 @@ if (fs.existsSync(adrLogFile)) {
} else {
existingLogString = '<!-- adrlog -->' + os.EOL + os.EOL + '<!-- adrlogstop -->' + os.EOL;
}
var newLogString = toc.insertAdrToc(existingLogString, headings, adrLogDir);
var newLogString = toc.insertAdrToc(existingLogString, headings, {dir: adrLogDir, tocDir});

if (args.i) {
fs.writeFileSync(adrLogFile, newLogString);
Expand Down
17 changes: 17 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Architectural Decision Log

This log lists the architectural decisions for adr-log.

<!-- adrlog -- Regenerate the content by using "adr-log -i". You can install it via "npm install -g adr-log" -->

- [ADR-0000](0000-use-markdown-architectural-decision-records.md) - Use Markdown Architectural Decision Records
- [ADR-0001](0001-extend-markdown-toc.md) - Extend markdown-toc
- [ADR-0002](0002-use-console-stamp-as-logging-framework.md) - Use console-stamp as logging framework
- [ADR-0003](0003-use-release-it-and-github-release-from-changelog-as-release-tooling.md) - Use release-it and github-release-from-changelog for releasing
- [ADR-0004](0004-filename-as-direct-parameter.md) - Filename as direct parameter

<!-- adrlogstop -->

For new ADRs, please use [template.md](template.md) as basis.
More information on MADR is available at <https://adr.github.io/madr/>.
General information about architectural decision records is available at <https://adr.github.io/>.
21 changes: 15 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* Module dependencies
*/

var utils = require('./lib/utils');
const utils = require('./lib/utils');
const fs = require('fs');
const path = require('path');
const slash = require('slash');

/**
* expose `toc`
Expand Down Expand Up @@ -43,32 +45,39 @@ function generate(options) {
const res = {
content: ''
};

tokens = tokens.filter(t => !!t.content);

for (const token of tokens) {
let file;
if (!options.dir) {
return {content: ''};
}

const numb = token.content.match(/^\d+/m);
if (numb === null || numb === undefined) {
continue;
}
var content = fs.readFileSync(`${options.dir}/${token.content}`).toString();

let content = fs.readFileSync(`${options.dir}/${token.content}`).toString();

let tokenPath = slash(
path.relative(options.tocDir, `${options.dir}${token.content}`)
);

// does the file have front-matter?
if (/^---/.test(content)) {
// extract it temporarily so the syntax
// doesn't get mistaken for a heading
var obj = utils.matter(content);
let obj = utils.matter(content);
content = obj.content;
}

const newline = utils.determineNewline(content);
var title = content.split(newline)[0].substr(2);
let title = content.split(newline)[0].substr(2);
console.log("title before decimal removal: ", title);
title = title.replace(/^\d+\. /, '');
console.log("title after decimal removal: ", title);
res.content += `- [ADR-${numb[0].trim()}](${token.content}) - ${title + options.newline}`
res.content += `- [ADR-${numb[0].trim()}](${tokenPath}) - ${title + options.newline}`
}
res.content = res.content.trim();
return res;
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"lazy-cache": "^2.0.2",
"minimist": "^1.2.0",
"path": "^0.12.7",
"remarkable": "^1.7.1"
"remarkable": "^1.7.1",
"slash": "^3.0.0"
},
"devDependencies": {
"gulp-format-md": "^0.1.11"
Expand Down

0 comments on commit 3b908f5

Please sign in to comment.