command.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. const { filterOptions } = require("@lerna/filter-options");
  3. /**
  4. * @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module
  5. */
  6. exports.command = "add <pkg> [globs..]";
  7. exports.describe = "Add a single dependency to matched packages";
  8. exports.builder = (yargs) => {
  9. yargs
  10. .positional("pkg", {
  11. describe: "Package name to add as a dependency",
  12. type: "string",
  13. })
  14. .positional("globs", {
  15. describe: "Optional package directory globs to match",
  16. type: "array",
  17. })
  18. .options({
  19. D: {
  20. group: "Command Options:",
  21. type: "boolean",
  22. alias: "dev",
  23. describe: "Save to devDependencies",
  24. },
  25. E: {
  26. group: "Command Options:",
  27. type: "boolean",
  28. alias: "exact",
  29. describe: "Save version exactly",
  30. },
  31. P: {
  32. group: "Command Options:",
  33. type: "boolean",
  34. alias: "peer",
  35. describe: "Save to peerDependencies",
  36. },
  37. registry: {
  38. group: "Command Options:",
  39. describe: "Use the specified registry for all npm client operations.",
  40. type: "string",
  41. requiresArg: true,
  42. },
  43. "no-bootstrap": {
  44. group: "Command Options:",
  45. describe: "Do not automatically chain `lerna bootstrap` after changes are made.",
  46. type: "boolean",
  47. },
  48. bootstrap: {
  49. // proxy for --no-bootstrap
  50. hidden: true,
  51. type: "boolean",
  52. },
  53. })
  54. .example(
  55. "$0 add module-1 packages/prefix-*",
  56. "Adds the module-1 package to the packages in the 'prefix-' prefixed folders"
  57. )
  58. .example("$0 add module-1 --scope=module-2", "Install module-1 to module-2")
  59. .example("$0 add module-1 --scope=module-2 --dev", "Install module-1 to module-2 in devDependencies")
  60. .example("$0 add module-1 --scope=module-2 --peer", "Install module-1 to module-2 in peerDependencies")
  61. .example("$0 add module-1", "Install module-1 in all modules except module-1")
  62. .example("$0 add module-1 --no-bootstrap", "Skip automatic `lerna bootstrap`")
  63. .example("$0 add babel-core", "Install babel-core in all modules");
  64. return filterOptions(yargs);
  65. };
  66. exports.handler = function handler(argv) {
  67. return require(".")(argv);
  68. };