Skip to content

Commit

Permalink
feat: print version via -v and --version flags
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 14, 2022
1 parent b2c4b0b commit fc2fe73
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main/ts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const flags = new Command()
'Switch log level to verbose/debug',
env.YAF_VERBOSE,
)
.option(
'--version, -v',
'Print current yarn-audit-fix version'
)
.allowUnknownOption()
.parse(process.argv)
.opts()
Expand Down
7 changes: 6 additions & 1 deletion src/main/ts/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'node:path'

import { getFlow } from './flows'
import { TContext, TFlags, TFlow, TStage } from './ifaces'
import { getTemp, normalizeFlags, readJson } from './util'
import { getSelfManifest, getTemp, normalizeFlags, readJson } from './util'

/**
* Build running context.
Expand Down Expand Up @@ -44,6 +44,11 @@ export const exec = (stages: TStage, ctx: TContext): void => {
* Public static void main.
*/
export const runSync = (_flags: TFlags = {}, _flow?: TFlow): void => {
if (_flags.V) {
console.log(getSelfManifest().version)
return
}

const flags = normalizeFlags(_flags)
const ctx = getContext(flags)
const flow = _flow || getFlow(flags.flow)
Expand Down
9 changes: 2 additions & 7 deletions src/main/ts/stages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs-extra'
import { dirname, join, relative } from 'node:path'
import { fileURLToPath } from 'node:url'
import semver from 'semver'
import synp from 'synp'

Expand All @@ -11,23 +10,19 @@ import {
formatFlags,
getBinVersion,
getNpm,
getSelfManifest,
getSymlinkType,
getWorkspaces,
getYarn,
invoke,
pkgDir,
readJson,
} from './util'

const __dirname = dirname(fileURLToPath(import.meta.url))

/**
* Resolve bins.
*/
export const resolveBins: TCallback = ({ ctx, temp, flags }) => {
const yafManifest = readJson(
join(pkgDir(__dirname) + '', 'package.json'), // eslint-disable-line
)
const yafManifest = getSelfManifest()
ctx.bins = {
yarn: getYarn(),
npm: getNpm(flags['npm-path']),
Expand Down
4 changes: 4 additions & 0 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,7 @@ export const formatYaml = yaml.dump

export const getBinVersion = (bin: string, cwd = process.cwd()): string =>
invoke(bin, ['--version'], cwd, true, false)

export const getSelfManifest = () => readJson(
join(pkgDir(__dirname) + '', 'package.json'), // eslint-disable-line
)

0 comments on commit fc2fe73

Please sign in to comment.