giget 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,27 +1,31 @@
1
- # giget
1
+ # giget
2
2
 
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
- [![Github Actions][github-actions-src]][github-actions-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
6
  [![Codecov][codecov-src]][codecov-href]
7
7
 
8
8
  > Download templates and git repositories with pleasure!
9
9
 
10
10
  ## Features
11
11
 
12
- Support popular git providers (GitHub, GitLab, Bitbucket, Sourcehut) out of the box.
12
+ Support popular git providers (GitHub, GitLab, Bitbucket, Sourcehut) out of the box.
13
13
 
14
- Built-in and custom [template registry](#template-registry).
14
+ Built-in and custom [template registry](#template-registry).
15
15
 
16
- Fast cloning using tarball gzip without depending on local `git` and `tar`.
16
+ Fast cloning using tarball gzip without depending on local `git` and `tar`.
17
17
 
18
- Works online and offline with disk cache support.
18
+ Works online and offline with disk cache support.
19
19
 
20
- Custom template provider support with programmatic usage.
20
+ Custom template provider support with programmatic usage.
21
21
 
22
- Support extracting with a subdir.
22
+ Support extracting with a sub dir.
23
23
 
24
- Authorization support to download private templates
24
+ Authorization support to download private templates
25
+
26
+ ✨ Optionally install dependencies after clone using [unjs/nypm](https://github.com/unjs/nypm)
27
+
28
+ ✨ HTTP proxy support and native fetch via [unjs/node-fetch-native](https://github.com/unjs/node-fetch-native)
25
29
 
26
30
  ## Usage (CLI)
27
31
 
@@ -31,21 +35,22 @@ npx giget@latest <template> [<dir>] [...options]
31
35
 
32
36
  ### Arguments
33
37
 
34
- - **template**: Template name or a a URI describing provider, repository, subdir, and branch/ref. (See [Examples](#examples))
38
+ - **template**: Template name or a URI describing provider, repository, sub dir, and branch/ref. (See [Examples](#examples))
35
39
  - **dir**: A relative or absolute path where to extract the template.
36
40
 
37
41
  ### Options
38
42
 
39
43
  - `--force`: Clone to existing directory even if exists.
40
- - `--offline`: Do not attempt to download and use cached version.
44
+ - `--offline`: Do not attempt to download and use the cached version.
41
45
  - `--prefer-offline`: Use cache if exists otherwise try to download.
42
- - `--force-clean`: ⚠️ Remove any existing directory or file recusively before cloning.
43
- - `--shell`: ⚠️ Open a new shell with current working directory in cloned dir. (Experimental).
44
- - `--registry`: URL to a custom registry. (Can be overriden with `GIGET_REGISTRY` environment variable).
46
+ - `--force-clean`: ⚠️ Remove any existing directory or file recursively before cloning.
47
+ - `--shell`: ⚠️ Open a new shell with the current working directory in cloned dir. (Experimental).
48
+ - `--registry`: URL to a custom registry. (Can be overridden with `GIGET_REGISTRY` environment variable).
45
49
  - `--no-registry`: Disable registry lookup and functionality.
46
50
  - `--verbose`: Show verbose debugging info.
47
- - `--cwd`: Set current working directory to resolve dirs relative to it.
48
- - `--auth`: Custom Authorization token to use for downloading template. (Can be overriden with `GIGET_AUTH` environment variable).
51
+ - `--cwd`: Set the current working directory to resolve dirs relative to it.
52
+ - `--auth`: Custom Authorization token to use for downloading template. (Can be overridden with `GIGET_AUTH` environment variable).
53
+ - `--install`: Install dependencies after cloning using [unjs/nypm](https://github.com/unjs/nypm).
49
54
 
50
55
  ### Examples
51
56
 
@@ -73,17 +78,23 @@ npx giget@latest bitbucket:unjs/template
73
78
 
74
79
  # Clone from sourcehut
75
80
  npx giget@latest sourcehut:pi0/unjs-template
81
+
82
+ # Clone from https URL (tarball)
83
+ npx giget@latest https://api.github.com/repos/unjs/template/tarball/main
84
+
85
+ # Clone from https URL (JSON)
86
+ npx giget@latest https://raw.githubusercontent.com/unjs/giget/main/templates/unjs.json
76
87
  ```
77
88
 
78
89
  ## Template Registry
79
90
 
80
- Giget has a built-in HTTP registry system for resolving templates. This way you can support template name shortcuts and meta-data. Default registry is served from [unjs/giget/templates](./templates/).
91
+ Giget has a built-in HTTP registry system for resolving templates. This way you can support template name shortcuts and meta-data. The default registry is served from [unjs/giget/templates](./templates/).
81
92
 
82
- If you want to add your template to the built-in registry, just drop a PR to add it to the [./templates](./templates) directory. Slugs are added on first-come first-served basis but this might change in the future.
93
+ If you want to add your template to the built-in registry, just drop a PR to add it to the [./templates](./templates) directory. Slugs are added on a first-come first-served basis but this might change in the future.
83
94
 
84
95
  ### Custom Registry
85
96
 
86
- A custom registry should provide an endpoint with dynamic path `/:template.json` that returns a JSON response with keys same as [custom providers](#custom-providers).
97
+ A custom registry should provide an endpoint with the dynamic path `/:template.json` that returns a JSON response with keys the same as [custom providers](#custom-providers).
87
98
 
88
99
  - `name`: (required) Name of the template.
89
100
  - `tar` (required) Link to the tar download link.
@@ -92,7 +103,7 @@ A custom registry should provide an endpoint with dynamic path `/:template.json`
92
103
  - `subdir`: (optional) Directory inside the tar file.
93
104
  - `headers`: (optional) Custom headers to send while downloading template.
94
105
 
95
- Because of the simplicity, you can even use a GitHub repository as template registry but also you can build something more powerful by bringing your own API.
106
+ Because of the simplicity, you can even use a GitHub repository as a template registry but also you can build something more powerful by bringing your own API.
96
107
 
97
108
  ## Usage (Programmatic)
98
109
 
@@ -133,17 +144,17 @@ const { source, dir } = await downloadTemplate("github:unjs/template");
133
144
  - `options`: (object) Options are usually inferred from the input string. You can customize them.
134
145
  - `dir`: (string) Destination directory to clone to. If not provided, `user-name` will be used relative to the current directory.
135
146
  - `provider`: (string) Either `github`, `gitlab`, `bitbucket` or `sourcehut`. The default is `github`.
136
- - `repo`: (string) Name of repository in format of `{username}/{reponame}`.
147
+ - `repo`: (string) Name of the repository in the format of `{username}/{reponame}`.
137
148
  - `ref`: (string) Git ref (branch or commit or tag). The default value is `main`.
138
149
  - `subdir`: (string) Directory of the repo to clone from. The default value is none.
139
- - `force`: (boolean) Extract to the exisiting dir even if already exsists.
140
- - `forceClean`: (boolean) ⚠️ Clean ups any existing directory or file before cloning.
141
- - `offline`: (boolean) Do not attempt to download and use cached version.
150
+ - `force`: (boolean) Extract to the existing dir even if already exists.
151
+ - `forceClean`: (boolean) ⚠️ Clean up any existing directory or file before cloning.
152
+ - `offline`: (boolean) Do not attempt to download and use the cached version.
142
153
  - `preferOffline`: (boolean) Use cache if exists otherwise try to download.
143
154
  - `providers`: (object) A map from provider name to custom providers. Can be used to override built-ins too.
144
- - `registry`: (string or false) Set to `false` to disable registry. Set to a URL string (without trailing slash) for custom registry. (Can be overriden with `GIGET_REGISTRY` environment variable).
155
+ - `registry`: (string or false) Set to `false` to disable registry. Set to a URL string (without trailing slash) for custom registry. (Can be overridden with `GIGET_REGISTRY` environment variable).
145
156
  - `cwd`: (string) Current working directory to resolve dirs relative to it.
146
- - `auth`: (string) Custom Authorization token to use for downloading template. (Can be overriden with `GIGET_AUTH` environment variable).
157
+ - `auth`: (string) Custom Authorization token to use for downloading template. (Can be overridden with `GIGET_AUTH` environment variable).
147
158
 
148
159
  **Return value:**
149
160
 
@@ -152,11 +163,11 @@ The return value is a promise that resolves to the resolved template.
152
163
  - `dir`: (string) Path to extracted dir.
153
164
  - `source`: (string) Normalized version of the input source without provider.
154
165
  - [other provider template keys]
155
- - `url`: (string) URL of repostiroy that can be opened in browser. Useful for logging.
166
+ - `url`: (string) URL of the repository that can be opened in the browser. Useful for logging.
156
167
 
157
168
  ## Custom Providers
158
169
 
159
- Using programmatic method, you can make your own custom template providers.
170
+ Using the programmatic method, you can make your custom template providers.
160
171
 
161
172
  ```ts
162
173
  import type { TemplateProvider } from "giget";
@@ -184,7 +195,7 @@ You can define additional [custom registry](#custom-registry) providers using `r
184
195
  import { registryProvider } from "giget";
185
196
 
186
197
  const themes = registryProvider(
187
- "https://raw.githubusercontent.com/unjs/giget/main/templates"
198
+ "https://raw.githubusercontent.com/unjs/giget/main/templates",
188
199
  );
189
200
 
190
201
  const { source, dir } = await downloadRepo("themes:test", {
@@ -192,9 +203,15 @@ const { source, dir } = await downloadRepo("themes:test", {
192
203
  });
193
204
  ```
194
205
 
206
+ ## Providing token for private repositories
207
+
208
+ For private repositories and sources, you might need a token. In order to provide it, using CLI, you can use `--auth`, using programmatic API using `auth` option and in both modes also it is possible to use `GIGET_AUTH` environment variable to set it. The value will be set in `Authorization: Bearer ...` header by default.
209
+
210
+ **Note:** For github private repository access with Fine-grained access tokens, you need to give **Contents** and **Metadata** repository permissions.
211
+
195
212
  ## Related projects
196
213
 
197
- Giget wouldn't be possible without inspiration from former projects. In comparison, giget does not depend on any local command which increases stability and performance, supports custom template providers, auth and many more features out of the box.
214
+ Giget wouldn't be possible without inspiration from former projects. In comparison, giget does not depend on any local command which increases stability and performance and supports custom template providers, auth, and many more features out of the box.
198
215
 
199
216
  - https://github.com/samsonjs/gitter
200
217
  - https://github.com/tiged/tiged
@@ -215,11 +232,11 @@ Published under [MIT License](./LICENSE).
215
232
 
216
233
  <!-- Badges -->
217
234
 
218
- [npm-version-src]: https://img.shields.io/npm/v/giget?style=flat-square
219
- [npm-version-href]: https://npmjs.com/package/giget
220
- [npm-downloads-src]: https://img.shields.io/npm/dm/giget?style=flat-square
221
- [npm-downloads-href]: https://npmjs.com/package/giget
222
- [github-actions-src]: https://img.shields.io/github/workflow/status/unjs/giget/ci/main?style=flat-square
223
- [github-actions-href]: https://github.com/unjs/giget/actions?query=workflow%3Aci
224
- [codecov-src]: https://img.shields.io/codecov/c/gh/unjs/giget/main?style=flat-square
225
- [codecov-href]: https://codecov.io/gh/unjs/giget
235
+ [npm-version-src]: https://img.shields.io/npm/v/packageName?style=flat&colorA=18181B&colorB=F0DB4F
236
+ [npm-version-href]: https://npmjs.com/package/packageName
237
+ [npm-downloads-src]: https://img.shields.io/npm/dm/packageName?style=flat&colorA=18181B&colorB=F0DB4F
238
+ [npm-downloads-href]: https://npmjs.com/package/packageName
239
+ [codecov-src]: https://img.shields.io/codecov/c/gh/unjs/packageName/main?style=flat&colorA=18181B&colorB=F0DB4F
240
+ [codecov-href]: https://codecov.io/gh/unjs/packageName
241
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/packageName?style=flat&colorA=18181B&colorB=F0DB4F
242
+ [bundle-href]: https://bundlephobia.com/result?p=packageName
package/dist/cli.cjs CHANGED
@@ -1,67 +1,178 @@
1
- #!/usr/bin/env node
2
1
  'use strict';
3
2
 
4
3
  const node_path = require('node:path');
5
- const mri = require('mri');
6
- const colorette = require('colorette');
7
- const giget = require('./shared/giget.a16f8b31.cjs');
4
+ const citty = require('citty');
5
+ const consola = require('consola');
6
+ const index = require('./index.cjs');
8
7
  require('node:fs/promises');
9
8
  require('node:fs');
10
9
  require('tar');
11
10
  require('pathe');
12
11
  require('defu');
12
+ require('nypm');
13
13
  require('node:stream');
14
14
  require('node:child_process');
15
15
  require('node:os');
16
16
  require('node:util');
17
- require('node-fetch-native');
18
- require('https-proxy-agent');
17
+ require('node-fetch-native/proxy');
19
18
 
20
- async function main() {
21
- const arguments_ = mri(process.argv.slice(2), {
22
- boolean: [
23
- "help",
24
- "force",
25
- "force-clean",
26
- "offline",
27
- "prefer-offline",
28
- "shell",
29
- "verbose"
30
- ],
31
- string: ["registry", "cwd", "auth"]
32
- });
33
- const input = arguments_._[0];
34
- const dir = arguments_._[1];
35
- if (!input || arguments_.help || arguments_.h) {
36
- console.error(
37
- "Usage: npx giget@latest <input> [<dir>] [--force] [--force-clean] [--offline] [--prefer-offline] [--shell] [--registry] [--no-registry] [--verbose] [--cwd] [--auth]"
38
- );
39
- process.exit(1);
40
- }
41
- if (arguments_.verbose) {
42
- process.env.DEBUG = process.env.DEBUG || "true";
43
- }
44
- const r = await giget.downloadTemplate(input, {
45
- dir,
46
- force: arguments_.force,
47
- forceClean: arguments_["force-clean"],
48
- offline: arguments_.offline,
49
- registry: arguments_.registry,
50
- cwd: arguments_.cwd,
51
- auth: arguments_.auth
52
- });
53
- console.log(
54
- `\u2728 Successfully cloned ${colorette.cyan(r.name || r.url)} to ${colorette.cyan(
55
- node_path.relative(process.cwd(), r.dir)
56
- )}
57
- `
58
- );
59
- if (arguments_.shell) {
60
- giget.startShell(r.dir);
19
+ const name = "giget";
20
+ const version = "1.2.0";
21
+ const description = "Download templates and git repositories with pleasure!";
22
+ const repository = "unjs/giget";
23
+ const license = "MIT";
24
+ const sideEffects = false;
25
+ const type = "module";
26
+ const exports$1 = {
27
+ ".": {
28
+ "import": {
29
+ types: "./dist/index.d.mts",
30
+ "default": "./dist/index.mjs"
31
+ },
32
+ require: {
33
+ types: "./dist/index.d.cts",
34
+ "default": "./dist/index.cjs"
35
+ }
36
+ }
37
+ };
38
+ const main = "./dist/index.cjs";
39
+ const module$1 = "./dist/index.mjs";
40
+ const types = "./dist/index.d.ts";
41
+ const bin = {
42
+ giget: "./dist/cli.mjs"
43
+ };
44
+ const files = [
45
+ "dist"
46
+ ];
47
+ const scripts = {
48
+ build: "unbuild",
49
+ dev: "vitest dev",
50
+ giget: "jiti ./src/cli.ts",
51
+ lint: "eslint --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
52
+ "lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test",
53
+ prepack: "unbuild",
54
+ play: "pnpm giget --force-clean --verbose unjs .tmp/clone",
55
+ release: "pnpm test && changelogen --release && npm publish && git push --follow-tags",
56
+ test: "pnpm lint && vitest run --coverage"
57
+ };
58
+ const dependencies = {
59
+ citty: "^0.1.5",
60
+ consola: "^3.2.3",
61
+ defu: "^6.1.3",
62
+ "node-fetch-native": "^1.6.1",
63
+ nypm: "^0.3.3",
64
+ ohash: "^1.1.3",
65
+ pathe: "^1.1.1",
66
+ tar: "^6.2.0"
67
+ };
68
+ const devDependencies = {
69
+ "@types/node": "^20.10.5",
70
+ "@types/tar": "^6.1.10",
71
+ "@vitest/coverage-v8": "^1.1.0",
72
+ changelogen: "^0.5.5",
73
+ eslint: "^8.56.0",
74
+ "eslint-config-unjs": "^0.2.1",
75
+ jiti: "^1.21.0",
76
+ prettier: "^3.1.1",
77
+ typescript: "^5.3.3",
78
+ unbuild: "^2.0.0",
79
+ vitest: "^1.1.0"
80
+ };
81
+ const packageManager = "pnpm@8.12.1";
82
+ const pkg = {
83
+ name: name,
84
+ version: version,
85
+ description: description,
86
+ repository: repository,
87
+ license: license,
88
+ sideEffects: sideEffects,
89
+ type: type,
90
+ exports: exports$1,
91
+ main: main,
92
+ module: module$1,
93
+ types: types,
94
+ bin: bin,
95
+ files: files,
96
+ scripts: scripts,
97
+ dependencies: dependencies,
98
+ devDependencies: devDependencies,
99
+ packageManager: packageManager
100
+ };
101
+
102
+ const mainCommand = citty.defineCommand({
103
+ meta: {
104
+ name: pkg.name,
105
+ version: pkg.version,
106
+ description: pkg.description
107
+ },
108
+ args: {
109
+ // TODO: Make it `-t` in the next major version
110
+ template: {
111
+ type: "positional",
112
+ description: "Template name or a a URI describing provider, repository, subdir, and branch/ref"
113
+ },
114
+ dir: {
115
+ type: "positional",
116
+ description: "A relative or absolute path where to extract the template",
117
+ required: false
118
+ },
119
+ auth: {
120
+ type: "string",
121
+ description: "Custom Authorization token to use for downloading template. (Can be overriden with `GIGET_AUTH` environment variable)"
122
+ },
123
+ cwd: {
124
+ type: "string",
125
+ description: "Set current working directory to resolve dirs relative to it"
126
+ },
127
+ force: {
128
+ type: "boolean",
129
+ description: "Clone to existing directory even if exists"
130
+ },
131
+ forceClean: {
132
+ type: "boolean",
133
+ description: "Remove any existing directory or file recusively before cloning"
134
+ },
135
+ offline: {
136
+ type: "boolean",
137
+ description: "o not attempt to download and use cached version"
138
+ },
139
+ preferOffline: {
140
+ type: "boolean",
141
+ description: "Use cache if exists otherwise try to download"
142
+ },
143
+ shell: {
144
+ type: "boolean",
145
+ description: "Open a new shell with current working "
146
+ },
147
+ install: {
148
+ type: "boolean",
149
+ description: "Install dependencies after cloning"
150
+ },
151
+ verbose: {
152
+ type: "boolean",
153
+ description: "Show verbose debugging info"
154
+ }
155
+ },
156
+ run: async ({ args }) => {
157
+ if (args.verbose) {
158
+ process.env.DEBUG = process.env.DEBUG || "true";
159
+ }
160
+ const r = await index.downloadTemplate(args.template, {
161
+ dir: args.dir,
162
+ force: args.force,
163
+ forceClean: args.forceClean,
164
+ offline: args.offline,
165
+ preferOffline: args.preferOffline,
166
+ auth: args.auth,
167
+ install: args.install
168
+ });
169
+ const _from = r.name || r.url;
170
+ const _to = node_path.relative(process.cwd(), r.dir) || "./";
171
+ consola.consola.log(`\u2728 Successfully cloned \`${_from}\` to \`${_to}\`
172
+ `);
173
+ if (args.shell) {
174
+ index.startShell(r.dir);
175
+ }
61
176
  }
62
- process.exit(0);
63
- }
64
- main().catch((error) => {
65
- console.error(error);
66
- process.exit(1);
67
177
  });
178
+ citty.runMain(mainCommand);
package/dist/cli.d.cts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.mts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
package/dist/cli.mjs CHANGED
@@ -1,65 +1,176 @@
1
- #!/usr/bin/env node
2
1
  import { relative } from 'node:path';
3
- import mri from 'mri';
4
- import { cyan } from 'colorette';
5
- import { d as downloadTemplate, s as startShell } from './shared/giget.093c29e5.mjs';
2
+ import { defineCommand, runMain } from 'citty';
3
+ import { consola } from 'consola';
4
+ import { downloadTemplate, startShell } from './index.mjs';
6
5
  import 'node:fs/promises';
7
6
  import 'node:fs';
8
7
  import 'tar';
9
8
  import 'pathe';
10
9
  import 'defu';
10
+ import 'nypm';
11
11
  import 'node:stream';
12
12
  import 'node:child_process';
13
13
  import 'node:os';
14
14
  import 'node:util';
15
- import 'node-fetch-native';
16
- import 'https-proxy-agent';
15
+ import 'node-fetch-native/proxy';
17
16
 
18
- async function main() {
19
- const arguments_ = mri(process.argv.slice(2), {
20
- boolean: [
21
- "help",
22
- "force",
23
- "force-clean",
24
- "offline",
25
- "prefer-offline",
26
- "shell",
27
- "verbose"
28
- ],
29
- string: ["registry", "cwd", "auth"]
30
- });
31
- const input = arguments_._[0];
32
- const dir = arguments_._[1];
33
- if (!input || arguments_.help || arguments_.h) {
34
- console.error(
35
- "Usage: npx giget@latest <input> [<dir>] [--force] [--force-clean] [--offline] [--prefer-offline] [--shell] [--registry] [--no-registry] [--verbose] [--cwd] [--auth]"
36
- );
37
- process.exit(1);
38
- }
39
- if (arguments_.verbose) {
40
- process.env.DEBUG = process.env.DEBUG || "true";
41
- }
42
- const r = await downloadTemplate(input, {
43
- dir,
44
- force: arguments_.force,
45
- forceClean: arguments_["force-clean"],
46
- offline: arguments_.offline,
47
- registry: arguments_.registry,
48
- cwd: arguments_.cwd,
49
- auth: arguments_.auth
50
- });
51
- console.log(
52
- `\u2728 Successfully cloned ${cyan(r.name || r.url)} to ${cyan(
53
- relative(process.cwd(), r.dir)
54
- )}
55
- `
56
- );
57
- if (arguments_.shell) {
58
- startShell(r.dir);
17
+ const name = "giget";
18
+ const version = "1.2.0";
19
+ const description = "Download templates and git repositories with pleasure!";
20
+ const repository = "unjs/giget";
21
+ const license = "MIT";
22
+ const sideEffects = false;
23
+ const type = "module";
24
+ const exports = {
25
+ ".": {
26
+ "import": {
27
+ types: "./dist/index.d.mts",
28
+ "default": "./dist/index.mjs"
29
+ },
30
+ require: {
31
+ types: "./dist/index.d.cts",
32
+ "default": "./dist/index.cjs"
33
+ }
34
+ }
35
+ };
36
+ const main = "./dist/index.cjs";
37
+ const module = "./dist/index.mjs";
38
+ const types = "./dist/index.d.ts";
39
+ const bin = {
40
+ giget: "./dist/cli.mjs"
41
+ };
42
+ const files = [
43
+ "dist"
44
+ ];
45
+ const scripts = {
46
+ build: "unbuild",
47
+ dev: "vitest dev",
48
+ giget: "jiti ./src/cli.ts",
49
+ lint: "eslint --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
50
+ "lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test",
51
+ prepack: "unbuild",
52
+ play: "pnpm giget --force-clean --verbose unjs .tmp/clone",
53
+ release: "pnpm test && changelogen --release && npm publish && git push --follow-tags",
54
+ test: "pnpm lint && vitest run --coverage"
55
+ };
56
+ const dependencies = {
57
+ citty: "^0.1.5",
58
+ consola: "^3.2.3",
59
+ defu: "^6.1.3",
60
+ "node-fetch-native": "^1.6.1",
61
+ nypm: "^0.3.3",
62
+ ohash: "^1.1.3",
63
+ pathe: "^1.1.1",
64
+ tar: "^6.2.0"
65
+ };
66
+ const devDependencies = {
67
+ "@types/node": "^20.10.5",
68
+ "@types/tar": "^6.1.10",
69
+ "@vitest/coverage-v8": "^1.1.0",
70
+ changelogen: "^0.5.5",
71
+ eslint: "^8.56.0",
72
+ "eslint-config-unjs": "^0.2.1",
73
+ jiti: "^1.21.0",
74
+ prettier: "^3.1.1",
75
+ typescript: "^5.3.3",
76
+ unbuild: "^2.0.0",
77
+ vitest: "^1.1.0"
78
+ };
79
+ const packageManager = "pnpm@8.12.1";
80
+ const pkg = {
81
+ name: name,
82
+ version: version,
83
+ description: description,
84
+ repository: repository,
85
+ license: license,
86
+ sideEffects: sideEffects,
87
+ type: type,
88
+ exports: exports,
89
+ main: main,
90
+ module: module,
91
+ types: types,
92
+ bin: bin,
93
+ files: files,
94
+ scripts: scripts,
95
+ dependencies: dependencies,
96
+ devDependencies: devDependencies,
97
+ packageManager: packageManager
98
+ };
99
+
100
+ const mainCommand = 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 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 = relative(process.cwd(), r.dir) || "./";
169
+ consola.log(`\u2728 Successfully cloned \`${_from}\` to \`${_to}\`
170
+ `);
171
+ if (args.shell) {
172
+ startShell(r.dir);
173
+ }
59
174
  }
60
- process.exit(0);
61
- }
62
- main().catch((error) => {
63
- console.error(error);
64
- process.exit(1);
65
175
  });
176
+ runMain(mainCommand);