This repository has been archived by the owner on Jan 4, 2024. It is now read-only.
forked from lerna/lerna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (47 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"use strict";
const childProcess = require("@lerna/child-process");
const { Command } = require("@lerna/command");
const { ValidationError } = require("@lerna/validation-error");
const { getLastCommit } = require("./lib/get-last-commit");
const { hasCommit } = require("./lib/has-commit");
module.exports = factory;
function factory(argv) {
return new DiffCommand(argv);
}
class DiffCommand extends Command {
initialize() {
const packageName = this.options.pkgName;
let targetPackage;
if (packageName) {
targetPackage = this.packageGraph.get(packageName);
if (!targetPackage) {
throw new ValidationError("ENOPKG", `Cannot diff, the package '${packageName}' does not exist.`);
}
}
if (!hasCommit(this.execOpts)) {
throw new ValidationError("ENOCOMMITS", "Cannot diff, there are no commits in this repository yet.");
}
const args = ["diff", getLastCommit(this.execOpts), "--color=auto"];
if (targetPackage) {
args.push("--", targetPackage.location);
} else {
args.push("--", ...this.project.packageParentDirs);
}
if (this.options.ignoreChanges) {
this.options.ignoreChanges.forEach((ignorePattern) => {
// https://stackoverflow.com/a/21079437
args.push(`:(exclude,glob)${ignorePattern}`);
});
}
this.args = args;
}
execute() {
return childProcess.spawn("git", this.args, this.execOpts).catch((err) => {
if (err.exitCode) {
// quitting the diff viewer is not an error
throw err;
}
});
}
}
module.exports.DiffCommand = DiffCommand;