Skip to content

Commit

Permalink
Add versions to lerna ls. Fixes #603. (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-eb authored and hzoo committed Feb 28, 2017
1 parent b595884 commit 3ace547
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 71 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"async": "^1.5.0",
"chalk": "^1.1.1",
"cmd-shim": "^2.0.2",
"columnify": "^1.5.4",
"command-join": "^2.0.0",
"cross-spawn": "^4.0.0",
"glob": "^7.0.6",
Expand Down
12 changes: 9 additions & 3 deletions src/commands/LsCommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Command from "../Command";
import chalk from "chalk";
import columnify from "columnify";

export default class LsCommand extends Command {
initialize(callback) {
Expand All @@ -9,10 +10,15 @@ export default class LsCommand extends Command {

execute(callback) {
const formattedPackages = this.filteredPackages
.map((pkg) => `- ${pkg.name}${pkg.isPrivate() ? ` (${chalk.red("private")})` : ""}`)
.join("\n");
.map((pkg) => {
return {
name: pkg.name,
version: chalk.grey(`v${pkg.version}`),
private: pkg.isPrivate() ? `(${chalk.red("private")})` : ""
};
});

this.logger.info(formattedPackages);
this.logger.info(columnify(formattedPackages, {showHeaders: false}));
callback(null, true);
}
}
20 changes: 16 additions & 4 deletions test/LsCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import LsCommand from "../src/commands/LsCommand";
import logger from "../src/logger";
import stub from "./_stub";

function formatPrivate (pkg) {
return `${pkg} ${chalk.grey("v1.0.0")} (${chalk.red("private")})`;
}

function formatPublic (pkg) {
return `${pkg} ${chalk.grey("v1.0.0")} `;
}

function formatOnlyPublic (pkg) {
return `${pkg} ${chalk.grey("v1.0.0")} `;
}

describe("LsCommand", () => {

describe("in a basic repo", () => {
Expand All @@ -21,7 +33,7 @@ describe("LsCommand", () => {
lsCommand.runPreparations();

stub(logger, "info", (message) => {
assert.equal(message, `- package-1\n- package-2\n- package-3\n- package-4\n- package-5 (${chalk.red("private")})`);
assert.equal(message, `${formatPublic("package-1")}\n${formatPublic("package-2")}\n${formatPublic("package-3")}\n${formatPublic("package-4")}\n${formatPrivate("package-5")}`);
});

lsCommand.runCommand(exitWithCode(0, done));
Expand All @@ -41,7 +53,7 @@ describe("LsCommand", () => {
lsCommand.runPreparations();

stub(logger, "info", (message) => {
assert.equal(message, "- package-1");
assert.equal(message, formatOnlyPublic("package-1"));
});

lsCommand.runCommand(exitWithCode(0, done));
Expand All @@ -61,7 +73,7 @@ describe("LsCommand", () => {
lsCommand.runPreparations();

stub(logger, "info", (message) => {
assert.equal(message, "- package-1\n- package-2\n- package-3");
assert.equal(message, `${formatOnlyPublic("package-1")}\n${formatOnlyPublic("package-2")}\n${formatOnlyPublic("package-3")}`);
});

lsCommand.runCommand(exitWithCode(0, done));
Expand All @@ -83,7 +95,7 @@ describe("LsCommand", () => {
lsCommand.runPreparations();

stub(logger, "info", (message) => {
assert.equal(message, "- @test/package-2\n- @test/package-1");
assert.equal(message, `${formatOnlyPublic("@test/package-2")}\n${formatOnlyPublic("@test/package-1")}`);
});

lsCommand.runCommand(exitWithCode(0, done));
Expand Down
Loading

0 comments on commit 3ace547

Please sign in to comment.