markdown-documentation-generator
Advanced tools
Comparing version 3.1.0 to 3.2.0
65
index.js
@@ -159,3 +159,3 @@ #!/usr/bin/env node | ||
const root = path.resolve(customOptions.rootFolder); | ||
return path.relative(root, path.resolve(_sg.moduleDir, folder)); | ||
return path.relative(root, path.resolve(__dirname, folder)); | ||
} | ||
@@ -205,4 +205,7 @@ | ||
logFiles(_sg.brand('Configuration')); | ||
//Read passed object or configFile global. | ||
customOptions = customOptions || fs.readJSONSync(_sg.configFile, 'utf8'); | ||
_sg.configFile = path.isAbsolute(_sg.configFile) | ||
? _sg.configFile | ||
: path.join(process.cwd(), _sg.configFile); | ||
customOptions = customOptions | ||
|| require(_sg.configFile); | ||
} | ||
@@ -653,35 +656,30 @@ catch(err) { | ||
let output = { | ||
'json': json, | ||
'json': JSON.stringify(json, null, ' '), | ||
'html': template(json, options) | ||
}; | ||
let filePath; | ||
let filePromises = []; | ||
if (options.htmlOutput && _.isString(options.htmlOutput)) { | ||
filePath = path.resolve(_sg.root, options.htmlOutput); | ||
fs.outputFile(filePath, output.html, function(err) { | ||
if (err) { | ||
console.error(_sg.logPre + _sg.error('Error saving html file')); | ||
console.error(err); | ||
} | ||
else { | ||
logFiles(options.htmlOutput, 'create'); | ||
} | ||
}); | ||
} | ||
Object.keys(output).forEach((fileType) => { | ||
let filePath = options[fileType+'Output']; | ||
if (options.jsonOutput && _.isString(options.jsonOutput)) { | ||
filePath = path.resolve(_sg.root, options.jsonOutput); | ||
fs.outputFile(options.jsonOutput, JSON.stringify(json, null, ' '), function(err) { | ||
if (err){ | ||
console.error(_sg.logPre + _sg.error('Error saving json file')); | ||
if (filePath && _.isString(filePath)) { | ||
let fullFilePath = path.resolve(_sg.root, filePath); | ||
filePromises.push( | ||
fs.outputFile(fullFilePath, output[fileType]) | ||
.then(() => { | ||
logFiles(filePath, 'create'); | ||
}) | ||
.catch((err) => { | ||
console.error( | ||
_sg.logPre + | ||
_sg.error(` Error saving ${fileType} file`) | ||
); | ||
console.error(err); | ||
} | ||
else { | ||
logFiles(options.jsonOutput, 'create'); | ||
} | ||
}); | ||
}) | ||
) | ||
} | ||
}) | ||
return output; | ||
return filePromises; | ||
} | ||
@@ -747,3 +745,3 @@ | ||
function init(args, customOptions) { | ||
function init(args, customOptions, callback) { | ||
@@ -777,3 +775,5 @@ //Set up stuff based on arguments | ||
const json = convertHTMLtoJSON('<div class="sg-article-' + _sg.uniqueIdentifier + '">\n' + fileContents + '</div>'); | ||
return saveFiles(json, options); | ||
// Resolve files | ||
Promise.all(saveFiles(json, options)) | ||
.then(() => callback(json)); | ||
}); | ||
@@ -797,4 +797,5 @@ } | ||
try { | ||
data = init(argv, customOptions); | ||
return resolve(data); | ||
init(argv, customOptions, (data) => { | ||
return resolve(data); | ||
}); | ||
} | ||
@@ -801,0 +802,0 @@ catch(err){ |
{ | ||
"name": "markdown-documentation-generator", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Searches files for markdown and generates a static style/documentation guide. A fork of markdown-styleguide-generator.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
2566
428374
6