Skip to content

Commit

Permalink
better comments and such
Browse files Browse the repository at this point in the history
  • Loading branch information
HBobertz committed Dec 8, 2024
1 parent 057644a commit 5bcdaad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 0 additions & 2 deletions bin/cdk-assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Modified bin/cdk-assets.ts
import * as yargs from 'yargs';
import { list } from './list';
import { log, setGlobalProgressListener, setLogThreshold, VERSION } from './logging';
Expand All @@ -7,7 +6,6 @@ import { AssetManifest, EventType, IPublishProgress, IPublishProgressListener }

class DefaultProgressListener implements IPublishProgressListener {
public onPublishEvent(type: EventType, event: IPublishProgress): void {
// Map event types to log levels
switch (type) {
case EventType.FAIL:
log('error', event.message);
Expand Down
9 changes: 3 additions & 6 deletions bin/logging.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Modified bin/logging.ts to integrate with progress interface
import * as fs from 'fs';
import * as path from 'path';
import { EventType, IPublishProgress, IPublishProgressListener } from '../lib/progress';
Expand All @@ -10,7 +9,7 @@ export const VERSION = JSON.parse(
export type LogLevel = 'verbose' | 'info' | 'error';
let logThreshold: LogLevel = 'info';

// Global progress listener that can be set
// Global progress listener that will eventually be set
let globalProgressListener: IPublishProgressListener | undefined;

export const LOG_LEVELS: Record<LogLevel, number> = {
Expand Down Expand Up @@ -41,10 +40,9 @@ function logLevelToEventType(level: LogLevel): EventType {

export function log(level: LogLevel, message: string, percentComplete?: number) {
if (LOG_LEVELS[level] >= LOG_LEVELS[logThreshold]) {
// Still write to stderr for backward compatibility
console.error(`${level.padEnd(7, ' ')}: ${message}`);

// Also send to progress listener if configured
// Write to progress listener if configured
if (globalProgressListener) {
const progressEvent: IPublishProgress = {
message: `${message}`,
Expand All @@ -62,14 +60,13 @@ export class ShellOutputHandler {
public handleOutput(chunk: any, isError: boolean = false) {
const text = chunk.toString();

// Write to standard streams for backward compatibility
if (isError) {
process.stderr.write(text);
} else {
process.stdout.write(text);
}

// Also send to progress listener if configured
// Send to progress listener if configured
if (this.progressListener) {
const progressEvent: IPublishProgress = {
message: text,
Expand Down
6 changes: 6 additions & 0 deletions lib/private/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export interface ShellOptions extends child_process.SpawnOptions {
readonly progressListener?: IPublishProgressListener;
}

/**
* OS helpers
*
* Shell function which both prints to stdout and collects the output into a
* string.
*/
export async function shell(command: string[], options: ShellOptions = {}): Promise<string> {
if (options.logger) {
options.logger(renderCommandLine(command));
Expand Down

0 comments on commit 5bcdaad

Please sign in to comment.