git-auto-badger
Version:
Add badges to your project markdown in 2 seconds
31 lines (30 loc) • 1.39 kB
JavaScript
const { providerTypes, badgeTypes } = require("../constants/types");
const { detectType } = require("../helpers/detectType");
const { packageManagerProviders } = require("../constants/provierConstants");
const { readCacheFile } = require("../helpers/readCacheFile");
const chalk = require("chalk");
exports.generate = async function ({ exclude }) {
if (exclude.includes(badgeTypes.SIZE)) return "";
const { type } = await detectType(packageManagerProviders, "Package manager");
switch (type) {
case providerTypes.NPM: {
let packagejson = await readCacheFile("package.json");
packagejson = JSON.parse(packagejson);
if (packagejson.bin && Object.keys(packagejson.bin).length > 0) {
return `[](https://packagephobia.com/result?p=${packagejson.name})`;
}
return [
`[](https://bundlephobia.com/result?p=${packagejson.name})`,
`[](https://bundlephobia.com/result?p=${packagejson.name})`,
].join("\n");
}
default: {
console.warn(
chalk.yellow(
"Could not find any size related configuration. Skipping it..."
)
);
return "";
}
}
};