From e4525f79b549b66e25e6c01297ccc77cc6c85250 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 25 Aug 2020 17:36:12 -0700 Subject: [PATCH 1/2] feat(output): show elapsed time for tasks --- .../@ionic/cli-framework-output/src/output.ts | 29 ++++++++++--------- .../@ionic/cli-framework-output/src/tasks.ts | 26 +++++++++++++++-- .../@ionic/cli-framework-output/src/utils.ts | 15 ++++++++++ 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/packages/@ionic/cli-framework-output/src/output.ts b/packages/@ionic/cli-framework-output/src/output.ts index 9503eaeea0..e8ef8e651b 100644 --- a/packages/@ionic/cli-framework-output/src/output.ts +++ b/packages/@ionic/cli-framework-output/src/output.ts @@ -3,6 +3,7 @@ import { LogUpdate } from 'log-update'; import { Colors, NO_COLORS } from './colors'; import { ICON_FAILURE, ICON_SUCCESS, Spinner, TaskChain } from './tasks'; +import { formatHrTime } from './utils'; export interface OutputStrategy { readonly stream: NodeJS.WritableStream; @@ -29,16 +30,16 @@ export class StreamOutputStrategy implements OutputStrategy { } createTaskChain(): TaskChain { - const { failure, success } = this.colors; + const { failure, success, weak } = this.colors; const chain = new TaskChain(); chain.on('next', task => { - task.on('success', () => { - this.stream.write(`${success(ICON_SUCCESS)} ${task.msg} - done!`); - }); - - task.on('failure', () => { - this.stream.write(`${failure(ICON_FAILURE)} ${task.msg} - failed!`); + task.on('end', result => { + if (result.success) { + this.stream.write(`${success(ICON_SUCCESS)} ${task.msg} ${weak(`in ${formatHrTime(result.elapsedTime)}`)}`); + } else { + this.stream.write(`${failure(ICON_FAILURE)} ${task.msg} ${failure(weak('- failed!'))}`); + } }); }); @@ -68,16 +69,16 @@ export class LogUpdateOutputStrategy implements OutputStrategy, RedrawLine { } createTaskChain(): TaskChain { - const { failure, strong, success } = this.colors; + const { failure, strong, success, weak } = this.colors; const chain = new TaskChain({ taskOptions: { tickInterval: 50 } }); chain.on('next', task => { - task.on('success', () => { - this.stream.write(`${success(ICON_SUCCESS)} ${task.msg} - done!\n`); - }); - - task.on('failure', () => { - this.stream.write(`${failure(ICON_FAILURE)} ${task.msg} - failed!\n`); + task.on('end', result => { + if (result.success) { + this.stream.write(`${success(ICON_SUCCESS)} ${task.msg} ${weak(`in ${formatHrTime(result.elapsedTime)}`)}\n`); + } else { + this.stream.write(`${failure(ICON_FAILURE)} ${task.msg} ${failure(weak('- failed!'))}\n`); + } }); const spinner = new Spinner(); diff --git a/packages/@ionic/cli-framework-output/src/tasks.ts b/packages/@ionic/cli-framework-output/src/tasks.ts index b255a6c042..25e97c61ee 100644 --- a/packages/@ionic/cli-framework-output/src/tasks.ts +++ b/packages/@ionic/cli-framework-output/src/tasks.ts @@ -24,17 +24,29 @@ export interface TaskOptions { readonly tickInterval?: number; } +export interface TaskResult { + /** + * Elapsed time from process.hrtime() + */ + elapsedTime: [number, number]; + + /** + * Whether the task succeeded or not + */ + success: boolean; +} + export interface Task extends EventEmitter { on(name: 'success', handler: () => void): this; on(name: 'failure', handler: () => void): this; on(name: 'clear', handler: () => void): this; on(name: 'tick', handler: () => void): this; - on(name: 'end', handler: () => void): this; + on(name: 'end', handler: (result: TaskResult) => void): this; emit(name: 'success'): boolean; emit(name: 'failure'): boolean; emit(name: 'clear'): boolean; emit(name: 'tick'): boolean; - emit(name: 'end'): boolean; + emit(name: 'end', result: TaskResult): boolean; } export class Task extends EventEmitter { @@ -45,6 +57,8 @@ export class Task extends EventEmitter { progressRatio?: number; protected _msg = ''; + protected _startTime?: [number, number]; // hrtime + protected _success = false; constructor({ msg = '', tickInterval }: TaskOptions = {}) { super(); @@ -67,6 +81,7 @@ export class Task extends EventEmitter { } this.running = true; + this._startTime = process.hrtime(); return this; } @@ -98,13 +113,17 @@ export class Task extends EventEmitter { this.running = false; this.tick(); this.clear(); - this.emit('end'); + this.emit('end', { + elapsedTime: process.hrtime(this._startTime), + success: this._success, + }); return this; } succeed(): this { if (this.running) { + this._success = true; this.end(); this.emit('success'); } @@ -114,6 +133,7 @@ export class Task extends EventEmitter { fail(): this { if (this.running) { + this._success = false; this.end(); this.emit('failure'); } diff --git a/packages/@ionic/cli-framework-output/src/utils.ts b/packages/@ionic/cli-framework-output/src/utils.ts index c5cfe0893d..996f9b549a 100644 --- a/packages/@ionic/cli-framework-output/src/utils.ts +++ b/packages/@ionic/cli-framework-output/src/utils.ts @@ -22,3 +22,18 @@ export function dropWhile(array: readonly T[], predicate: (item: T) => boolea } }); } + +const TIME_UNITS = ['s', 'ms', 'μp']; + +export function formatHrTime(hrtime: [number, number]): string { + let time = hrtime[0] + hrtime[1] / 1e9; + let index = 0; + + for (; index < TIME_UNITS.length - 1; index++, time *= 1000) { + if (time >= 1) { + break; + } + } + + return time.toFixed(2) + TIME_UNITS[index]; +} From 8ed8f6bdee185d324e4183ff75d643a57c47b9b6 Mon Sep 17 00:00:00 2001 From: Ionitron Date: Wed, 26 Aug 2020 00:44:56 +0000 Subject: [PATCH 2/2] chore(release): publish [skip ci] - @ionic/cli-framework-output@1.1.0 - @ionic/cli-framework@4.2.2 - @ionic/cli@6.11.3 - @ionic/lab@3.2.2 - @ionic/v1-toolkit@3.2.6 - cli-scripts@2.1.23 --- packages/@ionic/cli-framework-output/CHANGELOG.md | 11 +++++++++++ packages/@ionic/cli-framework-output/package.json | 2 +- packages/@ionic/cli-framework/CHANGELOG.md | 8 ++++++++ packages/@ionic/cli-framework/package.json | 4 ++-- packages/@ionic/cli/CHANGELOG.md | 8 ++++++++ packages/@ionic/cli/package.json | 4 ++-- packages/@ionic/lab/CHANGELOG.md | 8 ++++++++ packages/@ionic/lab/package.json | 4 ++-- packages/@ionic/v1-toolkit/CHANGELOG.md | 8 ++++++++ packages/@ionic/v1-toolkit/package.json | 4 ++-- packages/cli-scripts/CHANGELOG.md | 8 ++++++++ packages/cli-scripts/package.json | 6 +++--- 12 files changed, 63 insertions(+), 12 deletions(-) diff --git a/packages/@ionic/cli-framework-output/CHANGELOG.md b/packages/@ionic/cli-framework-output/CHANGELOG.md index 17cbefd057..f73fa9342a 100644 --- a/packages/@ionic/cli-framework-output/CHANGELOG.md +++ b/packages/@ionic/cli-framework-output/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.1.0](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-framework-output@1.0.1...@ionic/cli-framework-output@1.1.0) (2020-08-26) + + +### Features + +* **output:** show elapsed time for tasks ([e4525f7](https://github.com/ionic-team/ionic-cli/commit/e4525f79b549b66e25e6c01297ccc77cc6c85250)) + + + + + ## 1.0.1 (2020-08-25) **Note:** Version bump only for package @ionic/cli-framework-output diff --git a/packages/@ionic/cli-framework-output/package.json b/packages/@ionic/cli-framework-output/package.json index f93995aed7..7475f40f2d 100644 --- a/packages/@ionic/cli-framework-output/package.json +++ b/packages/@ionic/cli-framework-output/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/cli-framework-output", - "version": "1.0.1", + "version": "1.1.0", "description": "The log/tasks/spinners portion of Ionic CLI Framework", "homepage": "https://ionicframework.com/", "author": "Ionic Team (https://ionicframework.com)", diff --git a/packages/@ionic/cli-framework/CHANGELOG.md b/packages/@ionic/cli-framework/CHANGELOG.md index 535bb46ae0..8739b3435f 100644 --- a/packages/@ionic/cli-framework/CHANGELOG.md +++ b/packages/@ionic/cli-framework/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.2.2](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-framework@4.2.1...@ionic/cli-framework@4.2.2) (2020-08-26) + +**Note:** Version bump only for package @ionic/cli-framework + + + + + ## [4.2.1](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-framework@4.2.0...@ionic/cli-framework@4.2.1) (2020-08-25) **Note:** Version bump only for package @ionic/cli-framework diff --git a/packages/@ionic/cli-framework/package.json b/packages/@ionic/cli-framework/package.json index b54fa2df58..0db1d58bcd 100644 --- a/packages/@ionic/cli-framework/package.json +++ b/packages/@ionic/cli-framework/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/cli-framework", - "version": "4.2.1", + "version": "4.2.2", "description": "The foundation framework of the Ionic CLI", "homepage": "https://ionicframework.com/", "author": "Ionic Team (https://ionicframework.com) ", @@ -19,7 +19,7 @@ }, "license": "MIT", "dependencies": { - "@ionic/cli-framework-output": "1.0.1", + "@ionic/cli-framework-output": "1.1.0", "@ionic/utils-array": "2.1.4", "@ionic/utils-fs": "3.1.4", "@ionic/utils-object": "2.1.4", diff --git a/packages/@ionic/cli/CHANGELOG.md b/packages/@ionic/cli/CHANGELOG.md index 77f2da143b..ae1468f7fd 100644 --- a/packages/@ionic/cli/CHANGELOG.md +++ b/packages/@ionic/cli/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [6.11.3](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli@6.11.2...@ionic/cli@6.11.3) (2020-08-26) + +**Note:** Version bump only for package @ionic/cli + + + + + ## [6.11.2](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli@6.11.1...@ionic/cli@6.11.2) (2020-08-25) **Note:** Version bump only for package @ionic/cli diff --git a/packages/@ionic/cli/package.json b/packages/@ionic/cli/package.json index e500a09946..ef98640e72 100644 --- a/packages/@ionic/cli/package.json +++ b/packages/@ionic/cli/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/cli", - "version": "6.11.2", + "version": "6.11.3", "description": "A tool for creating and developing Ionic Framework mobile apps.", "homepage": "https://ionicframework.com", "author": "Ionic Team (https://ionicframework.com) ", @@ -40,7 +40,7 @@ }, "license": "MIT", "dependencies": { - "@ionic/cli-framework": "4.2.1", + "@ionic/cli-framework": "4.2.2", "@ionic/cli-framework-prompts": "2.1.4", "@ionic/utils-array": "2.1.4", "@ionic/utils-fs": "3.1.4", diff --git a/packages/@ionic/lab/CHANGELOG.md b/packages/@ionic/lab/CHANGELOG.md index 1256b42be2..14985c2649 100644 --- a/packages/@ionic/lab/CHANGELOG.md +++ b/packages/@ionic/lab/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [3.2.2](https://github.com/ionic-team/ionic-cli/compare/@ionic/lab@3.2.1...@ionic/lab@3.2.2) (2020-08-26) + +**Note:** Version bump only for package @ionic/lab + + + + + ## [3.2.1](https://github.com/ionic-team/ionic-cli/compare/@ionic/lab@3.2.0...@ionic/lab@3.2.1) (2020-08-25) **Note:** Version bump only for package @ionic/lab diff --git a/packages/@ionic/lab/package.json b/packages/@ionic/lab/package.json index 0e8cb84fb9..a6e9317471 100644 --- a/packages/@ionic/lab/package.json +++ b/packages/@ionic/lab/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/lab", - "version": "3.2.1", + "version": "3.2.2", "description": "Ionic Lab utility for developing Ionic apps, used by Ionic CLI", "bin": { "ionic-lab": "./bin/ionic-lab" @@ -41,7 +41,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@ionic/cli-framework": "4.2.1", + "@ionic/cli-framework": "4.2.2", "@ionic/utils-fs": "3.1.4", "chalk": "^4.0.0", "express": "^4.16.2", diff --git a/packages/@ionic/v1-toolkit/CHANGELOG.md b/packages/@ionic/v1-toolkit/CHANGELOG.md index b81f4860c8..fc7a8b818f 100644 --- a/packages/@ionic/v1-toolkit/CHANGELOG.md +++ b/packages/@ionic/v1-toolkit/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [3.2.6](https://github.com/ionic-team/ionic-cli/compare/@ionic/v1-toolkit@3.2.5...@ionic/v1-toolkit@3.2.6) (2020-08-26) + +**Note:** Version bump only for package @ionic/v1-toolkit + + + + + ## [3.2.5](https://github.com/ionic-team/ionic-cli/compare/@ionic/v1-toolkit@3.2.4...@ionic/v1-toolkit@3.2.5) (2020-08-25) **Note:** Version bump only for package @ionic/v1-toolkit diff --git a/packages/@ionic/v1-toolkit/package.json b/packages/@ionic/v1-toolkit/package.json index c1cbbea796..7665cdf6aa 100644 --- a/packages/@ionic/v1-toolkit/package.json +++ b/packages/@ionic/v1-toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/v1-toolkit", - "version": "3.2.5", + "version": "3.2.6", "description": "Utility CLI for Ionic 1.x apps, used by Ionic CLI", "bin": { "ionic-v1": "./bin/ionic-v1" @@ -36,7 +36,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@ionic/cli-framework": "4.2.1", + "@ionic/cli-framework": "4.2.2", "@ionic/utils-fs": "3.1.4", "chalk": "^4.0.0", "chokidar": "^3.0.1", diff --git a/packages/cli-scripts/CHANGELOG.md b/packages/cli-scripts/CHANGELOG.md index 5e39ac2d65..b6905da9ea 100644 --- a/packages/cli-scripts/CHANGELOG.md +++ b/packages/cli-scripts/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.1.23](https://github.com/ionic-team/ionic-cli/compare/cli-scripts@2.1.22...cli-scripts@2.1.23) (2020-08-26) + +**Note:** Version bump only for package cli-scripts + + + + + ## [2.1.22](https://github.com/ionic-team/ionic-cli/compare/cli-scripts@2.1.21...cli-scripts@2.1.22) (2020-08-25) **Note:** Version bump only for package cli-scripts diff --git a/packages/cli-scripts/package.json b/packages/cli-scripts/package.json index 01ba7abe23..11f6fea299 100644 --- a/packages/cli-scripts/package.json +++ b/packages/cli-scripts/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "cli-scripts", - "version": "2.1.22", + "version": "2.1.23", "bin": { "ionic-cli-scripts": "./bin/ionic-cli-scripts" }, @@ -16,8 +16,8 @@ "main": "./dist/index.js", "types": "./dist/index.d.ts", "dependencies": { - "@ionic/cli": "6.11.2", - "@ionic/cli-framework": "4.2.1", + "@ionic/cli": "6.11.3", + "@ionic/cli-framework": "4.2.2", "@ionic/utils-fs": "3.1.4", "ansi-styles": "^4.0.0", "chalk": "^4.0.0",