From 7b8e49fe91dc3bf6e2dcd25e56d7b78072cc9f84 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 4 Mar 2019 15:26:23 -0800 Subject: [PATCH] Add update-codeowners script Right now it works but doesn't open a PR for you. Also not present as an npm script. --- scripts/tsconfig.json | 9 ++---- scripts/update-codeowners.js | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 scripts/update-codeowners.js diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 899f96af64..a79409f406 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -2,12 +2,7 @@ "compilerOptions": { "module": "commonjs", "target": "es6", - "noImplicitAny": true, - "strictNullChecks": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": true, - "noUnusedParameters": true, + "strict": true, "baseUrl": "../types", "typeRoots": [ "../types" @@ -15,4 +10,4 @@ "types": [], "forceConsistentCasingInFileNames": true } -} \ No newline at end of file +} diff --git a/scripts/update-codeowners.js b/scripts/update-codeowners.js new file mode 100644 index 0000000000..bbe42e52f2 --- /dev/null +++ b/scripts/update-codeowners.js @@ -0,0 +1,57 @@ +const { AllPackages, getDefinitelyTyped, logUncaughtErrors, loggerWithErrors, + parseDefinitions, parseNProcesses, clean } = require("types-publisher"); +const { writeFile } = require("fs-extra"); + +logUncaughtErrors(main()); + +async function main() { + const options = { definitelyTypedPath: "..", progress: false, parseInParallel: true }; + const log = loggerWithErrors()[0]; + + clean(); + const dt = await getDefinitelyTyped(options, log); + await parseDefinitions(dt, { nProcesses: parseNProcesses(), definitelyTypedPath: ".." }, log); + const allPackages = await AllPackages.read(dt); + const typings = allPackages.allTypings(); + const maxPathLen = Math.max(...typings.map(t => t.subDirectoryPath.length)); + const entries = mapDefined(typings, t => getEntry(t, maxPathLen)); + await writeFile([options.definitelyTypedPath, ".github", "CODEOWNERS"].join("/"), `${header}\n\n${entries.join("\n")}\n`, { encoding: "utf-8" }); +} + +const header = +`# This file is generated. +# Add yourself to the "Definitions by:" list instead. +# See https://github.com/DefinitelyTyped/DefinitelyTyped#edit-an-existing-package`; + +/** + * @param { { contributors: ReadonlyArray<{githubUsername?: string }>, subDirectoryPath: string} } pkg + * @param {number} maxPathLen + * @return {string | undefined} + */ +function getEntry(pkg, maxPathLen) { + const users = mapDefined(pkg.contributors, c => c.githubUsername); + if (!users.length) { + return undefined; + } + + const path = `${pkg.subDirectoryPath}/`.padEnd(maxPathLen); + return `/types/${path} ${users.map(u => `@${u}`).join(" ")}`; +} + +/** + * @template T,U + * @param {ReadonlyArray} arr + * @param {(t: T) => U | undefined} mapper + * @return U[] + */ +function mapDefined(arr, mapper) { + const out = []; + for (const a of arr) { + const res = mapper(a); + if (res !== undefined) { + out.push(res); + } + } + return out; +} +