changelog2html
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -5,43 +5,60 @@ 'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
module.exports = renderChangelogForFolder; | ||
module.exports = render; | ||
// Test | ||
let promise = renderChangelogForFolder('.','template.html', 'changes'); | ||
promise.then(function (output) { | ||
console.log("OUTPUT: ", output); | ||
}); | ||
const fileRegex = /([^\.]*)\.([^\.]*)\.(.*)/; | ||
function checkFolders(templateFile, pathToChangesFolder) { | ||
var filepath = path.resolve(process.cwd(),pathToChangesFolder); | ||
//console.log("Rendering changelog for repo in {" + repoPath + "} using template {" + templateFile + "}"); | ||
//console.log("Checking change files in {" + pathInRepo + "}"); | ||
return checkPath(templateFile, false, "Could not find template file {" + templateFile + "}") | ||
.then(e => checkPath(pathToChangesFolder, true, "Could not find changes folder {" + pathToChangesFolder + "}")) | ||
.then(e => nodegit.Repository.discover(pathToChangesFolder, 100, "")) | ||
.then(buf => { | ||
let workspaceFolderPath = path.resolve(buf.toString(), ".."); | ||
let pathToChangesWithinRepo = path.relative(workspaceFolderPath, filepath); | ||
return { | ||
'repoPath': buf.toString(), | ||
'workspacePath': workspaceFolderPath, | ||
'changesPath': pathToChangesWithinRepo | ||
} | ||
//.then(e => checkPath(repoPath, true, "Could not find repository folder {" + repoPath +"}")) | ||
}); | ||
} | ||
/** | ||
* Render the changelog. | ||
* @param {String} templateFile - Swig template file which should be used to render the changelog. | ||
* @param {String} pathInRepo - Folder which contains the git changelog files. | ||
* @param {String} pathToChangesFolder - Folder which contains the git changelog files. | ||
* @returns a promise | ||
*/ | ||
function renderChangelogForFolder(repoPath, templateFile, pathInRepo) { | ||
const path = require('path'); | ||
function render(templateFile, pathToChangesFolder) { | ||
const markdown = require('markdown').markdown; | ||
const swig = require('swig'); | ||
let repo, tags, headHistory; | ||
let repo, tags, headHistory, pathInfo; | ||
// Open repository and list files in folder | ||
return Promise.all([ | ||
nodegit.Repository.open(repoPath) | ||
.then(repository => | ||
Promise.all([ | ||
// We need a commit list of HEAD ... | ||
repository.getHeadCommit() | ||
.then(headCommit => getHistoryOfCommit(headCommit)) | ||
.then(history => headHistory = history), | ||
// ... and all tags in the repo | ||
getTagCommitsOfRepo(repository) | ||
.then(tagList => tags = tagList) | ||
]) | ||
.then(() => repo = repository) | ||
), | ||
findFilesInFolder(path.join(repoPath, pathInRepo)) | ||
]) | ||
return checkFolders(templateFile, pathToChangesFolder) | ||
.then(info => { | ||
pathInfo = info; | ||
return Promise.all([ | ||
nodegit.Repository.open(pathInfo.repoPath) | ||
.then(repository => | ||
Promise.all([ | ||
// We need a commit list of HEAD ... | ||
repository.getHeadCommit() | ||
.then(headCommit => getHistoryOfCommit(headCommit)) | ||
.then(history => headHistory = history), | ||
// ... and all tags in the repo | ||
getTagCommitsOfRepo(repository) | ||
.then(tagList => tags = tagList) | ||
]) | ||
.then(() => repo = repository) | ||
), | ||
findFilesInFolder(pathToChangesFolder) | ||
]) | ||
}) | ||
// Result is [repo, file list] | ||
@@ -52,3 +69,3 @@ .then(result => result[1]) | ||
file => { | ||
return findFirstCommitForFile(headHistory, path.join(pathInRepo, file)) | ||
return findFirstCommitForFile(headHistory, path.join(pathInfo.changesPath, file)) | ||
.then(commit => { | ||
@@ -68,3 +85,3 @@ return {tag: findFirstTagWithCommit(tags, commit), commit: commit} | ||
fileList.forEach(file => { | ||
let filePath = path.join(pathInRepo, file.fileName); | ||
let filePath = path.join(pathToChangesFolder, file.fileName); | ||
let content = fs.readFileSync(filePath, 'utf8'); | ||
@@ -107,2 +124,3 @@ let rendered = markdown.toHTML(content); | ||
function findAllCommitsForFile(repoHeadHistory, filepath) { | ||
//console.log(filepath); | ||
return Promise.all( | ||
@@ -159,6 +177,23 @@ repoHeadHistory.map( | ||
} | ||
return null; | ||
} | ||
function checkPath(path, expectFolder, failureMessage) { | ||
return new Promise((success, fail) => { | ||
fs.stat(path, (err, stats) => { | ||
if (err) { | ||
return fail(failureMessage, err); | ||
} else { | ||
if (expectFolder && !stats.isDirectory()) { | ||
return fail(failureMessage); | ||
} | ||
if (!expectFolder && !stats.isFile()) { | ||
return fail(failureMessage); | ||
} | ||
return success(null); | ||
} | ||
}); | ||
}); | ||
} | ||
function findFilesInFolder(folder) { | ||
@@ -165,0 +200,0 @@ const fs = require('fs'); |
{ | ||
"name": "changelog2html", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A changelog generator which uses git tags to identify versions and dates for found changelog entry files.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -51,4 +51,6 @@ ## changelog2html | ||
```js | ||
changelog = require('changelog-generator'); | ||
changelog("template.html", "src/main/changelog").then(function(result) { | ||
changelog = require('changelog2html'); | ||
let templateFile = "template.html"; | ||
let pathToChangesFolder = "changes"; | ||
changelog(templateFile, pathToChangesFolder).then(function(result) { | ||
console.log(result); | ||
@@ -55,0 +57,0 @@ }); |
10
test.js
changelog = require("./changelog.js") | ||
changelog("template.html", "changes").then(function(result) { | ||
console.log(result); | ||
}); | ||
/* | ||
changelog("template.html", "src/main/changelog").then(function(result) { | ||
console.log(result); | ||
changelog(".", "template.html", "../changelog2html/changes").then(function(result) { | ||
console.log(result); | ||
}); | ||
*/ | ||
*/ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12954
201
80
0