Skip to content

Commit

Permalink
remove unnecessary feature
Browse files Browse the repository at this point in the history
  • Loading branch information
HBobertz committed Dec 26, 2024
1 parent 7fee2ff commit 39b52b6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 551 deletions.
4 changes: 1 addition & 3 deletions bin/cdk-assets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as yargs from 'yargs';
import { list } from './list';
import { setGlobalProgressListener, setLogThreshold, VERSION, DefaultProgressListener } from './logging';
import { setLogThreshold, VERSION } from './logging';
import { publish } from './publish';
import { AssetManifest } from '../lib';

async function main() {
const defaultListener = new DefaultProgressListener();
setGlobalProgressListener(defaultListener);

const argv = yargs
.usage('$0 <cmd> [args]')
Expand Down
55 changes: 2 additions & 53 deletions bin/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,9 @@ export const VERSION = JSON.parse(
fs.readFileSync(path.join(__dirname, '..', 'package.json'), { encoding: 'utf-8' })
).version;

export class DefaultProgressListener implements IPublishProgressListener {
public onPublishEvent(type: EventType, event: IPublishProgress): void {
switch (type) {
case EventType.FAIL:
console.error(`error : ${event.message}`);
break;
case EventType.DEBUG:
console.error(`verbose: ${event.message}`);
break;
default:
console.error(`info : ${event.message}`);
}
}
}

export type LogLevel = 'verbose' | 'info' | 'error';
let logThreshold: LogLevel = 'info';

// Global default progress listener that will be set if using the cli
// If using the library, you should set your own listener
let globalProgressListener: IPublishProgressListener | undefined;

export const LOG_LEVELS: Record<LogLevel, number> = {
verbose: 1,
info: 2,
Expand All @@ -38,35 +19,9 @@ export function setLogThreshold(threshold: LogLevel) {
logThreshold = threshold;
}

export function setGlobalProgressListener(listener: IPublishProgressListener) {
globalProgressListener = listener;
}

// Convert log level to event type
function logLevelToEventType(level: LogLevel): EventType {
switch (level) {
case 'error':
return EventType.FAIL;
default:
return EventType.DEBUG;
}
}

export function log(level: LogLevel, message: string, percentComplete?: number) {
export function log(level: LogLevel, message: string ) {
// should be entirely irrelevant but just to verify that the globalProgressListener is set
if (!globalProgressListener) {
setGlobalProgressListener(new DefaultProgressListener());
}

if (LOG_LEVELS[level] >= LOG_LEVELS[logThreshold]) {
const progressEvent: IPublishProgress = {
message: `${message}`,
percentComplete: percentComplete,
abort: () => {},
};

globalProgressListener!.onPublishEvent(logLevelToEventType(level), progressEvent);
}
console.error(`${level.padEnd(7, ' ')}: ${message}`);
}

export class ShellOutputHandler {
Expand All @@ -75,12 +30,6 @@ export class ShellOutputHandler {
public handleOutput(chunk: any, isError: boolean = false) {
const text = chunk.toString();

if (isError) {
process.stderr.write(text);
} else {
process.stdout.write(text);
}

// Send to progress listener if configured
if (this.progressListener && text.length > 0) {
const progressEvent: IPublishProgress = {
Expand Down
2 changes: 1 addition & 1 deletion lib/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface IPublishProgress {
/**
* How far along are we?
*/
readonly percentComplete?: number;
readonly percentComplete: number;

/**
* Abort the current publishing operation
Expand Down
Loading

0 comments on commit 39b52b6

Please sign in to comment.