#!/usr/bin/env node import { logger } from '@4lch4/logger' import { Commander } from '@4lch4/lt-commander' import fs from 'fs-extra' import { getBadgeFooter, getBadgeHeader } from './URLs.js' // Commander.program // .name('badge-code-generator') // .version('0.0.1') // .description('Generate the code to display my usual badges.') // .addOption(readmePath) // .addOption(repoName) // .addOption(repoOwner) // .action(main) // const OwnerArg = new Commander.Argument('owner', 'The owner of the repository.') // .argRequired() // .default('4lch4') // const RepoArg = new Commander.Argument( // 'repo', // 'The name of the repository.' // ).argRequired() // const ReadmeOpt = new Commander.Option( // '-r, --readme [path]', // 'The path to the README file you wish to add the badges to.' // ) // .makeOptionMandatory(false) // .default('./README.md') // const PackageNameOpt = new Commander.Option( // '-p, --package [name]', // 'The name of the NPM package to use for Snyk vulnerability scanning (e.g. @4lch4/logger).' // ) // const PackageNameArg = new Commander.Argument( // 'package', // 'The name of the NPM package to use for Snyk vulnerability scanning.' // ).argOptional() Commander.program .name('badge-code-generator') .version('0.0.1') .description('Generate the code to display my usual badges.') .addArgument( new Commander.Argument('', 'The owner of the repository.') ) .addArgument(new Commander.Argument('', 'The name of the repository.')) .addOption( new Commander.Option( '-r, --readme [path]', 'The path to the README file you wish to add the badges to.' ) .makeOptionMandatory(false) .default('./README.md') ) .addOption( new Commander.Option( '-p, --package [name]', 'The name of the NPM package to use for Snyk vulnerability scanning (e.g. @4lch4/logger).' ).makeOptionMandatory(false) ) .addOption( new Commander.Option( '-b, --branch [name]', 'The name of the branch to use.' ).makeOptionMandatory(false) ) .addOption( new Commander.Option( '-o, --org-id [id]', 'The Snyk organization ID containing the project..' ) ) .addOption( new Commander.Option('-P, --project-id [id]', 'The Snyk project ID.') ) .action(async (owner, repo) => { const opts = Commander.program.opts() const input = { owner, repo, packageName: opts.package, branch: opts.branch, snykOrgId: opts.orgId, snykProjectId: opts.projectId } const fileContent = await fs.readFile(opts.readme, 'utf8') const headerText = getBadgeHeader(input) const footerText = getBadgeFooter(input) const newContent = `${headerText}\n\n${fileContent}\n\n${footerText.join('\n')}\n` await fs.writeFile(opts.readme, newContent) logger.info(`Wrote new content to ${opts.readme}`) }) Commander.program.parse()