cli.cjs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env node
  2. 'use strict';
  3. const citty = require('citty');
  4. const index = require('./index.cjs');
  5. require('node:fs');
  6. require('node:fs/promises');
  7. require('pathe');
  8. require('node:module');
  9. require('ufo');
  10. const name = "nypm";
  11. const version = "0.3.6";
  12. const description = "Unified Package Manager for Node.js";
  13. const operationArgs = {
  14. cwd: {
  15. type: "string",
  16. description: "Current working directory"
  17. },
  18. workspace: {
  19. type: "boolean",
  20. description: "Add to workspace"
  21. },
  22. silent: {
  23. type: "boolean",
  24. description: "Run in silent mode"
  25. }
  26. };
  27. const install = citty.defineCommand({
  28. meta: {
  29. description: "Install dependencies"
  30. },
  31. args: {
  32. ...operationArgs,
  33. name: {
  34. type: "positional",
  35. description: "Dependency name",
  36. required: false
  37. },
  38. dev: {
  39. type: "boolean",
  40. alias: "D",
  41. description: "Add as dev dependency"
  42. }
  43. },
  44. run: async ({ args }) => {
  45. await (args._.length > 0 ? index.addDependency(args._, args) : index.installDependencies(args));
  46. }
  47. });
  48. const remove = citty.defineCommand({
  49. meta: {
  50. description: "Remove dependencies"
  51. },
  52. args: {
  53. name: {
  54. type: "positional",
  55. description: "Dependency name",
  56. required: true
  57. },
  58. ...operationArgs
  59. },
  60. run: async ({ args }) => {
  61. await index.removeDependency(args.name, args);
  62. }
  63. });
  64. const main = citty.defineCommand({
  65. meta: {
  66. name,
  67. version,
  68. description
  69. },
  70. subCommands: {
  71. install,
  72. i: install,
  73. add: install,
  74. remove
  75. }
  76. });
  77. citty.runMain(main);