Skip to content

Commit

Permalink
fix indentation and remove logging to file
Browse files Browse the repository at this point in the history
  • Loading branch information
piuccio committed Jun 21, 2017
1 parent f43fcdd commit 5bad6c5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[*]
charset=utf-8
end_of_line=lf
trim_trailing_whitespace=true
insert_final_newline=true
indent_style=tab
indent_size=2
spaces_around_brackets=both

[{.eslintrc,.babelrc,.stylelintrc,.firebaserc,*.bowerrc,*.jsb3,*.jsb2,*.json,*.config,*.yml,*.yaml}]
indent_style=space
indent_size=2
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module.exports = function(data, callback) {
* commits: [], // the array of commits as described above
* range: '<since>..<until>',
* dateFnsFormat: function () {},
* debug: function() {}, // utility function to log debug messages
* }
*
* Do all the processing you need and when ready call the callback passing the new data structure
Expand Down Expand Up @@ -140,4 +141,4 @@ The DEBUG environment variable can also be useful for fault diagnosis:
SET DEBUG=release-notes:cli,release-notes:externalscript
git-release-notes ...

Note the filtering options available: `release-notes:cli` and `release-notes:externalscript`
Note the filtering options available: `release-notes:cli`, `release-notes:externalscript`, `release-notes:data`
30 changes: 14 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var fs = require("fs");
var ejs = require("ejs");
var path = require("path");
var debug = require("debug")("release-notes:cli");
var debugData = require("debug")("release-notes:data");
var dateFnsFormat = require('date-fns/format')

var template = argv._[1];
Expand Down Expand Up @@ -123,38 +124,35 @@ function postProcess(templateContent, commits) {
debug("Got %d commits", commits.length);
if (commits.length) {
if (argv.s) {
externalScriptPath = path.join(process.cwd(), argv.s);
var externalScriptPath = path.join(process.cwd(), argv.s);
try {
var externalScript = require(externalScriptPath);
} catch (ex) {
debug("Exception while reading external script '%s'", ex.message);
debug("Exception while reading external script '%s': '%s'", externalScriptPath, ex.message);
console.error('Unable to read external script');
process.exit(7);
}
debug("Trying to run the external script");
var jsonData;
var inputData;
var outputData;
try {
jsonData = {
inputData = {
commits: commits,
range: argv._[0],
dateFnsFormat: dateFnsFormat,
debug: require("debug")("release-notes:externalscript")
debug: require("debug")("release-notes:externalscript")
};
externalScript(jsonData, function (modifiedData) {
jsonData = modifiedData;
render(templateContent, jsonData);
externalScript(inputData, function (data) {
outputData = data;
render(templateContent, data);
});
debug("Waiting for external script to call the callback");
} catch (ex) {
debug("Exception while running external script '%s'", ex.message);
var errorFile = externalScriptPath + ".json";
console.error('Error while processing external script. Writing json data to "' + errorFile + '".', ex);
fs.writeFile(errorFile, JSON.stringify(jsonData), function(err) {
if(err) {
console.log(err);
}
process.exit(8);
});
debugData("Input data passed to the external script `%s`", JSON.stringify(inputData, null, ' '));
debugData("Output data received from the external script `%s`", outputData ? JSON.stringify(outputData, null, ' ') : '');
console.error('Error while processing external script', ex);
process.exit(8);
}
} else {
debug("Rendering template without post processing");
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"posttest": "npm run lint",
"test-html": "node index.js -- 32a369f..0419636 ./templates/html.ejs > ./samples/output-html.html",
"test-html-bootstrap": "cross-env DEBUG=* node index.js -- 32a369f..0419636 ./templates/html-bootstrap.ejs > ./samples/output-html-bootstrap.html",
"test-markdown": "node index.js -- 32a369f..0419636 ./templates/markdown.ejs > ./samples/output-markdown.md"
"test-markdown": "node index.js -- 32a369f..0419636 ./templates/markdown.ejs > ./samples/output-markdown.md",
"test-script": "node index.js -s ./samples/post-processing.js 32a369f..0419636 ./templates/markdown.ejs"
},
"version": "1.1.0",
"dependencies": {
Expand Down

0 comments on commit 5bad6c5

Please sign in to comment.