diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/dist/index.js b/dist/index.js index 96cd76e..285f20d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -22,7 +22,7 @@ var _es6TemplateStrings = require('es6-template-strings'); var _es6TemplateStrings2 = _interopRequireDefault(_es6TemplateStrings); -var _macros = require('./macros'); +var _macros = require("./macros"); var macros = _interopRequireWildcard(_macros); @@ -76,7 +76,7 @@ function compile(userPath, fallbackPath, cb) { * or the default node-readme `src/.README.md` template */ function createReadme() { - var overwrite = arguments[0] === undefined ? true : arguments[0]; + var overwrite = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0]; compile('.README.md', _path2['default'].join(__dirname, './.README.md'), function (markdown) { var destination = _path2['default'].join(process.cwd(), './README.md'); diff --git a/dist/macros/badge.js b/dist/macros/badge.js index 7936eb9..901409d 100644 --- a/dist/macros/badge.js +++ b/dist/macros/badge.js @@ -6,7 +6,7 @@ Object.defineProperty(exports, '__esModule', { exports['default'] = badge; function image(src) { - var title = arguments[1] === undefined ? '' : arguments[1]; + var title = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1]; return '![' + title + '](' + src + ')'; } diff --git a/dist/macros/dependencies.js b/dist/macros/dependencies.js index 73e9181..979cbd5 100644 --- a/dist/macros/dependencies.js +++ b/dist/macros/dependencies.js @@ -8,14 +8,14 @@ exports['default'] = dependencies; function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } function singleDep(name, version) { - var dev = arguments[2] === undefined ? false : arguments[2]; + var dev = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; var check = dev ? '✔' : '✖'; return '[' + name + '](https://www.npmjs.com/package/' + name + ') | ' + version + ' | ' + check; } function dependenciesList(obj) { - var dev = arguments[1] === undefined ? false : arguments[1]; + var dev = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; if (!obj) { obj = {}; diff --git a/dist/macros/index.js b/dist/macros/index.js index bd5192d..88e7fea 100644 --- a/dist/macros/index.js +++ b/dist/macros/index.js @@ -34,4 +34,10 @@ var _dependencies2 = require('./dependencies'); var _dependencies3 = _interopRequireDefault(_dependencies2); -exports.dependencies = _dependencies3['default']; \ No newline at end of file +exports.dependencies = _dependencies3['default']; + +var _subdirs2 = require('./subdirs'); + +var _subdirs3 = _interopRequireDefault(_subdirs2); + +exports.subdirs = _subdirs3['default']; \ No newline at end of file diff --git a/dist/macros/license.js b/dist/macros/license.js index 53d2866..39f71ab 100644 --- a/dist/macros/license.js +++ b/dist/macros/license.js @@ -17,7 +17,7 @@ function license(options, scope) { } else if (scope.pkg.licenses) { return scope.pkg.licenses.map(function (license) { return singleLicense(license.type); - }).join(';'); + }).join('\;'); } } diff --git a/dist/macros/subdirs.js b/dist/macros/subdirs.js new file mode 100644 index 0000000..7033e9b --- /dev/null +++ b/dist/macros/subdirs.js @@ -0,0 +1,48 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports['default'] = subdirs; +var path = require('path'); +var fs = require('fs'); + +var walk = function walk(dir) { + var results = []; + var list = fs.readdirSync(dir); + list.forEach(function (file) { + file = dir + '/' + file; + var stat = fs.statSync(file); + if (stat && stat.isDirectory()) results = results.concat(walk(file));else results.push(file); + }); + return results; +}; + +function subdirs(options, scope) { + var subdir = options || ''; + var basePath = path.resolve('.', subdir); + var readmes = walk(basePath); + var struct = readmes.reduce(function (acc, filepath) { + var relativePath = filepath.replace(basePath + '/', ''); + var componentName = relativePath.split('/').slice(0, 1)[0]; + var firstLetter = componentName[0]; + if (/\./i.test(componentName)) { + return acc; + } + if (!acc.hasOwnProperty(componentName)) { + acc[componentName] = true; + } + if (/readme\.md/i.test(relativePath)) { + acc[componentName] = true; + } + return acc; + }, {}); + return Object.keys(struct).map(function (key) { + if (struct[key]) { + return '- [' + key + '](' + subdir + '/' + key + ')'; + } + return '- ' + key; + }).join('\n'); +} + +module.exports = exports['default']; \ No newline at end of file diff --git a/src/macros/index.js b/src/macros/index.js index 3b7eb04..92c8d63 100644 --- a/src/macros/index.js +++ b/src/macros/index.js @@ -4,3 +4,4 @@ export badge from './badge'; export license from './license'; export author from './author'; export dependencies from './dependencies'; +export subdirs from './subdirs'; diff --git a/src/macros/subdirs.js b/src/macros/subdirs.js new file mode 100644 index 0000000..73e5657 --- /dev/null +++ b/src/macros/subdirs.js @@ -0,0 +1,42 @@ +var path = require('path'); +var fs = require('fs'); + + +var walk = function(dir) { + var results = [] + var list = fs.readdirSync(dir) + list.forEach(function(file) { + file = dir + '/' + file + var stat = fs.statSync(file) + if (stat && stat.isDirectory()) results = results.concat(walk(file)) + else results.push(file) + }) + return results +} + +export default function subdirs(options, scope) { + const subdir = options || '' + var basePath = path.resolve('.', subdir) + var readmes = walk(basePath) + const struct = readmes.reduce((acc, filepath) => { + const relativePath = filepath.replace(basePath + '/', '') + const componentName = relativePath.split('/').slice(0, 1)[0] + const firstLetter = componentName[0] + if (/\./i.test(componentName)) { + return acc + } + if (!acc.hasOwnProperty(componentName)) { + acc[componentName] = true + } + if (/readme\.md/i.test(relativePath)) { + acc[componentName] = true + } + return acc + }, {}) + return Object.keys(struct).map(key => { + if (struct[key]) { + return `- [${key}](${subdir}/${key})` + } + return `- ${key}` + }).join('\n') +}