Skip to content

Commit

Permalink
feat: prioritise name*, version, author, contributor and `des…
Browse files Browse the repository at this point in the history
…cription` headers
  • Loading branch information
double-beep committed Oct 14, 2024
1 parent 6fbb3d4 commit 7ae724f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/generators/common/monkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,25 @@ export const finalizeMonkeyHeaders = <T extends CommonHeaders<CustomHeaders>>(

const longest = getLongest(headers.map(([key]) => key)) + spaces - 1;

// @name header should come first, the rest are sorted alphabetically
const sortedHeaders: HeaderEntries<T> = headers.sort(
([a], [b]) => a === "name" ? -1 : a < b ? -1 : 1,
);
// these should go first
const important = [
"name",
"namespace",
"version",
"author",
"contributor",
"contributors",
];

const primary = important
.map(name => headers.find(([header]) => header === name))
.filter(Boolean) as HeaderEntries<T>;
const secondary = headers.filter(([header]) => !important.includes(header));

const sortedHeaders = [
...primary,
...secondary,
];

const indentedHeaders: HeaderEntries<T> = sortedHeaders.map(([key, val]) => [
key.padEnd(longest),
Expand Down

0 comments on commit 7ae724f

Please sign in to comment.