@lerna/publish
Version:
Publish packages in the current project
48 lines (47 loc) • 1.79 kB
JavaScript
var import_core = require("@lerna/core");
var import_watch = require("nx/src/command-line/watch");
var import_configuration = require("nx/src/config/configuration");
module.exports = function factory(argv) {
return new WatchCommand(argv);
};
class WatchCommand extends import_core.Command {
filteredPackages = [];
count = 0;
packagePlural = "packages";
get requiresGit() {
return false;
}
async initialize() {
if (!this.options.command) {
throw new import_core.ValidationError("ENOCOMMAND", "A command to execute is required");
}
this.filteredPackages = await (0, import_core.getFilteredPackages)(this.packageGraph, this.execOpts, this.options);
this.count = this.filteredPackages.length;
this.packagePlural = this.count === 1 ? "package" : "packages";
}
async execute() {
this.logger.info(
"watch",
"Executing command %j on changes in %d %s.",
this.options.command,
this.count,
this.packagePlural
);
const projectNames = getNxProjectNamesFromLernaPackageNames(this.filteredPackages.map((p) => p.name));
await (0, import_watch.watch)({
command: this.options.command,
projectNameEnvName: "LERNA_PACKAGE_NAME",
fileChangesEnvName: "LERNA_FILE_CHANGES",
includeDependentProjects: false,
// dependent projects are accounted for via lerna filter options
projects: projectNames,
verbose: this.options.verbose
});
}
}
const getNxProjectNamesFromLernaPackageNames = (packageNames) => {
const nxJson = (0, import_configuration.readNxJson)();
const nxConfiguredNpmScope = nxJson.npmScope;
return nxConfiguredNpmScope ? packageNames.map((name) => name.replace(`@${nxConfiguredNpmScope}/`, "")) : packageNames;
};
module.exports.WatchCommand = WatchCommand;