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 +55 -38
- package/dist/cli.cjs +163 -52
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +163 -52
- package/dist/index.cjs +360 -15
- package/dist/index.d.cts +49 -0
- package/dist/index.d.mts +49 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +361 -12
- package/package.json +33 -27
- package/dist/shared/giget.093c29e5.mjs +0 -287
- package/dist/shared/giget.a16f8b31.cjs +0 -291
package/README.md
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
#
|
|
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
|
-
[![
|
|
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
|
-
|
|
12
|
+
✨ Support popular git providers (GitHub, GitLab, Bitbucket, Sourcehut) out of the box.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
✨ Built-in and custom [template registry](#template-registry).
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
✨ Fast cloning using tarball gzip without depending on local `git` and `tar`.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
✨ Works online and offline with disk cache support.
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
✨ Custom template provider support with programmatic usage.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
✨ Support extracting with a sub dir.
|
|
23
23
|
|
|
24
|
-
|
|
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
|
|
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
|
|
43
|
-
- `--shell`: ⚠️ Open a new shell with current working directory in cloned dir. (Experimental).
|
|
44
|
-
- `--registry`: URL to a custom registry. (Can be
|
|
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
|
|
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.
|
|
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
|
|
140
|
-
- `forceClean`: (boolean) ⚠️ Clean
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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/
|
|
219
|
-
[npm-version-href]: https://npmjs.com/package/
|
|
220
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/
|
|
221
|
-
[npm-downloads-href]: https://npmjs.com/package/
|
|
222
|
-
[
|
|
223
|
-
[
|
|
224
|
-
[
|
|
225
|
-
[
|
|
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
|
|
6
|
-
const
|
|
7
|
-
const
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
package/dist/cli.d.mts
ADDED
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
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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);
|