amplify-prompts
Advanced tools
Comparing version 2.3.0-pretty-print.1 to 2.3.0-rc.aaf221035.0
@@ -6,3 +6,3 @@ # Change Log | ||
# [2.3.0-pretty-print.1](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@2.2.0...amplify-prompts@2.3.0-pretty-print.1) (2022-08-06) | ||
# [2.3.0-rc.aaf221035.0](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@2.2.0...amplify-prompts@2.3.0-rc.aaf221035.0) (2022-08-15) | ||
@@ -12,8 +12,3 @@ | ||
* addressing api review suggestions ([bf2206f](https://github.com/aws-amplify/amplify-cli/commit/bf2206f5dc898e5523893d9717aabdfcb7f9b126)) | ||
* addressing review comments ([b18971b](https://github.com/aws-amplify/amplify-cli/commit/b18971b061f0e05b690f693e1478b5e466517c3e)) | ||
* fixing test failures ([5d8c24f](https://github.com/aws-amplify/amplify-cli/commit/5d8c24f9df3e87b656ba8e560dddad5289c5622a)) | ||
* introducing spinner while fetching bucket ([77e21ef](https://github.com/aws-amplify/amplify-cli/commit/77e21ef16f30a195cba7f447dde4d4dbde9a0121)) | ||
* pretty-print push cfn logs ([d5a66e4](https://github.com/aws-amplify/amplify-cli/commit/d5a66e44500d2ea48fff5d4b0638da317f859466)) | ||
* updating multibar tests ([71c7916](https://github.com/aws-amplify/amplify-cli/commit/71c79160544382250d69ed28f63940cd33d42ed5)) | ||
* pretty print cloudformation event logs ([#10720](https://github.com/aws-amplify/amplify-cli/issues/10720)) ([aaf2210](https://github.com/aws-amplify/amplify-cli/commit/aaf22103548a329b3092f52736c28c9b5c5b8b8b)) | ||
@@ -24,18 +19,2 @@ | ||
# [2.3.0-pretty-print.0](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@2.2.0...amplify-prompts@2.3.0-pretty-print.0) (2022-08-06) | ||
### Features | ||
* addressing api review suggestions ([bf2206f](https://github.com/aws-amplify/amplify-cli/commit/bf2206f5dc898e5523893d9717aabdfcb7f9b126)) | ||
* addressing review comments ([b18971b](https://github.com/aws-amplify/amplify-cli/commit/b18971b061f0e05b690f693e1478b5e466517c3e)) | ||
* fixing test failures ([5d8c24f](https://github.com/aws-amplify/amplify-cli/commit/5d8c24f9df3e87b656ba8e560dddad5289c5622a)) | ||
* introducing spinner while fetching bucket ([77e21ef](https://github.com/aws-amplify/amplify-cli/commit/77e21ef16f30a195cba7f447dde4d4dbde9a0121)) | ||
* pretty-print push cfn logs ([d5a66e4](https://github.com/aws-amplify/amplify-cli/commit/d5a66e44500d2ea48fff5d4b0638da317f859466)) | ||
* updating multibar tests ([71c7916](https://github.com/aws-amplify/amplify-cli/commit/71c79160544382250d69ed28f63940cd33d42ed5)) | ||
# [2.2.0](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@2.1.0...amplify-prompts@2.2.0) (2022-06-03) | ||
@@ -42,0 +21,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { StringObj } from './terminal'; | ||
import { ProgressBar as Bar, BarOptions, ItemPayload, ProgressPayload } from './progressbar'; | ||
@@ -17,4 +18,4 @@ export declare class MultiProgressBar { | ||
constructor(options: BarOptions); | ||
private isTTY; | ||
writeLines(prefixText: string): void; | ||
isTTY(): boolean; | ||
writeLines(prefixText: StringObj): void; | ||
render(): void; | ||
@@ -21,0 +22,0 @@ getBar(name: string): { |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MultiProgressBar = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const terminal_1 = require("./terminal"); | ||
@@ -34,3 +30,3 @@ const progressbar_1 = require("./progressbar"); | ||
let stringsToRender = []; | ||
if (prefixText.length) { | ||
if (Object.keys(prefixText).length !== 0) { | ||
stringsToRender.push(prefixText); | ||
@@ -49,3 +45,3 @@ } | ||
render() { | ||
let initLine = ''; | ||
let initLine = {}; | ||
if (this.timer) { | ||
@@ -55,3 +51,6 @@ clearTimeout(this.timer); | ||
if (this.prefixText.length) { | ||
initLine = `${this.prefixText} ${this.frames[this.frameCount]}`; | ||
initLine = { | ||
renderString: `${this.prefixText} ${this.frames[this.frameCount]}`, | ||
color: '', | ||
}; | ||
} | ||
@@ -142,6 +141,12 @@ this.writeLines(initLine); | ||
clearTimeout(this.timer); | ||
let initLine = chalk_1.default.green(this.options.successText || ''); | ||
let initLine = { | ||
renderString: this.options.successText || '', | ||
color: 'green', | ||
}; | ||
for (const { bar } of this.bars) { | ||
if (bar.isFailed()) { | ||
initLine = chalk_1.default.red(this.options.failureText || ''); | ||
initLine = { | ||
renderString: this.options.failureText || '', | ||
color: 'red', | ||
}; | ||
break; | ||
@@ -148,0 +153,0 @@ } |
@@ -0,4 +1,8 @@ | ||
import { StringObj } from './terminal'; | ||
export declare type BarOptions = { | ||
progressBarFormatter: (payload: ProgressPayload, value: number, total: number) => string; | ||
itemFormatter: (payload: ItemPayload) => string; | ||
itemFormatter: (payload: ItemPayload) => { | ||
renderString: string; | ||
color: string; | ||
}; | ||
loneWolf: boolean; | ||
@@ -29,2 +33,3 @@ hideCursor: boolean; | ||
renderString: string; | ||
color: string; | ||
finished: boolean; | ||
@@ -46,3 +51,3 @@ }; | ||
createBarString(): string; | ||
getRenderStrings(): string[]; | ||
getRenderStrings(): StringObj[]; | ||
getValue(): number; | ||
@@ -49,0 +54,0 @@ render(): void; |
@@ -29,4 +29,10 @@ "use strict"; | ||
const progressBar = this.options.progressBarFormatter.call(this, this.payload, this.value, this.total) + this.createBarString(); | ||
finalStrings.push(progressBar); | ||
finalStrings = this.items.reduce((prev, _current) => prev.concat(`\t${_current.renderString}`), finalStrings); | ||
finalStrings.push({ | ||
renderString: progressBar, | ||
color: '', | ||
}); | ||
finalStrings = this.items.reduce((prev, _current) => prev.concat({ | ||
renderString: `\t${_current.renderString}`, | ||
color: `${_current.color}`, | ||
}), finalStrings); | ||
return finalStrings; | ||
@@ -75,3 +81,2 @@ } | ||
addItem(name, itemPayload) { | ||
const renderString = this.options.itemFormatter.call(this, itemPayload); | ||
const status = itemPayload.ResourceStatus; | ||
@@ -81,3 +86,3 @@ this.items.push({ | ||
status, | ||
renderString, | ||
...this.options.itemFormatter.call(this, itemPayload), | ||
finished: this.options.itemCompleteStatus.includes(status), | ||
@@ -97,3 +102,3 @@ }); | ||
finished: item.finished || this.options.itemCompleteStatus.includes(newPayload.ResourceStatus), | ||
renderString: this.options.itemFormatter.call(this, newPayload), | ||
...this.options.itemFormatter.call(this, newPayload), | ||
}; | ||
@@ -100,0 +105,0 @@ } |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AmplifySpinner = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const terminal_1 = require("./terminal"); | ||
@@ -21,3 +17,6 @@ class AmplifySpinner { | ||
} | ||
const lines = [`${chalk_1.default.blue(this.frames[this.frameCount])} ${this.prefixText}`]; | ||
const lines = [{ | ||
renderString: `${this.frames[this.frameCount]} ${this.prefixText}`, | ||
color: '', | ||
}]; | ||
this.frameCount = ++this.frameCount % this.frames.length; | ||
@@ -33,8 +32,10 @@ this.terminal.writeLines(lines); | ||
stop(text, success = true) { | ||
let lines = []; | ||
clearTimeout(this.timer); | ||
if (text) { | ||
lines = success ? [chalk_1.default.green(text)] : [chalk_1.default.red(text)]; | ||
const lines = [{ | ||
renderString: text, | ||
color: success ? 'green' : 'red', | ||
}]; | ||
clearTimeout(this.timer); | ||
this.terminal.writeLines(lines); | ||
} | ||
this.terminal.writeLines(lines); | ||
} | ||
@@ -41,0 +42,0 @@ } |
@@ -0,1 +1,5 @@ | ||
export declare type StringObj = { | ||
renderString: string; | ||
color: string; | ||
}; | ||
export declare class AmplifyTerminal { | ||
@@ -10,3 +14,3 @@ private lastHeight; | ||
private get height(); | ||
writeLines(lines: string[]): void; | ||
writeLines(lines: StringObj[]): void; | ||
cursor(enabled: boolean): void; | ||
@@ -13,0 +17,0 @@ newLine(): void; |
@@ -8,3 +8,5 @@ "use strict"; | ||
const os_1 = __importDefault(require("os")); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const ESC = '\u001b'; | ||
const BUFFER_LENGTH = 10; | ||
const cursorUp = (n) => { | ||
@@ -17,2 +19,8 @@ const dy = typeof n === 'number' ? n : 1; | ||
const HIDE_CURSOR = '\x1b[?25l'; | ||
const getColoredLine = (line, color) => { | ||
if (color) { | ||
return chalk_1.default.keyword(color)(line); | ||
} | ||
return line; | ||
}; | ||
class AmplifyTerminal { | ||
@@ -37,7 +45,8 @@ constructor() { | ||
writeLines(lines) { | ||
const newLines = lines.flatMap(line => line.split(os_1.default.EOL)); | ||
this.stream.write(cursorUp(this.lastHeight)); | ||
newLines.forEach(line => { | ||
const truncatedLine = line.substring(0, Math.min(line.length, this.width - 2)); | ||
this.stream.write(`${clearLine()}${truncatedLine}${os_1.default.EOL}`); | ||
lines.forEach(line => { | ||
const { renderString, color } = line; | ||
const truncatedLine = renderString.substring(0, Math.min(renderString.length, this.width - BUFFER_LENGTH)); | ||
const writtenLine = getColoredLine(truncatedLine, color); | ||
this.stream.write(`${clearLine()}${writtenLine}${os_1.default.EOL}`); | ||
}); | ||
@@ -44,0 +53,0 @@ this.trailingEmptyLines = Math.max(0, this.lastHeight - lines.length); |
{ | ||
"name": "amplify-prompts", | ||
"version": "2.3.0-pretty-print.1", | ||
"version": "2.3.0-rc.aaf221035.0", | ||
"description": "Utility functions for Amplify CLI terminal I/O", | ||
@@ -52,3 +52,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "3f9dafdbee9c9106d87962b9175e8f43ade2d254" | ||
"gitHead": "7ad7ec576c43a0e7ea4619a1dbeb6dde8b37d984" | ||
} |
@@ -12,3 +12,3 @@ /* eslint-disable jest/no-conditional-expect */ | ||
progressBarFormatter: (payload : ProgressPayload) => payload.progressName, | ||
itemFormatter: (payload : ItemPayload) => payload.ResourceStatus, | ||
itemFormatter: (payload : ItemPayload) => ({ renderString: payload.ResourceStatus, color: '' }), | ||
loneWolf: false, | ||
@@ -15,0 +15,0 @@ hideCursor: true, |
@@ -7,3 +7,3 @@ /* eslint-disable jest/no-conditional-expect */ | ||
progressBarFormatter: payload => payload.progressName, | ||
itemFormatter: payload => payload.ResourceStatus, | ||
itemFormatter: payload => ({ renderString: payload.ResourceStatus, color: '' }), | ||
loneWolf: false, | ||
@@ -10,0 +10,0 @@ hideCursor: true, |
@@ -9,3 +9,6 @@ import { AmplifyTerminal as Terminal } from '../progressbars/terminal'; | ||
}); | ||
const stringsToRender = ['Hello World', 'How are you']; | ||
const stringsToRender = [ | ||
{ renderString: 'Hello World', color: '' }, | ||
{ renderString: 'How are you', color: '' }, | ||
]; | ||
terminal.writeLines(stringsToRender); | ||
@@ -12,0 +15,0 @@ expect(streamWriteMock).toBeCalledTimes(3); |
@@ -5,4 +5,3 @@ /** | ||
*/ | ||
import chalk from 'chalk'; | ||
import { AmplifyTerminal as Terminal } from './terminal'; | ||
import { AmplifyTerminal as Terminal, StringObj } from './terminal'; | ||
import { | ||
@@ -31,3 +30,3 @@ ProgressBar as Bar, | ||
private updated: boolean; | ||
private lastDrawnStrings : string[]; | ||
private lastDrawnStrings : StringObj[]; | ||
@@ -62,3 +61,3 @@ constructor(options : BarOptions) { | ||
*/ | ||
private isTTY() : boolean { | ||
isTTY() : boolean { | ||
return this.terminal.isTTY(); | ||
@@ -70,6 +69,6 @@ } | ||
*/ | ||
writeLines(prefixText: string) : void { | ||
let barStrings : string[] = []; | ||
let stringsToRender : string[] = []; | ||
if (prefixText.length) { | ||
writeLines(prefixText: StringObj) : void { | ||
let barStrings : StringObj[] = []; | ||
let stringsToRender : StringObj[] = []; | ||
if (Object.keys(prefixText).length !== 0) { | ||
stringsToRender.push(prefixText); | ||
@@ -93,3 +92,3 @@ } | ||
render() : void { | ||
let initLine = ''; | ||
let initLine = {} as StringObj; | ||
if (this.timer) { | ||
@@ -100,3 +99,6 @@ clearTimeout(this.timer); | ||
if (this.prefixText.length) { | ||
initLine = `${this.prefixText} ${this.frames[this.frameCount]}`; | ||
initLine = { | ||
renderString: `${this.prefixText} ${this.frames[this.frameCount]}`, | ||
color: '', | ||
}; | ||
} | ||
@@ -231,6 +233,12 @@ this.writeLines(initLine); | ||
// Change prefix text according to success/failure | ||
let initLine : string = chalk.green(this.options.successText || ''); | ||
let initLine : StringObj = { | ||
renderString: this.options.successText || '', | ||
color: 'green', | ||
}; | ||
for (const { bar } of this.bars) { | ||
if (bar.isFailed()) { | ||
initLine = chalk.red(this.options.failureText || ''); | ||
initLine = { | ||
renderString: this.options.failureText || '', | ||
color: 'red', | ||
}; | ||
break; | ||
@@ -237,0 +245,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { AmplifyTerminal as Terminal } from './terminal'; | ||
import { AmplifyTerminal as Terminal, StringObj } from './terminal'; | ||
@@ -9,3 +9,3 @@ /** | ||
progressBarFormatter: (payload: ProgressPayload, value: number, total: number) => string, | ||
itemFormatter: (payload: ItemPayload) => string, | ||
itemFormatter: (payload: ItemPayload) => { renderString: string, color: string }, | ||
// Indicates if the progress bar is part of a multiBar or standalone | ||
@@ -49,2 +49,3 @@ loneWolf: boolean, | ||
renderString: string, | ||
color: string, | ||
finished: boolean | ||
@@ -103,7 +104,13 @@ } | ||
*/ | ||
getRenderStrings() : string[] { | ||
let finalStrings = []; | ||
getRenderStrings() : StringObj[] { | ||
let finalStrings : StringObj[] = []; | ||
const progressBar = this.options.progressBarFormatter.call(this, this.payload, this.value, this.total) + this.createBarString(); | ||
finalStrings.push(progressBar); | ||
finalStrings = this.items.reduce((prev, _current) => prev.concat(`\t${_current.renderString}`), finalStrings); | ||
finalStrings.push({ | ||
renderString: progressBar, | ||
color: '', | ||
}); | ||
finalStrings = this.items.reduce((prev, _current) => prev.concat({ | ||
renderString: `\t${_current.renderString}`, | ||
color: `${_current.color}`, | ||
}), finalStrings); | ||
return finalStrings; | ||
@@ -191,3 +198,2 @@ } | ||
addItem(name: string, itemPayload: ItemPayload) : void { | ||
const renderString = this.options.itemFormatter.call(this, itemPayload); | ||
const status = itemPayload.ResourceStatus; | ||
@@ -197,3 +203,3 @@ this.items.push({ | ||
status, | ||
renderString, | ||
...this.options.itemFormatter.call(this, itemPayload), | ||
finished: this.options.itemCompleteStatus.includes(status), | ||
@@ -218,3 +224,3 @@ }); | ||
finished: item.finished || this.options.itemCompleteStatus.includes(newPayload.ResourceStatus), | ||
renderString: this.options.itemFormatter.call(this, newPayload), | ||
...this.options.itemFormatter.call(this, newPayload), | ||
}; | ||
@@ -221,0 +227,0 @@ } |
@@ -5,5 +5,5 @@ /** | ||
*/ | ||
import chalk from 'chalk'; | ||
import { AmplifyTerminal as Terminal } from './terminal'; | ||
import { AmplifyTerminal as Terminal, StringObj } from './terminal'; | ||
/** | ||
@@ -35,3 +35,6 @@ * Amplify spinner instance | ||
} | ||
const lines = [`${chalk.blue(this.frames[this.frameCount])} ${this.prefixText}`]; | ||
const lines = [{ | ||
renderString: `${this.frames[this.frameCount]} ${this.prefixText}`, | ||
color: '', | ||
}]; | ||
this.frameCount = ++this.frameCount % this.frames.length; | ||
@@ -55,9 +58,12 @@ this.terminal.writeLines(lines); | ||
stop(text : string | null, success = true) : void { | ||
let lines : string[] = []; | ||
clearTimeout(this.timer); | ||
if (text) { | ||
lines = success ? [chalk.green(text)] : [chalk.red(text)]; | ||
const lines : StringObj[] = [{ | ||
renderString: text, | ||
color: success ? 'green' : 'red', | ||
}]; | ||
clearTimeout(this.timer); | ||
this.terminal.writeLines(lines); | ||
} | ||
this.terminal.writeLines(lines); | ||
} | ||
} |
import os from 'os'; | ||
import chalk from 'chalk'; | ||
/** | ||
* String obj passed to terminal | ||
*/ | ||
export type StringObj = { | ||
renderString: string, | ||
color: string | ||
} | ||
const ESC = '\u001b'; | ||
const BUFFER_LENGTH = 10; | ||
@@ -14,2 +24,9 @@ const cursorUp = (n : number) : string => { | ||
const getColoredLine = (line: string, color: string) : string => { | ||
if (color) { | ||
return chalk.keyword(color)(line); | ||
} | ||
return line; | ||
}; | ||
/** | ||
@@ -60,14 +77,12 @@ * Amplify Terminal instance (Re writable block) | ||
*/ | ||
public writeLines(lines : string[]) : void { | ||
// Removing /n's since we are accounting for number of lines printed. | ||
// This is done to retain cursor positions. | ||
const newLines = lines.flatMap(line => line.split(os.EOL)); | ||
public writeLines(lines : StringObj[]) : void { | ||
// Go back to beginning of last written block | ||
this.stream.write(cursorUp(this.lastHeight)); | ||
newLines.forEach(line => { | ||
lines.forEach(line => { | ||
// Truncating to width-2 of terminal | ||
const truncatedLine = line.substring(0, Math.min(line.length, this.width - 2)); | ||
this.stream.write(`${clearLine()}${truncatedLine}${os.EOL}`); | ||
const { renderString, color } = line; | ||
const truncatedLine = renderString.substring(0, Math.min(renderString.length, this.width - BUFFER_LENGTH)); | ||
const writtenLine = getColoredLine(truncatedLine, color); | ||
this.stream.write(`${clearLine()}${writtenLine}${os.EOL}`); | ||
}); | ||
@@ -74,0 +89,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
246143
3053