Skip to content

Commit

Permalink
add author support
Browse files Browse the repository at this point in the history
  • Loading branch information
TimurRin committed Aug 12, 2024
1 parent 89e1eaf commit 34ad351
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 36 deletions.
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ npm test

## Authors

### Maintainers

- Timur Moziev ([@TimurRin](https://github.com/TimurRin))
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ npm install -g anca

Visit [`CONTRIBUTING.md`](CONTRIBUTING.md).

Current maintainers:

- Timur Moziev ([@TimurRin](https://github.com/TimurRin))
Current maintainer - Timur Moziev ([@TimurRin](https://github.com/TimurRin))

## License

Expand Down
7 changes: 4 additions & 3 deletions anca.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
"name": "Timur Moziev",
"github": "TimurRin",
"email": "timur.moziev@gmail.com",
"type": "maintainer",
"type": "author",
"status": "active",
"url": "https://timurrin.github.io/"
}
],
"cinnabarMeta": {
"dataVersion": 0,
"version": {
"latest": "0.1.0-dev.2",
"latestNext": "0.1.0-dev.2+next.20240812_132412",
"timestamp": 1723469052
"latestNext": "0.1.0-dev.2+next.20240812_153741",
"timestamp": 1723477061
},
"files": [
{
Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
"project manager"
],
"license": "ISC",
"contributors": [
{
"email": "timur.moziev@gmail.com",
"name": "Timur Moziev",
"url": "https://timurrin.github.io/"
}
],
"author": {
"email": "timur.moziev@gmail.com",
"name": "Timur Moziev",
"url": "https://timurrin.github.io/"
},
"files": [
"bin",
"dist"
Expand Down
14 changes: 10 additions & 4 deletions src/actions/contributing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ function getContents(development: AncaDevelopment) {
if (development.state.config.authors) {
lines.push(`## Authors`);

// Group authors by type
const groupedAuthors: Record<string, AncaConfigAuthor[]> = {
authors: [],
contributors: [],
maintainers: [],
specials: [],
};

development.state.config.authors.forEach((author) => {
if (author.type === "maintainer") {
if (author.type === "author") {
groupedAuthors.authors.push(author);
} else if (author.type === "maintainer") {
groupedAuthors.maintainers.push(author);
} else if (author.type === "contributor") {
groupedAuthors.contributors.push(author);
Expand All @@ -59,12 +61,16 @@ function getContents(development: AncaDevelopment) {
}
});

// Sort each group alphabetically by name
Object.keys(groupedAuthors).forEach((key) => {
groupedAuthors[key].sort((a, b) => a.name.localeCompare(b.name));
});

// Generate sections for each group
if (groupedAuthors.authors.length > 0) {
groupedAuthors.authors.forEach((author) => {
lines.push(formatAuthorLine(author));
});
}

if (groupedAuthors.maintainers.length > 0) {
lines.push(`### Maintainers`);
groupedAuthors.maintainers.forEach((author) => {
Expand Down
68 changes: 57 additions & 11 deletions src/actions/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const packageNameOrder = [
"homepage",
"bugs",
"license",
"author",
"contributors",
"funding",
"files",
Expand Down Expand Up @@ -143,16 +144,48 @@ const FILE_PATH = "package.json";
*
* @param config
*/
function getContributors(config: AncaConfig) {
return (
config.authors?.map((author) => {
return {
function getAuthors(config: AncaConfig) {
const authors: {
author?: NodeJsPackageAuthor;
contributors?: NodeJsPackageAuthor[];
} = {};

if (config.authors == null) {
return authors;
}

for (const author of config.authors) {
const isAuthor = author.type === "author" && authors.author == null;
const isMaintainer =
author.type === "maintainer" && author.status !== "retired";

if (!isAuthor && !isMaintainer) {
continue;
}

const authorNew: NodeJsPackageAuthor = { name: author.name };
if (author.email) {
authorNew.email = author.email;
}
if (author.url) {
authorNew.url = author.url;
}

if (isAuthor) {
authors.author = {
email: author.email,
name: author.name,
url: author.url,
};
}) || []
);
} else if (isMaintainer) {
if (authors.contributors == null) {
authors.contributors = [];
}
authors.contributors.push(authorNew);
}
}

return authors;
}

/**
Expand Down Expand Up @@ -279,8 +312,11 @@ function hasLicense(contents: NodejsPackageJson) {
* @param config
*/
function hasContributors(contents: NodejsPackageJson, config: AncaConfig) {
const contributors = getContributors(config);
return isDeepStrictEqual(contributors, contents.contributors);
const authors = getAuthors(config);
return (
isDeepStrictEqual(authors.author, contents.author) &&
isDeepStrictEqual(authors.contributors, contents.contributors)
);
}

/**
Expand Down Expand Up @@ -781,9 +817,19 @@ async function fixPackageContributors(
contents: NodejsPackageJson,
config: AncaConfig,
) {
const contributors = getContributors(config);
rebuildFile.contributors = contributors;
contents.author = null;
const authors = getAuthors(config);

if (authors.author) {
rebuildFile.author = authors.author;
} else {
contents.author = null;
}

if (authors.contributors) {
rebuildFile.contributors = authors.contributors;
} else {
contents.contributors = null;
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/actions/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ function getContents(development: AncaDevelopment) {

if (development.state.config.authors) {
const maintainers = development.state.config.authors.filter(
(author) => author.type === "maintainer",
(author) =>
(author.type === "author" || author.type === "maintainer") &&
author.status !== "retired",
);
if (maintainers.length > 0) {
if (maintainers.length > 1) {
lines.push(`Current maintainers:`);
lines.push(...maintainers.map(formatAuthorLine));
} else if (maintainers.length === 1) {
lines.push(`Current maintainer ${formatAuthorLine(maintainers[0])}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cinnabar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was generated by Cinnabar Meta. Do not edit.

export const CINNABAR_PROJECT_TIMESTAMP = 1723469052;
export const CINNABAR_PROJECT_VERSION = "0.1.0-dev.2+next.20240812_132412";
export const CINNABAR_PROJECT_TIMESTAMP = 1723477061;
export const CINNABAR_PROJECT_VERSION = "0.1.0-dev.2+next.20240812_153741";
9 changes: 7 additions & 2 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ export interface AncaConfigAuthor {
email?: string;
github?: string;
name: string;
status?: "active" | "inactive" | "retired";
text?: string;
type?: "contributor" | "maintainer" | "special";
type?: "author" | "contributor" | "maintainer" | "special";
url?: string;
}

Expand Down Expand Up @@ -199,9 +200,10 @@ export const ANCA_CONFIG_SCHEMA = {
email: { type: "string" },
github: { type: "string" },
name: { type: "string" },
status: { enum: ["active", "inactive", "retired"], type: "string" },
text: { type: "string" },
type: {
enum: ["contributor", "maintainer", "special"],
enum: ["author", "contributor", "maintainer", "special"],
type: "string",
},
url: { type: "string" },
Expand Down Expand Up @@ -317,6 +319,9 @@ export function formatAuthorLine(author: AncaConfigAuthor): string {
} else if (author.email) {
authorLine += ` — <${author.email}>`;
}
if (author.status != null && author.status !== "active") {
authorLine += ` — ${author.status}`;
}
if (author.text) {
authorLine += ` — ${author.text}`;
}
Expand Down

0 comments on commit 34ad351

Please sign in to comment.