markdown-documentation-generator
Advanced tools
Comparing version 2.3.2 to 2.4.0
387
index.js
#!/usr/bin/env node | ||
/* jshint node: true */ | ||
@@ -7,3 +6,2 @@ /* jshint esnext: true*/ | ||
var masterData = require('./lib/master-data'); | ||
var _sg = require('./lib/globals'); //"Global" variables | ||
@@ -27,3 +25,3 @@ var formatters = require('./lib/md-formats'); | ||
//Default options | ||
var options = { | ||
let options = { | ||
sgComment: 'SG', | ||
@@ -48,5 +46,6 @@ exampleIdentifier: 'html_example', | ||
htmlOutput: './styleguide/styleguide.html', | ||
jsonOutput: '', | ||
jsonOutput: './styleguide/styleguide.json', | ||
handlebarsPartials: { | ||
"jquery": sanitize.path('./', 'template/jquery.js') | ||
"jquery": sanitize.path('./', 'template/jquery.js'), | ||
"sticky": sanitize.path('./', 'template/sticky.js') | ||
}, | ||
@@ -66,7 +65,8 @@ highlightStyle: 'arduino-light', | ||
//Set up identifiers | ||
_sg.sgUniqueIdentifier = 'md-sg'; | ||
_sg.uniqueIdentifier = 'md-sg'; | ||
//Argument methods | ||
var arg = { | ||
const arg = { | ||
init: function() { | ||
let configFilePath = path.join(process.cwd(), '.styleguide'), | ||
@@ -77,9 +77,16 @@ existingConfig; | ||
existingConfig = fs.readJSONSync(configFilePath, 'utf8'); | ||
} catch(err) { | ||
} | ||
catch(err) { | ||
fs.writeFileSync(configFilePath, JSON.stringify(options,null,'\t')); | ||
listFiles(configFilePath, 'create'); | ||
} | ||
if (existingConfig !== undefined) { | ||
console.error(_sg.error(_sg.logPre + 'Configuration file \'.styleguide\' already exists in this directory.')); | ||
console.warn(_sg.logPre + 'Edit that file, or delete it and run \'init\' again if you want to create a new configuration file.'); | ||
const configError = _sg.error(_sg.logPre + | ||
'Configuration file ' + | ||
_sg.info('\'.styleguide\'') + ' already exists in this directory. \n' + | ||
_sg.logPre + 'Edit that file, or delete it and run ' + | ||
_sg.info('\'init\'') + ' again if you want to create a new configuration file.' | ||
); | ||
throw new Error(configError); | ||
} | ||
@@ -91,17 +98,20 @@ process.exit(0); | ||
}, | ||
ls: function() { | ||
_sg.fileList = true; | ||
}, | ||
help: function() { | ||
console.info(''); | ||
console.info(chalk.cyan(' _____ ')); | ||
console.info(chalk.cyan(' / ___/ _ / | ( ) / | ')); | ||
console.info(chalk.cyan(' | (___ | |_ _ _| | ___ __ _ _ _ _ __| | ___ ')); | ||
console.info(chalk.cyan(' \\___ \\| __| | | | |/ _ \\/ _` | | | | |/ _` |/ _ \\')); | ||
console.info(chalk.cyan(' ____) | |_| |_| | | __/ (_| | |_| | | (_| | __/')); | ||
console.info(chalk.cyan(' \\____/ \\___\\__, |_|\\___/\\__, |\\__,_|_|\\__,_|\\___/')); | ||
console.info(chalk.cyan(' __/ | __/ | ')); | ||
console.info(chalk.cyan(' |___/ |___/ ')); | ||
console.info(_sg.brand(' _____ ')); | ||
console.info(_sg.brand(' / ___/ _ / | ( ) / | ')); | ||
console.info(_sg.brand(' | (___ | |_ _ _| | ___ __ _ _ _ _ __| | ___ ')); | ||
console.info(_sg.brand(' \\___ \\| __| | | | |/ _ \\/ _` | | | | |/ _` |/ _ \\')); | ||
console.info(_sg.brand(' ____) | |_| |_| | | __/ (_| | |_| | | (_| | __/')); | ||
console.info(_sg.brand(' \\____/ \\___\\__, |_|\\___/\\__, |\\__,_|_|\\__,_|\\___/')); | ||
console.info(_sg.brand(' __/ | __/ | ')); | ||
console.info(_sg.brand(' |___/ |___/ ')); | ||
console.info(''); | ||
console.info(' ' + _sg.info('md_documentation') + ' Generate styleguide'); | ||
console.info(' ' + _sg.info('md_documentation init') + ' Create a new configuration file in the current directory'); | ||
console.info(' ' + _sg.info('md_documentation lf') + ' Show "Reading [filename]" during file processing' ); | ||
console.info(' ' + _sg.info('md_documentation help') + ' Show this'); | ||
console.info(' ' + _sg.brand('md_documentation') + ' Generate styleguide'); | ||
console.info(' ' + _sg.brand('md_documentation init') + ' Create a new configuration file in the current directory'); | ||
console.info(' ' + _sg.brand('md_documentation lf') + ' Show "Reading [filename]" during file processing' ); | ||
console.info(' ' + _sg.brand('md_documentation help') + ' Show this'); | ||
console.info(''); | ||
@@ -123,5 +133,5 @@ console.info(' More help at'); | ||
if (args.length > 0) { | ||
var curArg = args[0].toLowerCase(); | ||
let curArg = args[0].toLowerCase(); | ||
if(_.isUndefined(arg[curArg])) { | ||
if (_.isUndefined(arg[curArg])) { | ||
console.info( _sg.logPre + curArg + ' not recognized. Showing help instead.'); | ||
@@ -136,14 +146,20 @@ arg.help(); | ||
function mergeOptions(customOptions) { | ||
var defaults = options; | ||
/** | ||
* Merge custom options with default options. | ||
* | ||
* @param {Object} customOptions - user-provided options | ||
* @return {Object} - Merged options | ||
*/ | ||
function mergeOptions(defaults, customOptions) { | ||
//Resolve relative paths from what is here to what is passed in | ||
//Return a relative path for simpler display purposes | ||
function getPath(folder){ | ||
var root = customOptions.rootFolder; | ||
return path.relative(path.resolve(root), | ||
path.resolve(__dirname, folder)); | ||
const root = path.resolve(customOptions.rootFolder); | ||
return path.relative(root, path.resolve(_sg.moduleDir, folder)); | ||
} | ||
//Resolve paths for only a custom rootFolder | ||
if(customOptions.rootFolder){ | ||
if (customOptions.rootFolder){ | ||
defaults.highlightFolder = getPath(defaults.highlightFolder); | ||
@@ -153,2 +169,3 @@ defaults.templateFile = getPath(defaults.templateFile); | ||
defaults.handlebarsPartials.jquery = getPath(defaults.handlebarsPartials.jquery); | ||
defaults.handlebarsPartials.sticky = getPath(defaults.handlebarsPartials.sticky); | ||
} | ||
@@ -159,3 +176,3 @@ | ||
//Merge custom and defaults | ||
var newOptions = _.merge(defaults, customOptions); | ||
let newOptions = _.merge(defaults, customOptions); | ||
@@ -179,19 +196,31 @@ newOptions.rootFolder = path.resolve(process.cwd(), newOptions.rootFolder); | ||
function readConfig(customOptions) { | ||
function registerConfig(customOptions) { | ||
try { | ||
listFiles(chalk.cyan('Configuration')); | ||
listFiles(_sg.brand('Configuration')); | ||
customOptions = customOptions || fs.readJSONSync('.styleguide', 'utf8'); | ||
}catch(err){ | ||
console.error(_sg.logPre + _sg.error('Error with configuration: ')); | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
catch(err) { | ||
if (err.code !== "ENOENT") { | ||
err.message = _sg.logPre + err.message + '.\n Check your configuration and try again.'; | ||
throw new Error(_sg.error(err)); | ||
} | ||
} | ||
if (_.isUndefined(customOptions)) { | ||
console.info(_sg.logPre + 'No ".styleguide" configuration file (or options) found, using defaults'); | ||
console.info(_sg.warn( | ||
_sg.logPre + | ||
'No configuration file (\'.styleguide\') or options found, using defaults.' | ||
)); | ||
customOptions = { | ||
walkerOptions: { | ||
"filters": options.excludeDirs, | ||
"followLinks": false | ||
} | ||
}; | ||
} | ||
else { | ||
options = mergeOptions(customOptions); | ||
} | ||
return mergeOptions(options, customOptions); | ||
} | ||
@@ -205,19 +234,17 @@ | ||
var root = options.rootFolder; | ||
try { | ||
listFiles(chalk.cyan('Template: ') + options.templateFile); | ||
_sg.templateSource = fs.readFileSync(path.relative(root, options.templateFile), 'utf8'); | ||
listFiles(_sg.brand('Template: ') + options.templateFile); | ||
_sg.templateSource = fs.readFileSync(path.resolve(_sg.root, options.templateFile), 'utf8'); | ||
listFiles(chalk.cyan('Theme: ') + options.themeFile); | ||
_sg.themeSource = fs.readFileSync(path.resolve(root, options.themeFile), 'utf8'); | ||
listFiles(_sg.brand('Theme: ') + options.themeFile); | ||
_sg.themeSource = fs.readFileSync(path.resolve(_sg.root, options.themeFile), 'utf8'); | ||
listFiles(chalk.cyan('Highlight Style: ') + | ||
path.relative(root, options.highlightFolder) + options.highlightStyle + '.css'); | ||
listFiles(_sg.brand('Highlight Style: ') + | ||
path.relative(_sg.root, path.join(options.highlightFolder, options.highlightStyle + '.css'))); | ||
_sg.highlightSource = fs.readFileSync(path.join( | ||
path.resolve(root, options.highlightFolder), options.highlightStyle + '.css'), 'utf8'); | ||
path.resolve(_sg.root, options.highlightFolder), options.highlightStyle + '.css'), 'utf8'); | ||
} | ||
catch(err) { | ||
console.error(_sg.logPre + _sg.error('Could not read file: ' + err.path)); | ||
process.exit(1); | ||
const pathError = _sg.logPre + _sg.error('Could not read file: ' + path.resolve(err.path)); | ||
throw new Error(pathError); | ||
} | ||
@@ -233,11 +260,11 @@ } | ||
function findSection($article) { | ||
var currentSection, sectionIdentifier; | ||
var headerText = $article(tags.category).slice(0, 1).text() + $article(tags.article).text(); | ||
let currentSection, sectionIdentifier; | ||
let headerText = $article(tags.category).slice(0, 1).text() + $article(tags.article).text(); | ||
//Check headings for identifiers declared in "sections" option | ||
for (var sectionName in options.sections){ | ||
for (let sectionName in options.sections){ | ||
if ({}.hasOwnProperty.call(options.sections, sectionName)) { | ||
sectionIdentifier = options.sections[sectionName]; | ||
if(headerText.indexOf(sectionIdentifier) > -1 && sectionIdentifier !== ''){ | ||
if (headerText.indexOf(sectionIdentifier) > -1 && sectionIdentifier !== ''){ | ||
currentSection = sectionName; | ||
@@ -259,3 +286,3 @@ break; | ||
/** | ||
* Constructs a | ||
* Constructs a section object | ||
* | ||
@@ -266,5 +293,5 @@ * @param {Object} $article - article html loaded by cheerio | ||
function SectionStructure() { | ||
var structure = {}; | ||
let structure = {}; | ||
//Create section object for data structure, based on user's "sections" option | ||
for(var name in options.sections) { | ||
for(let name in options.sections) { | ||
if ({}.hasOwnProperty.call(options.sections, name)) { | ||
@@ -284,3 +311,4 @@ structure[name] = []; | ||
* @param {String} sectionIdentifier - string pattern that tells us the current section | ||
* @return {Array} Section Name, Section identifier | ||
* @return {Object} articleData along with meta tags | ||
* | ||
*/ | ||
@@ -294,4 +322,4 @@ function getMetaData($article, articleData, sectionIdentifier) { | ||
//A @section tag is pointing to a non-existant section | ||
if(_.isUndefined(sectionIdentifier)) { | ||
console.info(_sg.logPre + _sg.info("Warning: '" + articleData.currentSection + | ||
if (_.isUndefined(sectionIdentifier)) { | ||
console.info(_sg.logPre + _sg.warn("Warning: '" + chalk.bold(articleData.currentSection) + | ||
"' is not a registered section in your configuration.")); | ||
@@ -310,4 +338,4 @@ sectionIdentifier = ''; | ||
$article(this).remove(); | ||
}else { | ||
} | ||
else { | ||
$article(this).replaceWith( | ||
@@ -326,3 +354,3 @@ _sg.renderer.heading($article(this).text(), 1.1) | ||
$article(tags.example).each(function () { | ||
var categoryCode = $article(this).html().replace(/^\s+|\s+$/g, ''); | ||
let categoryCode = $article(this).html().replace(/^\s+|\s+$/g, ''); | ||
articleData.code.push(categoryCode); | ||
@@ -343,3 +371,3 @@ | ||
$article(tags.priority).each(function() { | ||
var priority = $article(this).text().trim(); | ||
let priority = $article(this).text().trim(); | ||
articleData.priority = (_.isNaN(Number(priority))) ? priority : Number(priority); | ||
@@ -349,5 +377,7 @@ | ||
if(articleData.heading === '') { | ||
if (articleData.heading === '') { | ||
articleData.priority = -1000; | ||
} | ||
return articleData; | ||
} | ||
@@ -363,13 +393,18 @@ | ||
function convertHTMLtoJSON(html) { | ||
var idCache = {}; | ||
var sectionIdentifier = ''; | ||
var previousArticle; | ||
let idCache = {}; | ||
let sectionIdentifier = ''; | ||
let previousArticle; | ||
var $ = cheerio.load(html); | ||
let $ = cheerio.load(html); | ||
sanitize.cheerioWrapAll($); //Add wrapAll method to cheerio | ||
masterData.sections = new SectionStructure(); | ||
let masterData = { | ||
sections: new SectionStructure(), | ||
menus: {}, | ||
colors: {}, | ||
customVariables: options.customVariables | ||
}; | ||
// Loop each section and turn into javascript object | ||
$('.sg-article-' + _sg.sgUniqueIdentifier).each(function() { | ||
$('.sg-article-' + _sg.uniqueIdentifier).each(function() { | ||
let $article = cheerio.load($(this).html()); | ||
@@ -393,7 +428,8 @@ | ||
if ($article(tags.category)[0]) { | ||
let sectionInfo = findSection($article); | ||
const sectionInfo = findSection($article); | ||
articleData.currentSection = sectionInfo[0]; | ||
sectionIdentifier = sectionInfo[1]; | ||
} | ||
else if(previousArticle !== undefined) { | ||
else if (previousArticle !== undefined) { | ||
//Without a heading, assume it should be concatenated with the previous category | ||
@@ -407,14 +443,4 @@ articleData.id = previousArticle.id; | ||
//Search through specific DOM elements for article meta data | ||
getMetaData($article, articleData, sectionIdentifier); | ||
articleData = getMetaData($article, articleData, sectionIdentifier); | ||
//Wrap dd/dt inside <dl>s | ||
// $article('.sg-code-meta-type').each(function (i2, elem2) { | ||
// // var $dddt = $(this).nextUntil(":not(dd, dt)").addBack(); | ||
// // //Must filter outside of chain because of a quirk in cheerio | ||
// // $dddt.filter('dd, dt').wrapAll('<dl class="sg-code-meta-block"></dl>'); | ||
// | ||
// $article('.sg-code-meta-block').find('br').remove(); | ||
// | ||
// }).remove(); | ||
//Give category an ID | ||
@@ -427,3 +453,3 @@ articleData.id = sanitize.makeUrlSafe(articleData.currentSection + '-' + articleData.category + '-' + articleData.heading); | ||
//Move category data to master | ||
checkData(articleData); | ||
return checkData(articleData); | ||
}); | ||
@@ -442,3 +468,3 @@ | ||
function checkData(articleData) { | ||
var currentSection = articleData.currentSection; | ||
let currentSection = articleData.currentSection; | ||
@@ -455,6 +481,6 @@ //Bail out for un-categorized comments | ||
//Grab the index | ||
var currentIndex = idCache[articleData.id][1]; | ||
let currentIndex = idCache[articleData.id][1]; | ||
//Select the matched section from the masterData | ||
var selectedSection = masterData.sections[currentSection][currentIndex]; | ||
let selectedSection = masterData.sections[currentSection][currentIndex]; | ||
@@ -476,7 +502,7 @@ //Append the new data to the matched section | ||
var catIndex = masterData.sections[currentSection].length; | ||
let catIndex = masterData.sections[currentSection].length; | ||
//Cache the ID and its index within its section | ||
idCache[articleData.id] = [currentSection, catIndex]; | ||
articleData.section[currentSection] = true; | ||
articleData.section[_.camelCase(currentSection)] = true; | ||
@@ -496,5 +522,3 @@ articleData.section.name = articleData.currentSection; | ||
masterData = saveToMaster(masterData); | ||
return masterData; | ||
return formatData(masterData); | ||
} | ||
@@ -510,3 +534,3 @@ | ||
*/ | ||
function saveToMaster(data) { | ||
function formatData(data) { | ||
//Sort section data | ||
@@ -520,3 +544,4 @@ if (options.sortCategories){ | ||
function formatData(sectionName, isMenu) { | ||
function formatSections(sectionName, isMenu) { | ||
let menuObj = {}; | ||
@@ -564,4 +589,4 @@ let sectionObj = {}; | ||
Object.keys(options.sections).forEach(function(section){ | ||
data.menus[section] = formatData(section, true); | ||
data.sections[section] = formatData(section, false); | ||
data.menus[section] = formatSections(section, true); | ||
data.sections[section] = formatSections(section, false); | ||
}); | ||
@@ -580,2 +605,3 @@ | ||
function regexType(fileExtension) { | ||
let sgComment = _.escapeRegExp(options.sgComment); | ||
@@ -604,18 +630,16 @@ | ||
fs.readFile(path.join(root, name), 'utf8', function (err, content) { | ||
var match, | ||
let match, | ||
filePath = path.join(root, name), | ||
regex = regexType(fileExtension), | ||
noFiles = true; | ||
regex = regexType(fileExtension); | ||
listFiles(path.relative(options.rootFolder, filePath)); | ||
listFiles(path.relative(_sg.root, filePath)); | ||
if (err) { | ||
console.error(_sg.logPre + _sg.error('File Error: ' + filePath) + err); | ||
process.exit(1); | ||
const fileError = _sg.logPre + _sg.error('File Error: ' + filePath) + err; | ||
throw new Error(fileError); | ||
} | ||
while ((match = regex.exec(content)) !== null) { | ||
noFiles = false; | ||
//If reading anything other than css, create a file-location reference we'll use later | ||
var fileLocation = (fileExtension !== "css") ? '<'+tags.file+'>'+path.relative(options.rootFolder, filePath)+'</'+tags.file+'>': ''; | ||
let fileLocation = (fileExtension !== "css") ? '<'+tags.file+'>'+path.relative(_sg.root, filePath)+'</'+tags.file+'>': ''; | ||
//Convert markdown to html | ||
@@ -628,10 +652,19 @@ fileContents.push(markdown(match[1]) + fileLocation); | ||
/** | ||
* Take JSON, template and write out files or return as templates as a string. | ||
* | ||
* @param {Object} json - styleguide json data | ||
* | ||
*/ | ||
function saveFiles(json){ | ||
let output = {'json': json}; | ||
output.html = template(json, options); | ||
let output = { | ||
'json': json, | ||
'html': template(json, options) | ||
}; | ||
let filePath; | ||
if (options.htmlOutput && _.isString(options.htmlOutput)) { | ||
filePath = path.resolve(options.rootFolder, options.htmlOutput); | ||
filePath = path.resolve(_sg.root, options.htmlOutput); | ||
fs.outputFile(filePath, output.html, function(err) { | ||
@@ -649,5 +682,5 @@ if (err) { | ||
if (options.jsonOutput && _.isString(options.jsonOutput)) { | ||
filePath = path.resolve(options.rootFolder, options.jsonOutput); | ||
fs.outputFile(options.jsonOutput, JSON.stringify(masterData, null, ' '), function(err) { | ||
if(err){ | ||
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')); | ||
@@ -662,3 +695,2 @@ console.error(err); | ||
return output; | ||
@@ -675,7 +707,16 @@ } | ||
*/ | ||
function walkFiles(walker) { | ||
function walkFiles(walker, callback) { | ||
const extensions = _.reduce(options.fileExtensions, function(result, value, key){ | ||
if(value){result.push(key);} | ||
return result; | ||
}, []).join(', '); | ||
console.info(_sg.logPre + _sg.info('Reading ' + extensions + ' files...')); | ||
//Send back file contents once walker has reached its end | ||
var fileContents = []; | ||
walker.on("file", function (root, fileStats, next) { | ||
var fileExtension = fileStats.name.substr((~-fileStats.name.lastIndexOf(".") >>> 0) + 2).toLowerCase(); | ||
let fileExtension = fileStats.name.substr((~-fileStats.name.lastIndexOf(".") >>> 0) + 2).toLowerCase(); | ||
@@ -691,33 +732,27 @@ if (options.fileExtensions[fileExtension]) { | ||
//Send back file contents once walker has reached its end | ||
return new Promise( | ||
function(resolve, reject) { | ||
walker.on("errors", function (root, nodeStatsArray) { | ||
console.error(_sg.logPre + _sg.error('File reading Error')); | ||
console.dir(nodeStatsArray); | ||
process.exit(1); | ||
}); | ||
walker.on("errors", function (root, nodeStatsArray) { | ||
const fileError = _sg.logPre + _sg.error('File reading Error ') + nodeStatsArray; | ||
throw new Error(fileError); | ||
}); | ||
walker.on("end", function () { | ||
//If nothing is found after all files are read, give some info | ||
if (fileContents.length <= 0) { | ||
console.info('\n'+ | ||
_sg.info(_sg.logPre + | ||
'Could not find anything to document.')+ | ||
'Please check the following:'+ | ||
' * You\'ve used /*'+options.sgComment+'*/ style comments.'+ | ||
' * Your "rootFolder" setting is pointing to the root of your style guide files.'+ | ||
' * If you\'re using the default settings, try using the "init" argument.'+ | ||
'If you\'re still receiving this error, please check the documentation or file an issue at'+ | ||
chalk.blue.bold('github.com/UWHealth/markdown-documentation-generator/') | ||
); | ||
reject(); | ||
} | ||
walker.on("end", function () { | ||
//If nothing is found after all files are read, give some info | ||
if (fileContents.length <= 0) { | ||
console.info('\n'+ | ||
_sg.warn(_sg.logPre + | ||
'Could not find anything to document.')+ | ||
'\n Please check the following:'+ | ||
'\n * You\'ve used /*'+options.sgComment+'*/ style comments.'+ | ||
'\n * Your "rootFolder" setting is pointing to the root of your style guide files.'+ | ||
'\n * If you\'re using the default settings, try using the "init" argument.'+ | ||
'\n If you\'re still receiving this error, please check the documentation or file an issue at '+ | ||
chalk.blue.bold('github.com/UWHealth/markdown-documentation-generator/') | ||
); | ||
return false; | ||
} | ||
//Wrap all comments starting with SG in a section, send it back to the promise | ||
resolve(fileContents.join('</div>'+ | ||
'\n<div class="sg-article-' + _sg.sgUniqueIdentifier + '">\n')); | ||
}); | ||
} | ||
); | ||
//Wrap all comments starting with SG in a section, send it back to the promise | ||
return callback(fileContents.join('</div>'+ | ||
'\n<div class="sg-article-' + _sg.uniqueIdentifier + '">\n')); | ||
}); | ||
} | ||
@@ -727,2 +762,3 @@ | ||
function init(args, customOptions) { | ||
//Set up stuff based on arguments | ||
@@ -732,4 +768,7 @@ readArgs(args); | ||
//Read and merge default options with custom ones | ||
readConfig(customOptions); | ||
options = registerConfig(customOptions); | ||
//Create global root reference | ||
_sg.root = path.resolve(options.rootFolder); | ||
//Make sure theme files exist and save their contents globally | ||
@@ -747,40 +786,44 @@ readTheme(); | ||
//Move customVariables options to JSON output | ||
masterData.customVariables = options.customVariables; | ||
let root = path.resolve(options.rootFolder); | ||
//Walk the file tree | ||
return walkFiles(walk.walk(root, options.walkerOptions)).then( | ||
function(fileContents) { | ||
var json = convertHTMLtoJSON('<div class="sg-article-' + _sg.sgUniqueIdentifier + '">\n' + fileContents + '</div>'); | ||
return saveFiles(json); | ||
} | ||
) | ||
.catch(function(err){ | ||
console.log(err); | ||
}); | ||
} | ||
const walker = walk.walk(_sg.root, options.walkerOptions); | ||
/** | ||
* Initialize automatically if not being imported | ||
*/ | ||
if(!module.parent) { | ||
init(process.argv.slice(2)); | ||
try { | ||
return walkFiles(walker, function(fileContents) { | ||
const json = convertHTMLtoJSON('<div class="sg-article-' + _sg.uniqueIdentifier + '">\n' + fileContents + '</div>'); | ||
return saveFiles(json, options); | ||
}); | ||
} | ||
catch(err) { | ||
throw new Error(err); | ||
} | ||
} | ||
module.exports.create = function(argv, customOptions) { | ||
//Assume args is actually customOptions if its an object | ||
if(_.isObject(argv)){ | ||
if (_.isObject(argv)){ | ||
customOptions = argv; | ||
} | ||
else if(! _.isArray(argv)){ | ||
else if (! _.isArray(argv)){ | ||
argv = [argv]; | ||
} | ||
return new Promise( | ||
function(resolve) { | ||
return resolve(init(argv, customOptions)); | ||
return new Promise(function(resolve, reject) { | ||
var data; | ||
try { | ||
data = init(argv, customOptions); | ||
return resolve(data); | ||
} | ||
catch(err){ | ||
return reject(err); | ||
} | ||
} | ||
); | ||
}; | ||
/** | ||
* Initialize automatically if not being imported | ||
*/ | ||
(function(){ | ||
if (!module.parent) { | ||
init(process.argv.slice(2)); | ||
} | ||
}()); |
@@ -0,1 +1,5 @@ | ||
/* jshint node: true */ | ||
/* jshint esnext: true*/ | ||
"use strict"; | ||
var chalk = require('chalk'); | ||
@@ -7,3 +11,4 @@ var path = require('path'); | ||
good: chalk.green, | ||
info: chalk.yellow, | ||
info: chalk.white, | ||
warn: chalk.yellow, | ||
brand: chalk.cyan, | ||
@@ -10,0 +15,0 @@ logPre: chalk.cyan("[Style Guide] "), |
@@ -1,3 +0,7 @@ | ||
var _sg = require('./globals'); | ||
/* jshint node: true */ | ||
/* jshint esnext: true*/ | ||
"use strict"; | ||
var _sg = require('./globals'); | ||
var chalk = require('chalk'); | ||
@@ -23,3 +27,3 @@ | ||
function getTime(){ | ||
function getTime() { | ||
var time = new Date(); | ||
@@ -26,0 +30,0 @@ return time.getHours() + |
/* jshint node: true */ | ||
/* jshint esversion:6 */ | ||
"use strict"; | ||
var tags = require('./tags').tags; | ||
@@ -4,0 +6,0 @@ var patterns = require('./tags').patterns; |
/* jshint node: true */ | ||
"use strict"; | ||
@@ -3,0 +4,0 @@ var _ = require('lodash'); |
@@ -0,1 +1,5 @@ | ||
/* jshint node: true */ | ||
/* jshint esnext: true*/ | ||
"use strict"; | ||
/** | ||
@@ -2,0 +6,0 @@ * Sort a section based on priority, category, or heading |
@@ -0,1 +1,5 @@ | ||
/* jshint node: true */ | ||
/* jshint esnext: true*/ | ||
"use strict"; | ||
/** | ||
@@ -2,0 +6,0 @@ * Tag abstractions library |
@@ -0,1 +1,5 @@ | ||
/* jshint node: true */ | ||
/* jshint esnext: true*/ | ||
"use strict"; | ||
var _sg = require('./globals'); | ||
@@ -18,3 +22,3 @@ var listFiles = require('./log'); | ||
try { | ||
listFiles(_sg.brand('Partial: ') + file); | ||
listFiles(_sg.brand('Partial: ') + path.relative(_sg.root, file)); | ||
return fs.readFileSync(file, 'utf8'); | ||
@@ -35,3 +39,3 @@ } | ||
module.exports = function(json, options) { | ||
var root = options.rootFolder; | ||
//Register Swag helpers | ||
@@ -43,3 +47,3 @@ helpers.registerHelpers(handlebars); | ||
var currentPartial = checkPartial( | ||
path.resolve(root, options.handlebarsPartials[partial]), | ||
path.resolve(_sg.root, options.handlebarsPartials[partial]), | ||
partial | ||
@@ -46,0 +50,0 @@ ); |
{ | ||
"name": "markdown-documentation-generator", | ||
"version": "2.3.2", | ||
"description": "A fork of markdown-styleguide-generator. Searches files for markdown and generates a static style/documentation guide.", | ||
"version": "2.4.0", | ||
"description": "Searches files for markdown and generates a static style/documentation guide. A fork of markdown-styleguide-generator.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "nodemon --ignore */styleguide/ -e js,hbs,css,styleguide index.js" | ||
"test": "node test.js" | ||
}, | ||
@@ -30,2 +30,5 @@ "repository": { | ||
"homepage": "https://github.com/UWHealth/markdown-documentation-generator#readme", | ||
"engines": { | ||
"node": ">= 4" | ||
}, | ||
"dependencies": { | ||
@@ -38,6 +41,9 @@ "chalk": "^1.1.3", | ||
"lodash": "^4.13.1", | ||
"marked": "^0.3.5", | ||
"marked": "^0.3.6", | ||
"swag": "^0.7.0", | ||
"walk": "^2.3.9" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.11.0" | ||
}, | ||
"bin": { | ||
@@ -44,0 +50,0 @@ "md_documentation": "index.js" |
@@ -326,3 +326,3 @@ # markdown-documentation-generator | ||
"sections": { | ||
"sectionName": { | ||
"section Name": { | ||
"category": "Category Name", | ||
@@ -336,3 +336,3 @@ "id": "category-name (HTML safe)" | ||
"name": "Parent Section", | ||
"ParentSection": true //Useful for template checks | ||
"parentSection": true //Useful for template checks (always camel cased) | ||
}, | ||
@@ -352,3 +352,3 @@ "file": "File path where this article originated", | ||
"menus": [ | ||
"sectionName": [ | ||
"section Name": [ | ||
{ | ||
@@ -355,0 +355,0 @@ "category": 'Category Name (one per unique "# Category")', |
26
test.js
@@ -1,22 +0,8 @@ | ||
"use strict"; | ||
var nodemon = require('nodemon'); | ||
var sys = require('util') | ||
var exec = require('child_process').exec; | ||
var path = require('path'); | ||
var pathToBin = path.join(process.cwd(), 'node_modules', '.bin') | ||
var pathToBin = path.join(process.cwd(), 'node_modules', '.bin') | ||
var pathName = /^win/.test(process.platform) ? 'Path' : 'PATH' | ||
var newPath = pathToBin + path.delimiter + process.env[pathName] | ||
exec('md_documentation lf', { | ||
env:{PATH:newPath} | ||
}, | ||
function(error, stdout, stderr){ | ||
console.log(`stdout: ${stdout}`); | ||
console.log(`stderr: ${stderr}`); | ||
if (error !== null) { | ||
console.log(`exec error: ${error}`); | ||
} | ||
nodemon( | ||
'--ignore */styleguide/ -e js,hbs,css,styleguide index.js ls' | ||
) | ||
.on('quit', function() { | ||
process.exit(0); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1123102
40
4051
2
1
Updatedmarked@^0.3.6