GithubHelp home page GithubHelp logo

progress-estimator's Introduction

progress-estimator

Logs a progress bar and estimation for how long a Promise will take to complete. This library tracks previous durations in order to provide more accurate estimates over time.

Demo

Installation

# use npm
npm install progress-estimator

# use yarn
yarn add progress-estimator

Usage example

const createLogger = require('progress-estimator');
const { join } = require('path');

// All configuration keys are optional, but it's recommended to specify a storage location.
// Learn more about configuration options below.
const logger = createLogger({
  storagePath: join(__dirname, '.progress-estimator'),
});

async function run() {
  await logger(promiseOne, "This is a promise");
  await logger(
    promiseTwo,
    "This is another promise. I think it will take about 1 second",
    {
      estimate: 1000
    }
  );
}

API

createLogger(optionalConfiguration)

This method is the default package export. It creates and configures a logger function (documented below). The following configuration options are supported. (They apply only to the logger instance that's returned.)

name type Description
logFunction Function Custom logging function. Defaults to log-update. Must define .done() and .clear() methods.
spinner object Which spinner from the cli-spinners package to use. Defaults to dots.
storagePath string Where to record durations between runs. Defaults to os.tmpdir().
theme object Custom chalk theme. Look to the default theme for a list of required keys.

logger(promise, labelString, options)

This method logs a progress bar and estimated duration for a promise. It requires at least two parameters– a Promise and a label (e.g. "Running tests"). The label is SHA1 hashed in order to uniquely identify the promise.

An optional third parameter can be provided as well with the following keys:

name type Description
estimate Number Estimated duration of promise. (This value is used initially, until a history of actual durations have been recorded.)
id String Uniquely identifies the promise. This value is needed if the label string is not guaranteed to be unique.

progress-estimator's People

Contributors

bvaughn avatar dependabot[bot] avatar hua1995116 avatar jacobwgillespie avatar maazadeeb avatar techieshark avatar tkh44 avatar tommy351 avatar zyszys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

progress-estimator's Issues

Suggestion: Add an explicit value to hash instead of relying on label

I'm using progress-estimator with an ESlint wrapper. The expected runtime is thus dependent on the number of files and can fluctuate a lot (eslint-wrapper singlefile.js vs. eslint-wrapper some/dir).

It'd be nice if the label could be consistent, while still having somewhat usable time estimates.

0.3.0 Release?

Hi Brian,

I added progress-estimator to a little script I wrote around the same time you had initially shared it. I've (somewhat regretfully) been adding TypeScript support to my own script, and it looks like pulling progress-estimator from npm results in the 0.2.2 version that doesn't have some of the more recent commits to master.

I'm putting at the repo directly for now, but figured I'd open the issue in case it was of interest to you (or others). Thanks for the neat library!

How to make this work nicely with stdout from other processes?

I have this unfortunate behavior where the progress bar gets carried along with the other logs. Any ideas how I can fix this?

⠹ Building Client  0%                  0.0m, estimated 3.6m
ℹ 「atl」: Using [email protected] from typescript
⠼ Building Client  20%                 0.7m, estimated 3.6m
(node:42049) DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead
    at Object.pitch (/Users/chet/Code/notion-next/node_modules/worker-loader/dist/index.js:87:19)
    at LOADER_EXECUTION (/Users/chet/Code/notion-next/node_modules/loader-runner/lib/LoaderRunner.js:119:14)
    at runSyncOrAsync (/Users/chet/Code/notion-next/node_modules/loader-runner/lib/LoaderRunner.js:120:4)
    at /Users/chet/Code/notion-next/node_modules/loader-runner/lib/LoaderRunner.js:175:3
    at loadLoader (/Users/chet/Code/notion-next/node_modules/loader-runner/lib/loadLoader.js:36:3)
    at iteratePitchingLoaders (/Users/chet/Code/notion-next/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at runLoaders (/Users/chet/Code/notion-next/node_modules/loader-runner/lib/LoaderRunner.js:362:2)
    at NormalModule.doBuild (/Users/chet/Code/notion-next/node_modules/webpack/lib/NormalModule.js:282:3)
    at NormalModule.build (/Users/chet/Code/notion-next/node_modules/webpack/lib/NormalModule.js:429:15)
    at Compilation.buildModule (/Users/chet/Code/notion-next/node_modules/webpack/lib/Compilation.js:369:10)
    at factory.create (/Users/chet/Code/notion-next/node_modules/webpack/lib/Compilation.js:596:14)
    at factory (/Users/chet/Code/notion-next/node_modules/webpack/lib/NormalModuleFactory.js:405:6)
    at hooks.afterResolve.callAsync (/Users/chet/Code/notion-next/node_modules/webpack/lib/NormalModuleFactory.js:155:13)
    at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (/Users/chet/Code/notion-next/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at resolver (/Users/chet/Code/notion-next/node_modules/webpack/lib/NormalModuleFactory.js:138:29)
    at process.nextTick (/Users/chet/Code/notion-next/node_modules/webpack/lib/NormalModuleFactory.js:342:9)
⠼ Building Client  67%                 2.4m, estimated 3.6m

Types seem pretty broken

The types seem to be wrong

Screen Shot 2019-07-02 at 2 50 25 PM

The types export a bunch of things the library doesn't seem to export. Such as the configure function.

Here are the fixed types:

import { Chalk } from 'chalk';

export interface Spinner {
  interval: number;
  frames: string[];
}

export interface ChalkTheme extends Chalk {
  asciiCompleted: Chalk;
  asciiInProgress: Chalk;
  estimate: Chalk;
  estimateExceeded: Chalk;
  label: Chalk;
  percentage: Chalk;
  progressBackground: Chalk;
  progressForeground: Chalk;
}

export interface Configuration {
  spinner?: Spinner;
  storagePath?: string;
  theme?: ChalkTheme;
}

export type ProgressEstimator = <T>(
  promise: Promise<T>,
  label: string,
  estimatedDuration?: number
) => Promise<T>;

declare const configure: (options: Configuration) => ProgressEstimator;

export default configure;

Support JSDOC

Hi,bvaughn.

I want to add jsdoc descriptions to all files in this library, because even with ts namespace, type hints will still be lost in js, which is not very good DX. Can I hear your opinion, I'd love to add this feature.

Suggestion: a way to inject a function instead of logUpdate

To integrate with listr where you can have many long tasks running in parallel and which uses its own renderer with log-update under the hood and provides a task.output abstraction to update the display, it would be beneficial to split this library's output string generation from printing/updating the terminal.

This can be simply done by providing a way to the caller of logProgress to replace logUpdate with a custom object provided via the logProgress arguments (potentially the fourth or the third should be the options object).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.