-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from kittens/diff
Add lerna diff command
- Loading branch information
Showing
7 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters