Skip to content

Commit

Permalink
Merge pull request #45 from kittens/diff
Browse files Browse the repository at this point in the history
Add lerna diff command
  • Loading branch information
jamiebuilds committed Feb 20, 2016
2 parents e3f1645 + b19d8bb commit 91a22ec
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bin/lerna.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var cli = meow([
" bootstrap Link together local packages and npm install remaining package dependencies",
" publish Publish updated packages to npm",
" updated Check which packages have changed since the last release",
" diff Diff all packages or a single package since the last release",
" run Run npm script in each package",
" ls List all public packages",
"",
Expand All @@ -37,4 +38,4 @@ if (!command) {

var config = init(commandName, process.cwd(), cli.flags.independent);

command(config);
command(config, cli);
41 changes: 41 additions & 0 deletions lib/commands/diff/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var gitGetLastTaggedCommit = require("../../utils/gitGetLastTaggedCommit");
var gitHasTags = require("../../utils/gitHasTags")
var execSync = require("../../utils/execSync");
var child = require("child_process");
var pager = require("default-pager");
var chalk = require("chalk");
var path = require("path");
var fs = require("fs");

function gitGetFirstCommit() {
execSync("git rev-list --max-parents=0 HEAD");
}

module.exports = function (config, cli) {
var packageName = cli.input[1];
var filePath = "packages";

if (packageName) {
var pkgLoc = path.join(config.packagesLoc, packageName, "package.json");

if (!fs.existsSync(pkgLoc)) {
console.log(chalk.red("Package '" + packageName + "' does not exist."));
process.exit(1);
}

filePath += "/" + packageName;
}

var hasTags = gitHasTags();
var lastCommit;

if (hasTags) {
lastCommit = gitGetLastTaggedCommit();
} else {
lastCommit = gitGetFirstCommit();
}

var diff = child.spawn("git", ["diff", lastCommit, "--color", filePath]);

diff.stdout.pipe(pager());
};
1 change: 1 addition & 0 deletions lib/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exports.bootstrap = require("./bootstrap");
exports.publish = require("./publish");
exports.updated = require("./updated");
exports.diff = require("./diff");
exports.run = require("./run");
exports.ls = require("./ls");
18 changes: 10 additions & 8 deletions lib/utils/checkUpdatedPackages.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var getPackageLocation = require("./getPackageLocation");
var getPackageConfig = require("./getPackageConfig");
var getPackages = require("./getPackages");
var progressBar = require("./progressBar");
var execSync = require("./execSync");
var chalk = require("chalk");
var gitGetLastTaggedCommit = require("./gitGetLastTaggedCommit");
var getPackageLocation = require("./getPackageLocation");
var getPackageConfig = require("./getPackageConfig");
var getPackages = require("./getPackages");
var progressBar = require("./progressBar");
var gitHasTags = require("./gitHasTags");
var execSync = require("./execSync");
var chalk = require("chalk");

module.exports = function checkUpdatedPackages(packagesLoc) {
var changedPackages = [];
Expand All @@ -16,12 +18,12 @@ module.exports = function checkUpdatedPackages(packagesLoc) {

var tick = progressBar(packages.length);

var hasTags = !!execSync("git tag");
var hasTags = gitHasTags();
var lastTagCommit;
var lastTag;

if (hasTags) {
lastTagCommit = execSync("git rev-list --tags --max-count=1");
lastTagCommit = gitGetLastTaggedCommit();
lastTag = execSync("git describe --tags " + lastTagCommit);
}

Expand Down
5 changes: 5 additions & 0 deletions lib/utils/gitGetLastTaggedCommit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var execSync = require("./execSync");

module.exports = function gitGetLastTaggedCommit() {
return execSync("git rev-list --tags --max-count=1");
};
5 changes: 5 additions & 0 deletions lib/utils/gitHasTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var execSync = require("./execSync");

module.exports = function gitHasTags() {
return !!execSync("git tag");
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"async": "^1.5.0",
"chalk": "^1.1.1",
"default-pager": "^1.0.2",
"meow": "^3.7.0",
"mkdirp": "^0.5.1",
"pad": "^1.0.0",
Expand Down

0 comments on commit 91a22ec

Please sign in to comment.