cli.cjs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/usr/bin/env node
  2. 'use strict';
  3. const node_path = require('node:path');
  4. const citty = require('citty');
  5. const consola = require('consola');
  6. const index = require('./index.cjs');
  7. require('node:fs/promises');
  8. require('node:fs');
  9. require('tar');
  10. require('pathe');
  11. require('defu');
  12. require('nypm');
  13. require('node:stream');
  14. require('node:child_process');
  15. require('node:os');
  16. require('node:util');
  17. require('node-fetch-native/proxy');
  18. const name = "giget";
  19. const version = "1.2.1";
  20. const description = "Download templates and git repositories with pleasure!";
  21. const repository = "unjs/giget";
  22. const license = "MIT";
  23. const sideEffects = false;
  24. const type = "module";
  25. const exports$1 = {
  26. ".": {
  27. "import": {
  28. types: "./dist/index.d.mts",
  29. "default": "./dist/index.mjs"
  30. },
  31. require: {
  32. types: "./dist/index.d.cts",
  33. "default": "./dist/index.cjs"
  34. }
  35. }
  36. };
  37. const main = "./dist/index.cjs";
  38. const module$1 = "./dist/index.mjs";
  39. const types = "./dist/index.d.ts";
  40. const bin = {
  41. giget: "./dist/cli.mjs"
  42. };
  43. const files = [
  44. "dist"
  45. ];
  46. const scripts = {
  47. build: "unbuild",
  48. dev: "vitest dev",
  49. giget: "jiti ./src/cli.ts",
  50. lint: "eslint --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
  51. "lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test",
  52. prepack: "unbuild",
  53. play: "pnpm giget --force-clean --verbose unjs .tmp/clone",
  54. release: "pnpm test && changelogen --release && npm publish && git push --follow-tags",
  55. test: "pnpm lint && vitest run --coverage"
  56. };
  57. const dependencies = {
  58. citty: "^0.1.5",
  59. consola: "^3.2.3",
  60. defu: "^6.1.3",
  61. "node-fetch-native": "^1.6.1",
  62. nypm: "^0.3.3",
  63. ohash: "^1.1.3",
  64. pathe: "^1.1.1",
  65. tar: "^6.2.0"
  66. };
  67. const devDependencies = {
  68. "@types/node": "^20.10.5",
  69. "@types/tar": "^6.1.10",
  70. "@vitest/coverage-v8": "^1.1.0",
  71. changelogen: "^0.5.5",
  72. eslint: "^8.56.0",
  73. "eslint-config-unjs": "^0.2.1",
  74. jiti: "^1.21.0",
  75. prettier: "^3.1.1",
  76. typescript: "^5.3.3",
  77. unbuild: "^2.0.0",
  78. vitest: "^1.1.0"
  79. };
  80. const packageManager = "pnpm@8.12.1";
  81. const pkg = {
  82. name: name,
  83. version: version,
  84. description: description,
  85. repository: repository,
  86. license: license,
  87. sideEffects: sideEffects,
  88. type: type,
  89. exports: exports$1,
  90. main: main,
  91. module: module$1,
  92. types: types,
  93. bin: bin,
  94. files: files,
  95. scripts: scripts,
  96. dependencies: dependencies,
  97. devDependencies: devDependencies,
  98. packageManager: packageManager
  99. };
  100. const mainCommand = citty.defineCommand({
  101. meta: {
  102. name: pkg.name,
  103. version: pkg.version,
  104. description: pkg.description
  105. },
  106. args: {
  107. // TODO: Make it `-t` in the next major version
  108. template: {
  109. type: "positional",
  110. description: "Template name or a a URI describing provider, repository, subdir, and branch/ref"
  111. },
  112. dir: {
  113. type: "positional",
  114. description: "A relative or absolute path where to extract the template",
  115. required: false
  116. },
  117. auth: {
  118. type: "string",
  119. description: "Custom Authorization token to use for downloading template. (Can be overriden with `GIGET_AUTH` environment variable)"
  120. },
  121. cwd: {
  122. type: "string",
  123. description: "Set current working directory to resolve dirs relative to it"
  124. },
  125. force: {
  126. type: "boolean",
  127. description: "Clone to existing directory even if exists"
  128. },
  129. forceClean: {
  130. type: "boolean",
  131. description: "Remove any existing directory or file recusively before cloning"
  132. },
  133. offline: {
  134. type: "boolean",
  135. description: "o not attempt to download and use cached version"
  136. },
  137. preferOffline: {
  138. type: "boolean",
  139. description: "Use cache if exists otherwise try to download"
  140. },
  141. shell: {
  142. type: "boolean",
  143. description: "Open a new shell with current working "
  144. },
  145. install: {
  146. type: "boolean",
  147. description: "Install dependencies after cloning"
  148. },
  149. verbose: {
  150. type: "boolean",
  151. description: "Show verbose debugging info"
  152. }
  153. },
  154. run: async ({ args }) => {
  155. if (args.verbose) {
  156. process.env.DEBUG = process.env.DEBUG || "true";
  157. }
  158. const r = await index.downloadTemplate(args.template, {
  159. dir: args.dir,
  160. force: args.force,
  161. forceClean: args.forceClean,
  162. offline: args.offline,
  163. preferOffline: args.preferOffline,
  164. auth: args.auth,
  165. install: args.install
  166. });
  167. const _from = r.name || r.url;
  168. const _to = node_path.relative(process.cwd(), r.dir) || "./";
  169. consola.consola.log(`\u2728 Successfully cloned \`${_from}\` to \`${_to}\`
  170. `);
  171. if (args.shell) {
  172. index.startShell(r.dir);
  173. }
  174. }
  175. });
  176. citty.runMain(mainCommand);