Skip to content

Commit

Permalink
feat: expose current version in CLI with --version/-V
Browse files Browse the repository at this point in the history
  • Loading branch information
timrogers committed Jul 31, 2023
1 parent 974d02b commit 7636259
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dist/commands/benefits.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import Table from 'cli-table';
import { actionRunner } from '../utils.js';
import { getAccessToken } from '../config.js';
import { getBenefits } from '../forma.js';
import VERSION from '../version.js';
const command = new commander.Command();
command
.name('benefits')
.version(VERSION)
.description('List benefits in your Forma account and their remaining balances')
.option('--access-token <access_token>', 'Access token used to authenticate with Forma')
.action(actionRunner(async (opts) => {
Expand Down
2 changes: 2 additions & 0 deletions dist/commands/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import Table from 'cli-table';
import { actionRunner } from '../utils.js';
import { getAccessToken } from '../config.js';
import { getCategoriesForBenefitName } from '../forma.js';
import VERSION from '../version.js';
const command = new commander.Command();
command
.name('categories')
.version(VERSION)
.description('List categories available for a Forma benefit')
.requiredOption('--benefit <benefit>', 'The benefit to list categories for')
.option('--access-token <access_token>', 'Access token used to authenticate with Forma')
Expand Down
2 changes: 2 additions & 0 deletions dist/commands/generate-template-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import * as commander from 'commander';
import { existsSync, writeFileSync } from 'fs';
import chalk from 'chalk';
import { actionRunner } from '../utils.js';
import VERSION from '../version.js';
const command = new commander.Command();
const TEMPLATE_CSV = `benefit,category,merchant,amount,description,purchaseDate,receiptPath\n`;
command
.name('generate-template-csv')
.version(VERSION)
.description('Generate a template CSV for submitting multiple claims at the same time')
.option('--output-path <output_path>', 'The path to write the CSV to', 'claims.csv')
.action(actionRunner(async (opts) => {
Expand Down
2 changes: 2 additions & 0 deletions dist/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chalk from 'chalk';
import { actionRunner, prompt } from '../utils.js';
import { setAccessToken } from '../config.js';
import { exchangeIdAndTkForAccessToken, requestMagicLink } from '../forma.js';
import VERSION from '../version.js';
const command = new commander.Command();
const parseEmailedFormaMagicLink = (input) => {
const parsedUrl = new URL(input);
Expand Down Expand Up @@ -57,6 +58,7 @@ const promptForEmailedMagicLink = (email, errorMessage = null) => {
};
command
.name('login')
.version(VERSION)
.description('Connect Formanator to your Forma account with a magic link')
.option('--email <email>', 'Email address used to log in to Forma')
.action(actionRunner(async (opts) => {
Expand Down
2 changes: 2 additions & 0 deletions dist/commands/submit-claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { actionRunner, prompt } from '../utils.js';
import { getAccessToken } from '../config.js';
import { createClaim, getBenefitsWithCategories, } from '../forma.js';
import { claimParamsToCreateClaimOptions } from '../claims.js';
import VERSION from '../version.js';
const command = new commander.Command();
const generateOpenaiPrompt = (opts) => {
const { description, merchant, validCategories } = opts;
Expand Down Expand Up @@ -52,6 +53,7 @@ const attemptToinferCategoryAndBenefit = async (opts) => {
};
command
.name('submit-claim')
.version(VERSION)
.description('Submit a claim for a Forma benefit')
.option('--benefit <benefit>', 'The benefit you are claiming for. You may omit this if an OpenAI API key is configured')
.requiredOption('--amount <amount>', 'The amount of the claim')
Expand Down
2 changes: 2 additions & 0 deletions dist/commands/submit-claims-from-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { actionRunner, serializeError } from '../utils.js';
import { getAccessToken } from '../config.js';
import { createClaim } from '../forma.js';
import { claimParamsToCreateClaimOptions } from '../claims.js';
import VERSION from '../version.js';
const command = new commander.Command();
const EXPECTED_HEADERS = [
'category',
Expand Down Expand Up @@ -37,6 +38,7 @@ const readClaimsFromCsv = async (inputPath) => {
};
command
.name('submit-claims-from-csv')
.version(VERSION)
.description('Submit multiple Forms claims from a CSV. To generate a template CSV to fill in, use the `generate-template-csv` command.')
.requiredOption('--input-path <input_path>', 'The path to the CSV to read claims from')
.option('--access-token <access_token>', 'Access token used to authenticate with Forma')
Expand Down
2 changes: 2 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import categories from './commands/categories.js';
import submitClaim from './commands/submit-claim.js';
import generateTemplateCsv from './commands/generate-template-csv.js';
import submitClaimsFromCsv from './commands/submit-claims-from-csv.js';
import VERSION from './version.js';
const program = new commander.Command();
program
.version(VERSION)
.addCommand(login)
.addCommand(benefits)
.addCommand(categories)
Expand Down
2 changes: 2 additions & 0 deletions dist/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// WARNING: This file will be overwritten with the correct version during the package release process.
export default '0.0.0-development';
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"build": "npx tsc -p tsconfig.json",
"prepublish": "npm run build",
"prepack": "node script/generate-version-file.cjs > dist/version.js",
"lint": "eslint . --ext .ts",
"lint-and-fix": "eslint . --ext .ts --fix",
"semantic-release": "semantic-release",
Expand Down
3 changes: 3 additions & 0 deletions script/generate-version-file.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const PACKAGE_VERSION = require('../package.json').version;

console.log(`export default '${PACKAGE_VERSION}'`);
2 changes: 2 additions & 0 deletions src/commands/benefits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Table from 'cli-table';
import { actionRunner } from '../utils.js';
import { getAccessToken } from '../config.js';
import { getBenefits } from '../forma.js';
import VERSION from '../version.js';

const command = new commander.Command();

Expand All @@ -13,6 +14,7 @@ interface Arguments {

command
.name('benefits')
.version(VERSION)
.description('List benefits in your Forma account and their remaining balances')
.option('--access-token <access_token>', 'Access token used to authenticate with Forma')
.action(
Expand Down
2 changes: 2 additions & 0 deletions src/commands/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Table from 'cli-table';
import { actionRunner } from '../utils.js';
import { getAccessToken } from '../config.js';
import { getCategoriesForBenefitName } from '../forma.js';
import VERSION from '../version.js';

const command = new commander.Command();

Expand All @@ -14,6 +15,7 @@ interface Arguments {

command
.name('categories')
.version(VERSION)
.description('List categories available for a Forma benefit')
.requiredOption('--benefit <benefit>', 'The benefit to list categories for')
.option('--access-token <access_token>', 'Access token used to authenticate with Forma')
Expand Down
2 changes: 2 additions & 0 deletions src/commands/generate-template-csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync, writeFileSync } from 'fs';
import chalk from 'chalk';

import { actionRunner } from '../utils.js';
import VERSION from '../version.js';

const command = new commander.Command();

Expand All @@ -14,6 +15,7 @@ const TEMPLATE_CSV = `benefit,category,merchant,amount,description,purchaseDate,

command
.name('generate-template-csv')
.version(VERSION)
.description('Generate a template CSV for submitting multiple claims at the same time')
.option('--output-path <output_path>', 'The path to write the CSV to', 'claims.csv')
.action(
Expand Down
2 changes: 2 additions & 0 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chalk from 'chalk';
import { actionRunner, prompt } from '../utils.js';
import { setAccessToken } from '../config.js';
import { exchangeIdAndTkForAccessToken, requestMagicLink } from '../forma.js';
import VERSION from '../version.js';

const command = new commander.Command();

Expand Down Expand Up @@ -87,6 +88,7 @@ const promptForEmailedMagicLink = (

command
.name('login')
.version(VERSION)
.description('Connect Formanator to your Forma account with a magic link')
.option('--email <email>', 'Email address used to log in to Forma')
.action(
Expand Down
2 changes: 2 additions & 0 deletions src/commands/submit-claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getBenefitsWithCategories,
} from '../forma.js';
import { claimParamsToCreateClaimOptions } from '../claims.js';
import VERSION from '../version.js';

const command = new commander.Command();

Expand Down Expand Up @@ -114,6 +115,7 @@ const attemptToinferCategoryAndBenefit = async (opts: {

command
.name('submit-claim')
.version(VERSION)
.description('Submit a claim for a Forma benefit')
.option(
'--benefit <benefit>',
Expand Down
2 changes: 2 additions & 0 deletions src/commands/submit-claims-from-csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { actionRunner, serializeError } from '../utils.js';
import { getAccessToken } from '../config.js';
import { createClaim } from '../forma.js';
import { type Claim, claimParamsToCreateClaimOptions } from '../claims.js';
import VERSION from '../version.js';

const command = new commander.Command();

Expand Down Expand Up @@ -56,6 +57,7 @@ const readClaimsFromCsv = async (inputPath: string): Promise<Claim[]> => {

command
.name('submit-claims-from-csv')
.version(VERSION)
.description(
'Submit multiple Forms claims from a CSV. To generate a template CSV to fill in, use the `generate-template-csv` command.',
)
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import categories from './commands/categories.js';
import submitClaim from './commands/submit-claim.js';
import generateTemplateCsv from './commands/generate-template-csv.js';
import submitClaimsFromCsv from './commands/submit-claims-from-csv.js';
import VERSION from './version.js';

const program = new commander.Command();

program
.version(VERSION)
.addCommand(login)
.addCommand(benefits)
.addCommand(categories)
Expand Down
2 changes: 2 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// WARNING: This file will be overwritten with the correct version during the package release process.
export default '0.0.0-development';

0 comments on commit 7636259

Please sign in to comment.