cli.mjs 1.5 KB

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