UNPKG

@lerna/publish

Version:

Publish packages in the current project

44 lines (43 loc) 1.45 kB
var import_core = require("@lerna/core"); const { getLastCommit } = require("./lib/get-last-commit"); const { hasCommit } = require("./lib/has-commit"); const childProcess = require("@lerna/child-process"); module.exports = function factory(argv) { return new DiffCommand(argv); }; class DiffCommand extends import_core.Command { args; initialize() { const packageName = this.options.pkgName; let targetPackage; if (packageName) { targetPackage = this.packageGraph.get(packageName); if (!targetPackage) { throw new import_core.ValidationError("ENOPKG", `Cannot diff, the package '${packageName}' does not exist.`); } } if (!hasCommit(this.execOpts)) { throw new import_core.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) => { args.push(`:(exclude,glob)${ignorePattern}`); }); } this.args = args; } execute() { return childProcess.spawn("git", this.args, this.execOpts).catch((err) => { if (err.exitCode) { throw err; } }); } } module.exports.DiffCommand = DiffCommand;