From d70afc87dda6f596a9c12f12b035ba2ea5e8b7f3 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Tue, 23 Oct 2018 11:36:10 +0200 Subject: [PATCH] feat: differentiate between install and update operation --- bin/dev-package.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/dev-package.js b/bin/dev-package.js index 3859772..6c5dc4d 100755 --- a/bin/dev-package.js +++ b/bin/dev-package.js @@ -60,26 +60,32 @@ const log = require("log4").get("dev-package") , installPackage = require("../lib/install-package") , resolveUserConfiguration = require("../lib/resolve-user-configuration"); -const installsInProgress = new Set(); +const installsInProgress = new Map(); + +const logWordForms = { + present: { install: "installing", update: "updating" }, + past: { install: "installed", update: "updated" } +}; cliFooter.shouldAddProgressAnimationPrefix = true; cliFooter.updateProgress(["resolving user configuration"]); const updateProgress = () => { cliFooter.updateProgress( - Array.from(installsInProgress, inProgressPackageName => - format("installing %s", inProgressPackageName) + Array.from(installsInProgress, ([inProgressPackageName, { type }]) => + format(`${ logWordForms.present[type] } %s`, inProgressPackageName) ) ); }; -installPackage.on("start", ({ packageName: startedPackageName }) => { - installsInProgress.add(startedPackageName); +installPackage.on("start", event => { + installsInProgress.set(event.packageName, event); updateProgress(); }); installPackage.on("end", ({ packageName: endedPackageName }) => { + const { type } = installsInProgress.get(endedPackageName); installsInProgress.delete(endedPackageName); - log.notice("installed %s", endedPackageName); + log.notice(`${ logWordForms.past[type] } %s`, endedPackageName); updateProgress(); }); resolveUserConfiguration()