Skip to content

Commit

Permalink
fix(cli): show subcommands and subcommand groups in build summary
Browse files Browse the repository at this point in the history
This code is a bit messy now and will need to be refactored...
  • Loading branch information
Pkmmte committed May 16, 2023
1 parent 3571f59 commit 99dbe81
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-bottles-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roboplay/robo.js': patch
---

fix(cli): show subcommands and subcommand groups in build summary
57 changes: 44 additions & 13 deletions packages/robo/src/cli/utils/build-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path'
import chalk from 'chalk'
import { logger } from '../../core/logger.js'
import { performance } from 'node:perf_hooks'
import { Manifest } from '../../types/index.js'
import { CommandEntry, Manifest } from '../../types/index.js'
import { packageJson } from './utils.js'

export async function getProjectSize(directory: string): Promise<number> {
Expand Down Expand Up @@ -34,29 +34,60 @@ export async function getProjectSize(directory: string): Promise<number> {

export function printBuildSummary(manifest: Manifest, totalSize: number, startTime: number, plugin: boolean) {
const maxLength = Math.min(Math.max(...Object.keys(manifest.commands).map((cmd) => cmd.length), 15), 30)
logger.log(chalk.bold(`\nType Name${' '.repeat(maxLength - 2)}Description`))
logger.log(`─`.repeat(maxLength + 30))
const maxTypeNameLength = Math.max(
...['Command', 'Subcommand', 'Subcommand Group', 'Event'].map((type) => type.length)
)

const headerType = 'Type'
const headerName = 'Name'
const headerDescription = 'Description'

// +4 to account for autoSymbol spacing, +1 for a space between type and name
const headerTypeSpacing = ' '.repeat(maxTypeNameLength - headerType.length + 4)
const headerNameSpacing = ' '.repeat(maxLength - headerName.length + 1)

logger.log(chalk.bold(`\n${headerType}${headerTypeSpacing}${headerName}${headerNameSpacing}${headerDescription}`))
logger.log(`─`.repeat(maxLength + maxTypeNameLength + headerDescription.length + 5))

let autoGeneratedExists = false
for (const [command, commandData] of Object.entries(manifest.commands)) {
const autoSymbol = commandData.__auto ? ' Δ ' : ' '
if (commandData.__auto) {
autoGeneratedExists = true

function logCommands(commands: Record<string, CommandEntry>, prefix = '', depth = 0) {
for (const [command, commandData] of Object.entries(commands)) {
if (commandData.subcommands) {
logCommands(commandData.subcommands, prefix ? `${prefix} ${command}` : command, depth + 1)
continue
}

const autoSymbol = commandData.__auto ? ' Δ ' : ' '
if (commandData.__auto) {
autoGeneratedExists = true
}
const fullPath = prefix ? `${prefix} ${command}` : command
let type = 'Command'
if (depth === 1) type = 'Subcommand'
if (depth >= 2) type = 'Subcommand Group'

const typeSpacing = ' '.repeat(maxTypeNameLength - type.length + 1)

logger.log(
chalk.bold.blue(type + typeSpacing + autoSymbol) +
`${chalk.bold(('/' + fullPath).padEnd(maxLength + 1))} ${commandData.description ?? ''}`
)
}
logger.log(
chalk.bold.blue('Command ' + autoSymbol) +
`${chalk.bold(('/' + command).padEnd(maxLength + 1))} ${commandData.description ?? ''}`
)
}
logCommands(manifest.commands)

for (const event of Object.keys(manifest.events)) {
const eventData = manifest.events[event]
const isAuto = eventData.every(e => e.__auto)
const isAuto = eventData.every((e) => e.__auto)
const autoSymbol = isAuto ? ' Δ ' : ' '
if (isAuto) {
autoGeneratedExists = true
}
logger.log(chalk.bold.magenta('Event ' + autoSymbol) + `${chalk.bold(event).padEnd(maxLength + 1)}`)

const type = 'Event'
const typeSpacing = ' '.repeat(maxTypeNameLength - type.length + 1)
logger.log(chalk.bold.magenta(type + typeSpacing + autoSymbol) + `${chalk.bold(event).padEnd(maxLength + 1)}`)
}

// Format sizing information
Expand Down

1 comment on commit 99dbe81

@vercel
Copy link

@vercel vercel bot commented on 99dbe81 May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.