Add update-codeowners script

Right now it works but doesn't open a PR for you.
Also not present as an npm script.
This commit is contained in:
Nathan Shively-Sanders
2019-03-04 15:26:23 -08:00
parent 843c4c82bb
commit 7b8e49fe91
2 changed files with 59 additions and 7 deletions

View File

@@ -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
}
}
}

View File

@@ -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<T>} 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;
}