0.2.1 • Published 2 years ago

commander-github-actions v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

commander-github-actions

License Build Status NPM Package Code Coverage semantic-release

Parse and generate GitHub Actions with commander

Install

npm install commander-github-actions

commander-github-actions/dev is used to generate actions.yml. Given the development nature, dependencies are optional:

npm install yaml lodash --save-dev

Use

program.js:

export function buildCommand(command = new Command()) {
  return command.option(...).addOption(command.createOption(...));
}

cli.js (executable):

import { buildCommand } from './program.js';
const options = buildCommand().parse();

action.js (GitHub action entrypoint):

import { Command } from 'commander-github-actions';
import { buildCommand } from './program.js';

const options = buildCommand(new Command()).parse();

drop in replacements for commander are provided:

import { createCommand, createOption, Command, Option, program } from "commander-github-actions";

Generate action.yml

dev/generate-action-yml.yml

#!/usr/bin/env node
import { writeFile } from 'fs/promises';

import { generateActionsYml } from 'commander-github-actions/dev';
import program from '../action/program.js';

await writeFile('action.yml', (await generateActionsYml(program, { runs: { main: 'action/main.js' } })));

Related

https://github.com/tj/commander.js/issues/1787