diff --git a/meta/scoreboard/index.js b/meta/scoreboard/index.js index 24584819..924c4975 100644 --- a/meta/scoreboard/index.js +++ b/meta/scoreboard/index.js @@ -7,27 +7,54 @@ const lernaConfig = require(join(rootDir, 'lerna.json')) const modulesDir = join(rootDir, 'modules') require('console.table') -const checks = [ - function hasStories(module) { - const key = 'has stories' +const unique = list => Array.from(new Set(list)).sort() + +const matchAll = (pattern, text) => { + const matches = [] + let match + while (match = pattern.exec(text)) { + matches.push(match) + } + return matches +} + +const checks = { + 'has stories': (module, key) => { return globby(join(module.path, '**/stories.js')) - .then(files => ({[key]: files.length > 0 ? 'yes' : 'no'})) + .then(files => ({ + [key]: files.length > 0 ? 'yes' : 'no' + })) }, - function passesDocTest(module) { - const key = 'docs test' + 'docs test': (module, key) => { return execa(join(rootDir, 'script/test-docs'), { cwd: module.path }) - .then(result => { - return {[key]: '✔'} - }) - .catch(result => { - return {[key]: 'FAIL'} + .then(result => ({[key]: 'pass'})) + .catch(({stderr}) => { + const pattern = /("\.[-\w]+") is not documented/g + const matches = matchAll(pattern, stderr) + .map(match => match[1]) + let missing = matches ? Array.from(matches) : [] + const max = 5 + if (missing.length > max) { + const more = missing.length - max + missing = missing.slice(0, max).concat(`and ${more} more...`) + } + return { + [key]: 'FAIL', + 'missing docs': unique(missing).join(', ') + } }) } -] +} -const modules = globby(join(modulesDir, 'primer-*')) +const args = process.argv.slice(2) + +const modules = args.length + ? Promise.resolve(args) + : globby(join(modulesDir, 'primer-*')) + +modules .then(moduleDirs => { console.log('Found %d module directories', moduleDirs.length) return moduleDirs @@ -40,19 +67,23 @@ const modules = globby(join(modulesDir, 'primer-*')) }) .then(modules => { console.log('Filtered to %d modules (excluding meta-packages)', modules.length) - const queue = new PromiseQueue({concurrency: 5}) + + const queue = new PromiseQueue({concurrency: 3}) + for (const module of modules) { module.checks = {} - for (const check of checks) { + for (const [name, check] of Object.entries(checks)) { queue.add(() => { - console.warn(`? check: ${module.name} ${check.name}`) - return check(module) + // console.warn(`? check: ${module.name} ${name}`) + return check(module, name) .then(result => { Object.assign(module.checks, result) }) }) } } + + console.warn(`Running ${queue.size} checks...`) return queue.onIdle().then(() => modules) }) .then(modules => { diff --git a/meta/scoreboard/package.json b/meta/scoreboard/package.json index 70a151cf..706dba94 100644 --- a/meta/scoreboard/package.json +++ b/meta/scoreboard/package.json @@ -3,7 +3,7 @@ "devDependencies": { "console.table": "^0.10.0", "execa": "^0.10.0", - "globby": "^8.0.1", + "globby": "^6.1.0", "p-queue": "^2.4.2" } }