Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type ENV = Remap<
SOCKET_CLI_NO_API_TOKEN: boolean
SOCKET_CLI_PUBLISHED_BUILD: boolean
SOCKET_CLI_SENTRY_BUILD: boolean
SOCKET_CLI_SHOW_BANNER: boolean
SOCKET_CLI_VERSION_HASH: string
}>
>
Expand Down Expand Up @@ -109,7 +108,6 @@ type Constants = Remap<
readonly SOCKET_CLI_SENTRY_NPM_BIN_NAME: 'socket-npm-with-sentry'
readonly SOCKET_CLI_SENTRY_NPX_BIN_NAME: 'socket-npx-with-sentry'
readonly SOCKET_CLI_SENTRY_PACKAGE_NAME: '@socketsecurity/cli-with-sentry'
readonly SOCKET_CLI_SHOW_BANNER: 'SOCKET_CLI_SHOW_BANNER'
readonly SOCKET_CLI_VERSION_HASH: 'SOCKET_CLI_VERSION_HASH'
readonly VLT: 'vlt'
readonly WITH_SENTRY: 'with-sentry'
Expand Down Expand Up @@ -179,7 +177,6 @@ const SOCKET_CLI_SENTRY_BUILD = 'SOCKET_CLI_SENTRY_BUILD'
const SOCKET_CLI_SENTRY_NPM_BIN_NAME = `${SOCKET_CLI_NPM_BIN_NAME}-${WITH_SENTRY}`
const SOCKET_CLI_SENTRY_NPX_BIN_NAME = `${SOCKET_CLI_NPX_BIN_NAME}-${WITH_SENTRY}`
const SOCKET_CLI_SENTRY_PACKAGE_NAME = `${SOCKET_CLI_LEGACY_PACKAGE_NAME}-${WITH_SENTRY}`
const SOCKET_CLI_SHOW_BANNER = 'SOCKET_CLI_SHOW_BANNER'
const SOCKET_CLI_VERSION_HASH = 'SOCKET_CLI_VERSION_HASH'
const VLT = 'vlt'
const YARN = 'yarn'
Expand Down Expand Up @@ -218,8 +215,6 @@ const LAZY_ENV = () => {
// Inlined flag set to determine if this is the Sentry build.
// The '@rollup/plugin-replace' will replace "process.env[SOCKET_CLI_SENTRY_BUILD]".
[SOCKET_CLI_SENTRY_BUILD]: process.env[SOCKET_CLI_SENTRY_BUILD],
// Flag set to toggle the informative ASCII art banner.
[SOCKET_CLI_SHOW_BANNER]: envAsBoolean(env[SOCKET_CLI_SHOW_BANNER]),
// Inlined flag set to determine the version hash of the build.
// The '@rollup/plugin-replace' will replace "process.env[SOCKET_CLI_VERSION_HASH]".
[SOCKET_CLI_VERSION_HASH]: process.env[SOCKET_CLI_VERSION_HASH]
Expand Down Expand Up @@ -331,7 +326,6 @@ const constants = <Constants>createConstantsObject(
SOCKET_CLI_SENTRY_NPM_BIN_NAME,
SOCKET_CLI_SENTRY_NPX_BIN_NAME,
SOCKET_CLI_SENTRY_PACKAGE_NAME,
SOCKET_CLI_SHOW_BANNER,
SOCKET_CLI_VERSION_HASH,
VLT,
WITH_SENTRY,
Expand Down
30 changes: 18 additions & 12 deletions src/utils/meow-with-subcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MeowFlags, commonFlags } from '../flags'

import type { Options } from 'meow'

const { DRY_RUN_LABEL, REDACTED, SOCKET_CLI_SHOW_BANNER } = constants
const { DRY_RUN_LABEL, REDACTED } = constants

interface CliAlias {
description: string
Expand Down Expand Up @@ -93,11 +93,8 @@ export async function meowWithSubcommands(
}
// ...else we provide basic instructions and help.

// Temp disable until we clear the --json and --markdown usage
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
logger.log(getAsciiHeader(name))
}
emitBanner(name)

const cli = meow(
`
Usage
Expand Down Expand Up @@ -167,11 +164,8 @@ export function meowOrExit({
}) {
const command = `${parentName} ${config.commandName}`
lastSeenCommand = command
// Temp disable until we clear the --json and --markdown usage.
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
logger.log(getAsciiHeader(command))
}

emitBanner(command)

// This exits if .printHelp() is called either by meow itself or by us.
const cli = meow({
Expand All @@ -189,6 +183,18 @@ export function meowOrExit({
return cli
}

export function emitBanner(name: string) {
// Print a banner at the top of each command.
// This helps with brand recognition and marketing.
// It also helps with debugging since it contains version and command details.
// Note: print over stderr to preserve stdout for flags like --json and
// --markdown. If we don't do this, you can't use --json in particular
// and pipe the result to other tools. By emiting the banner over stderr
// you can do something like `socket scan view xyz | jq | process`.
// The spinner also emits over stderr for example.
logger.error(getAsciiHeader(name))
}

function getAsciiHeader(command: string) {
// Note: In tests we return <redacted> because otherwise snapshots will fail.
// The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
Expand All @@ -208,7 +214,7 @@ function getAsciiHeader(command: string) {
? REDACTED
: process
.cwd()
.replace(new RegExp(`^${escapeRegExp(constants.homePath)}`, 'i'), '~/')
.replace(new RegExp(`^${escapeRegExp(constants.homePath)}`, 'i'), '~')
const body = `
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${cliVersion}
Expand Down
Loading