cli.mjs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env node
  2. import { relative } from 'node:path';
  3. import { defineCommand, runMain } from 'citty';
  4. import { consola } from 'consola';
  5. import { d as downloadTemplate, s as startShell } from './shared/giget.OCaTp9b-.mjs';
  6. import 'node:fs/promises';
  7. import 'node:fs';
  8. import 'assert';
  9. import 'path';
  10. import 'events';
  11. import 'stream';
  12. import 'string_decoder';
  13. import 'buffer';
  14. import 'zlib';
  15. import 'process';
  16. import 'fs';
  17. import 'util';
  18. import 'crypto';
  19. import 'pathe';
  20. import 'defu';
  21. import 'nypm';
  22. import 'node:stream';
  23. import 'node:child_process';
  24. import 'node:os';
  25. import 'node:util';
  26. import 'node-fetch-native/proxy';
  27. const name = "giget";
  28. const version = "2.0.0";
  29. const description = "Download templates and git repositories with pleasure!";
  30. const pkg = {
  31. name: name,
  32. version: version,
  33. description: description};
  34. const mainCommand = defineCommand({
  35. meta: {
  36. name: pkg.name,
  37. version: pkg.version,
  38. description: pkg.description
  39. },
  40. args: {
  41. // TODO: Make it `-t` in the next major version
  42. template: {
  43. type: "positional",
  44. description: "Template name or a a URI describing provider, repository, subdir, and branch/ref"
  45. },
  46. dir: {
  47. type: "positional",
  48. description: "A relative or absolute path where to extract the template",
  49. required: false
  50. },
  51. auth: {
  52. type: "string",
  53. description: "Custom Authorization token to use for downloading template. (Can be overriden with `GIGET_AUTH` environment variable)"
  54. },
  55. cwd: {
  56. type: "string",
  57. description: "Set current working directory to resolve dirs relative to it"
  58. },
  59. force: {
  60. type: "boolean",
  61. description: "Clone to existing directory even if exists"
  62. },
  63. forceClean: {
  64. type: "boolean",
  65. description: "Remove any existing directory or file recusively before cloning"
  66. },
  67. offline: {
  68. type: "boolean",
  69. description: "o not attempt to download and use cached version"
  70. },
  71. preferOffline: {
  72. type: "boolean",
  73. description: "Use cache if exists otherwise try to download"
  74. },
  75. shell: {
  76. type: "boolean",
  77. description: "Open a new shell with current working "
  78. },
  79. install: {
  80. type: "boolean",
  81. description: "Install dependencies after cloning"
  82. },
  83. verbose: {
  84. type: "boolean",
  85. description: "Show verbose debugging info"
  86. }
  87. },
  88. run: async ({ args }) => {
  89. if (args.verbose) {
  90. process.env.DEBUG = process.env.DEBUG || "true";
  91. }
  92. const r = await downloadTemplate(args.template, {
  93. dir: args.dir,
  94. force: args.force,
  95. forceClean: args.forceClean,
  96. offline: args.offline,
  97. preferOffline: args.preferOffline,
  98. auth: args.auth,
  99. install: args.install
  100. });
  101. const _from = r.name || r.url;
  102. const _to = relative(process.cwd(), r.dir) || "./";
  103. consola.log(`\u2728 Successfully cloned \`${_from}\` to \`${_to}\`
  104. `);
  105. if (args.shell) {
  106. startShell(r.dir);
  107. }
  108. }
  109. });
  110. runMain(mainCommand);