mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-10 12:10:18 +00:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
57
scripts/update-codeowners.js
Normal file
57
scripts/update-codeowners.js
Normal 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user