Skip to content

Commit

Permalink
feat: differentiate between install and update operation
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Oct 23, 2018
1 parent 05a98ac commit d70afc8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bin/dev-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d70afc8

Please sign in to comment.