From 3127962cd13429a1fa46041cf1098af4ab958c7d Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 18 Mar 2019 12:26:27 -0700 Subject: [PATCH] Fix authors script (#30440) --- scripts/authors.ts | 92 +++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/scripts/authors.ts b/scripts/authors.ts index b52898244b63c..f92511ed6efdb 100644 --- a/scripts/authors.ts +++ b/scripts/authors.ts @@ -15,8 +15,8 @@ type Command = { description?: string; }; -const mailMapPath = path.resolve("../.mailmap"); -const authorsPath = path.resolve("../AUTHORS.md"); +const mailMapPath = path.resolve(__dirname, "../.mailmap"); +const authorsPath = path.resolve(__dirname, "../AUTHORS.md"); function getKnownAuthors(): Author[] { const segmentRegExp = /\s?([^<]+)\s+<([^>]+)>/g; @@ -113,56 +113,54 @@ namespace Commands { const cmd = "git shortlog -se " + specs.join(" "); console.log(cmd); const outputRegExp = /\d+\s+([^<]+)<([^>]+)>/; - const tty = process.platform === 'win32' ? 'CON' : '/dev/tty'; const authors: { name: string, email: string, knownAuthor?: Author }[] = []; - child_process.exec(`${cmd} < ${tty}`, { cwd: path.resolve("../") }, function (error, stdout, stderr) { - if (error) { - console.log(stderr.toString()); - } - else { - const output = stdout.toString(); - const lines = output.split("\n"); - lines.forEach(line => { - if (line) { - let match: RegExpExecArray | null; - if (match = outputRegExp.exec(line)) { - authors.push({ name: match[1], email: match[2] }); - } - else { - throw new Error("Could not parse output: " + line); - } + const {output: [error, stdout, stderr]} = child_process.spawnSync(`git`, ["shortlog", "-se", ...specs], { cwd: path.resolve(__dirname, "../") }); + if (error) { + console.log(stderr.toString()); + } + else { + const output = stdout.toString(); + const lines = output.split("\n"); + lines.forEach(line => { + if (line) { + let match: RegExpExecArray | null; + if (match = outputRegExp.exec(line)) { + authors.push({ name: match[1], email: match[2] }); + } + else { + throw new Error("Could not parse output: " + line); } - }); - - const maps = getKnownAuthorMaps(); - - const lookupAuthor = function ({name, email}: { name: string, email: string }) { - return maps.authorsByEmail[email.toLocaleLowerCase()] || maps.authorsByName[name]; - }; - - const knownAuthors = authors - .map(lookupAuthor) - .filter(a => !!a) - .map(getAuthorName); - const unknownAuthors = authors - .filter(a => !lookupAuthor(a)) - .map(a => `${a.name} <${a.email}>`); - - if (knownAuthors.length) { - console.log("\r\n"); - console.log("Found known authors: "); - console.log("====================="); - deduplicate(knownAuthors).sort(sortAuthors).forEach(log); } + }); + + const maps = getKnownAuthorMaps(); + + const lookupAuthor = function ({name, email}: { name: string, email: string }) { + return maps.authorsByEmail[email.toLocaleLowerCase()] || maps.authorsByName[name]; + }; + + const knownAuthors = authors + .map(lookupAuthor) + .filter(a => !!a) + .map(getAuthorName); + const unknownAuthors = authors + .filter(a => !lookupAuthor(a)) + .map(a => `${a.name} <${a.email}>`); + + if (knownAuthors.length) { + console.log("\r\n"); + console.log("Found known authors: "); + console.log("====================="); + deduplicate(knownAuthors).sort(sortAuthors).forEach(log); + } - if (unknownAuthors.length) { - console.log("\r\n"); - console.log("Found unknown authors: "); - console.log("====================="); - deduplicate(unknownAuthors).sort(sortAuthors).forEach(log); - } + if (unknownAuthors.length) { + console.log("\r\n"); + console.log("Found unknown authors: "); + console.log("====================="); + deduplicate(unknownAuthors).sort(sortAuthors).forEach(log); } - }); + } }; listAuthors.description = "List known and unknown authors for a given spec, e.g. 'node authors.js listAuthors origin/release-2.6..origin/release-2.7'"; }