Skip to content

Commit

Permalink
feat(cli): provide silent flag support
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Aug 10, 2020
1 parent 53af728 commit 2a646bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ success Already up-to-date.
| Flag | Description | Default |
|---|---|---|
|`--verbose` | Switch log level to verbose/debug | false |
|`--silent` | Disable log output | false |
|`--loglevel` | Set custom [log level](https://docs.npmjs.com/misc/config#shorthands-and-other-cli-niceties)
|`--only` | Set package [updating scope](https://docs.npmjs.com/cli/audit): `dev`/`prod`
|`--force` | Have audit fix install semver-major updates to toplevel dependencies, not just semver-compatible ones | false
Expand Down
8 changes: 4 additions & 4 deletions src/main/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const yarnLockToPkgLock: TCallback = ({temp}) => {
const npmAuditFix: TCallback = ({temp, flags}) =>
invoke('npm', [
'audit', 'fix', '--package-lock-only',
...formatFlags(flags, 'verbose', 'loglevel', 'only', 'force', 'audit-level'),
...formatFlags(flags, 'verbose', 'loglevel', 'only', 'force', 'audit-level', 'silent'),
], temp)

/**
Expand All @@ -64,7 +64,7 @@ const npmAuditFix: TCallback = ({temp, flags}) =>
* @return {void}
*/
const yarnImport: TCallback = ({temp, flags}) => {
invoke('yarn', ['import', ...formatFlags(flags, 'verbose')], temp)
invoke('yarn', ['import', ...formatFlags(flags, 'verbose', 'silent')], temp)
fs.copyFileSync(join(temp, 'yarn.lock'), 'yarn.lock')
}

Expand All @@ -74,7 +74,7 @@ const yarnImport: TCallback = ({temp, flags}) => {
* @return {void}
*/
const yarnInstall: TCallback = ({cwd, flags}) =>
invoke('yarn', [...formatFlags(flags, 'verbose')], cwd)
invoke('yarn', [...formatFlags(flags, 'verbose', 'silent')], cwd)

/**
* Clean up temporaries.
Expand Down Expand Up @@ -121,7 +121,7 @@ export const run = async(flags: Record<string, any> = {}) => {
}

for (const [description, ...steps] of stages) {
console.log(chalk.bold(description))
!flags.silent && console.log(chalk.bold(description))

for (const step of steps) step(ctx)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import chalk from 'chalk'
import {FsSymlinkType} from 'fs-extra'
import minimist from 'minimist'

export const invoke = (cmd: string, args: string[], cwd: string) => {
console.log(chalk.bold('invoke'), cmd, ...args)
export const invoke = (cmd: string, args: string[], cwd: string, silent= false) => {
!silent && console.log(chalk.bold('invoke'), cmd, ...args)

const result = cp.spawnSync(cmd, args, {cwd, stdio: ['inherit', 'inherit', 'inherit']})

Expand Down

0 comments on commit 2a646bc

Please sign in to comment.