Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Oct 8, 2020
1 parent 9542494 commit 284c18a
Showing 1 changed file with 56 additions and 51 deletions.
107 changes: 56 additions & 51 deletions plugins/all-contributors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function getRcFile(auto: Auto) {
`Encountered errors loading all-contributors configuration at ${rcFile}`,
error
);
process.exit(1)
process.exit(1);
}
}

Expand Down Expand Up @@ -174,24 +174,29 @@ function getExtraContributors(body?: string) {
}

/** Determine which files need to display contributors and generate contributors */
function generateContributorReadme(config: AllContributorsRc, contributors: any) {
return Promise.all((config.files || ["README.md"]).map(async (file) => {
const oldReadMe = fs.readFileSync(file, {
encoding: "utf-8",
});
const newReadMe = await generateReadme(
{
contributorsPerLine: 7,
imageSize: 100,
...config,
function generateContributorReadme(
config: AllContributorsRc,
contributors: any
) {
return Promise.all(
(config.files || ["README.md"]).map(async (file) => {
const oldReadMe = fs.readFileSync(file, {
encoding: "utf-8",
});
const newReadMe = await generateReadme(
{
contributorsPerLine: 7,
imageSize: 100,
...config,
contributors,
},
contributors,
},
contributors,
oldReadMe
);
fs.writeFileSync(file, newReadMe);
}));
}
oldReadMe
);
fs.writeFileSync(file, newReadMe);
})
);
}

/** Automatically add contributors as changelogs are produced. */
export default class AllContributorsPlugin implements IPlugin {
Expand Down Expand Up @@ -265,38 +270,40 @@ export default class AllContributorsPlugin implements IPlugin {
const message = endent`
# Extra Contributions
${hasValidTypes
? endent`
${
hasValidTypes
? endent`
The following contributions will be added to all-contributors (as well as any code contributions) when this PR is released :tada::
${Object.entries(extra)
.map(([username, contributions]) => {
const validContributions = [...contributions].filter(
isContribution
);
if (!validContributions.length) {
return "";
}
return `- @${username} - ${validContributions.join(", ")}`;
})
.filter(Boolean)
.join("\n")}
.map(([username, contributions]) => {
const validContributions = [...contributions].filter(
isContribution
);
if (!validContributions.length) {
return "";
}
return `- @${username} - ${validContributions.join(", ")}`;
})
.filter(Boolean)
.join("\n")}
`
: "No valid contribution types found!"
: "No valid contribution types found!"
}
${unknownTypes.length
? endent`
${
unknownTypes.length
? endent`
## Unknown Contribution Types
We found some unknown contribution types in your PR body!
These contributions will not be counted and you should fix them.
${unknownTypes.map((type) => `- \`${type}\``)}
`
: ""
: ""
}
`;

Expand All @@ -318,7 +325,7 @@ export default class AllContributorsPlugin implements IPlugin {
try {
// Try to get sub-packages
packages = [...packages, ...(await getLernaPackages())];
} catch (error) { }
} catch (error) {}

// Go through each package and update code contributions
await packages.reduce(async (last, { name, path }) => {
Expand Down Expand Up @@ -397,8 +404,6 @@ export default class AllContributorsPlugin implements IPlugin {
});
}



/** Update the contributors rc for a package. */
private async updateContributors(auto: Auto, commits: IExtendedCommit[]) {
const config = getRcFile(auto);
Expand Down Expand Up @@ -511,31 +516,31 @@ export default class AllContributorsPlugin implements IPlugin {
);
this.generatedReadme = true;
// Update files that contain contributors table
await generateContributorReadme(config, contributors)

}
else {
await generateContributorReadme(config, contributors);
} else {
auto.logger.verbose.warn(`"${username}" had no new contributions...`);
}
}

if (config.contributors.length && !this.generatedReadme) {
if (config.contributors.length && !this.generatedReadme) {
// if the all-contributors has not been generated ... generate it
try {
// test if the first file in the list of files has been init
const file = path.join(process.cwd(), (config.files ? config.files[0] : "README.md"));
const file = path.join(
process.cwd(),
config.files ? config.files[0] : "README.md"
);

const displayFile = file ? fs.readFileSync(file, 'utf8') : '';
const displayFile = file ? fs.readFileSync(file, "utf8") : "";

const notInitalized = displayFile.indexOf(
'<!-- markdownlint-disable -->\n<!-- markdownlint-restore -->'
"<!-- markdownlint-disable -->\n<!-- markdownlint-restore -->"
);

if (notInitalized && file) {
await generateContributorReadme(config, config.contributors)

await generateContributorReadme(config, config.contributors);
}
} catch { }
} catch {}
}

if (didUpdate) {
Expand Down

0 comments on commit 284c18a

Please sign in to comment.