giget 1.1.0 → 1.1.2
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 +19 -13
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{giget.6c52cb03.mjs → giget.093c29e5.mjs} +27 -10
- package/dist/shared/{giget.51477975.cjs → giget.a16f8b31.cjs} +27 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -113,10 +113,10 @@ Import:
|
|
|
113
113
|
|
|
114
114
|
```js
|
|
115
115
|
// ESM
|
|
116
|
-
import { downloadTemplate } from
|
|
116
|
+
import { downloadTemplate } from "giget";
|
|
117
117
|
|
|
118
118
|
// CommonJS
|
|
119
|
-
const { downloadTemplate } = require(
|
|
119
|
+
const { downloadTemplate } = require("giget");
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
### `downloadTemplate(source, options?)`
|
|
@@ -124,7 +124,7 @@ const { downloadTemplate } = require('giget')
|
|
|
124
124
|
**Example:**
|
|
125
125
|
|
|
126
126
|
```js
|
|
127
|
-
const { source, dir } = await downloadTemplate(
|
|
127
|
+
const { source, dir } = await downloadTemplate("github:unjs/template");
|
|
128
128
|
```
|
|
129
129
|
|
|
130
130
|
**Options:**
|
|
@@ -159,19 +159,21 @@ The return value is a promise that resolves to the resolved template.
|
|
|
159
159
|
Using programmatic method, you can make your own custom template providers.
|
|
160
160
|
|
|
161
161
|
```ts
|
|
162
|
-
import type { TemplateProvider } from
|
|
162
|
+
import type { TemplateProvider } from "giget";
|
|
163
163
|
|
|
164
164
|
const rainbow: TemplateProvider = async (input, { auth }) => {
|
|
165
165
|
return {
|
|
166
|
-
name:
|
|
166
|
+
name: "rainbow",
|
|
167
167
|
version: input,
|
|
168
|
-
headers: {
|
|
168
|
+
headers: { authorization: auth },
|
|
169
169
|
url: `https://rainbow.template/?variant=${input}`,
|
|
170
|
-
tar: `https://rainbow.template/dl/rainbow.${input}.tar.gz
|
|
171
|
-
}
|
|
172
|
-
}
|
|
170
|
+
tar: `https://rainbow.template/dl/rainbow.${input}.tar.gz`,
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
173
|
|
|
174
|
-
const { source, dir } = await downloadRepo(
|
|
174
|
+
const { source, dir } = await downloadRepo("rainbow:one", {
|
|
175
|
+
providers: { rainbow },
|
|
176
|
+
});
|
|
175
177
|
```
|
|
176
178
|
|
|
177
179
|
### Custom Registry Providers
|
|
@@ -179,11 +181,15 @@ const { source, dir } = await downloadRepo('rainbow:one', { providers: { rainbow
|
|
|
179
181
|
You can define additional [custom registry](#custom-registry) providers using `registryProvider` utility and register to `providers`.
|
|
180
182
|
|
|
181
183
|
```ts
|
|
182
|
-
import { registryProvider } from
|
|
184
|
+
import { registryProvider } from "giget";
|
|
183
185
|
|
|
184
|
-
const themes = registryProvider(
|
|
186
|
+
const themes = registryProvider(
|
|
187
|
+
"https://raw.githubusercontent.com/unjs/giget/main/templates"
|
|
188
|
+
);
|
|
185
189
|
|
|
186
|
-
const { source, dir } = await downloadRepo(
|
|
190
|
+
const { source, dir } = await downloadRepo("themes:test", {
|
|
191
|
+
providers: { themes },
|
|
192
|
+
});
|
|
187
193
|
```
|
|
188
194
|
|
|
189
195
|
## Related projects
|
package/dist/cli.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const node_path = require('node:path');
|
|
5
5
|
const mri = require('mri');
|
|
6
6
|
const colorette = require('colorette');
|
|
7
|
-
const giget = require('./shared/giget.
|
|
7
|
+
const giget = require('./shared/giget.a16f8b31.cjs');
|
|
8
8
|
require('node:fs/promises');
|
|
9
9
|
require('node:fs');
|
|
10
10
|
require('tar');
|
package/dist/cli.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { relative } from 'node:path';
|
|
3
3
|
import mri from 'mri';
|
|
4
4
|
import { cyan } from 'colorette';
|
|
5
|
-
import { d as downloadTemplate, s as startShell } from './shared/giget.
|
|
5
|
+
import { d as downloadTemplate, s as startShell } from './shared/giget.093c29e5.mjs';
|
|
6
6
|
import 'node:fs/promises';
|
|
7
7
|
import 'node:fs';
|
|
8
8
|
import 'tar';
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as downloadTemplate, r as registryProvider, s as startShell } from './shared/giget.
|
|
1
|
+
export { d as downloadTemplate, r as registryProvider, s as startShell } from './shared/giget.093c29e5.mjs';
|
|
2
2
|
import 'node:fs/promises';
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import 'tar';
|
|
@@ -48,14 +48,31 @@ function debug(...arguments_) {
|
|
|
48
48
|
console.debug("[giget]", ...arguments_);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
async function sendFetch(url, options) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
async function sendFetch(url, options = {}) {
|
|
52
|
+
if (!options.agent) {
|
|
53
|
+
const proxyEnv = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
|
54
|
+
if (proxyEnv) {
|
|
55
|
+
options.agent = createHttpsProxyAgent(proxyEnv);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (options?.headers) {
|
|
59
|
+
options.headers = normalizeHeaders(options.headers);
|
|
60
|
+
}
|
|
61
|
+
return await fetch(url, options);
|
|
55
62
|
}
|
|
56
63
|
function cacheDirectory() {
|
|
57
64
|
return process.env.XDG_CACHE_HOME ? resolve(process.env.XDG_CACHE_HOME, "giget") : resolve(homedir(), ".cache/giget");
|
|
58
65
|
}
|
|
66
|
+
function normalizeHeaders(headers = {}) {
|
|
67
|
+
const normalized = {};
|
|
68
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
69
|
+
if (!value) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
normalized[key.toLowerCase()] = value;
|
|
73
|
+
}
|
|
74
|
+
return normalized;
|
|
75
|
+
}
|
|
59
76
|
function currentShell() {
|
|
60
77
|
if (process.env.SHELL) {
|
|
61
78
|
return process.env.SHELL;
|
|
@@ -86,7 +103,7 @@ const github = (input, options) => {
|
|
|
86
103
|
version: parsed.ref,
|
|
87
104
|
subdir: parsed.subdir,
|
|
88
105
|
headers: {
|
|
89
|
-
|
|
106
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
90
107
|
},
|
|
91
108
|
url: `${github2}/${parsed.repo}/tree/${parsed.ref}${parsed.subdir}`,
|
|
92
109
|
tar: `${github2}/${parsed.repo}/archive/${parsed.ref}.tar.gz`
|
|
@@ -100,7 +117,7 @@ const gitlab = (input, options) => {
|
|
|
100
117
|
version: parsed.ref,
|
|
101
118
|
subdir: parsed.subdir,
|
|
102
119
|
headers: {
|
|
103
|
-
|
|
120
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
104
121
|
},
|
|
105
122
|
url: `${gitlab2}/${parsed.repo}/tree/${parsed.ref}${parsed.subdir}`,
|
|
106
123
|
tar: `${gitlab2}/${parsed.repo}/-/archive/${parsed.ref}.tar.gz`
|
|
@@ -113,7 +130,7 @@ const bitbucket = (input, options) => {
|
|
|
113
130
|
version: parsed.ref,
|
|
114
131
|
subdir: parsed.subdir,
|
|
115
132
|
headers: {
|
|
116
|
-
|
|
133
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
117
134
|
},
|
|
118
135
|
url: `https://bitbucket.com/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`,
|
|
119
136
|
tar: `https://bitbucket.org/${parsed.repo}/get/${parsed.ref}.tar.gz`
|
|
@@ -126,7 +143,7 @@ const sourcehut = (input, options) => {
|
|
|
126
143
|
version: parsed.ref,
|
|
127
144
|
subdir: parsed.subdir,
|
|
128
145
|
headers: {
|
|
129
|
-
|
|
146
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
130
147
|
},
|
|
131
148
|
url: `https://git.sr.ht/~${parsed.repo}/tree/${parsed.ref}/item${parsed.subdir}`,
|
|
132
149
|
tar: `https://git.sr.ht/~${parsed.repo}/archive/${parsed.ref}.tar.gz`
|
|
@@ -148,7 +165,7 @@ const registryProvider = (registryEndpoint = DEFAULT_REGISTRY, options) => {
|
|
|
148
165
|
const registryURL = `${registryEndpoint}/${input}.json`;
|
|
149
166
|
const result = await sendFetch(registryURL, {
|
|
150
167
|
headers: {
|
|
151
|
-
|
|
168
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
152
169
|
}
|
|
153
170
|
});
|
|
154
171
|
if (result.status >= 400) {
|
|
@@ -227,7 +244,7 @@ async function downloadTemplate(input, options = {}) {
|
|
|
227
244
|
await download(template.tar, tarPath, {
|
|
228
245
|
headers: {
|
|
229
246
|
authorization: options.auth ? `Bearer ${options.auth}` : void 0,
|
|
230
|
-
...template.headers
|
|
247
|
+
...normalizeHeaders(template.headers)
|
|
231
248
|
}
|
|
232
249
|
}).catch((error) => {
|
|
233
250
|
if (!existsSync(tarPath)) {
|
|
@@ -50,14 +50,31 @@ function debug(...arguments_) {
|
|
|
50
50
|
console.debug("[giget]", ...arguments_);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
async function sendFetch(url, options) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
async function sendFetch(url, options = {}) {
|
|
54
|
+
if (!options.agent) {
|
|
55
|
+
const proxyEnv = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
|
56
|
+
if (proxyEnv) {
|
|
57
|
+
options.agent = createHttpsProxyAgent(proxyEnv);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (options?.headers) {
|
|
61
|
+
options.headers = normalizeHeaders(options.headers);
|
|
62
|
+
}
|
|
63
|
+
return await nodeFetchNative.fetch(url, options);
|
|
57
64
|
}
|
|
58
65
|
function cacheDirectory() {
|
|
59
66
|
return process.env.XDG_CACHE_HOME ? pathe.resolve(process.env.XDG_CACHE_HOME, "giget") : pathe.resolve(node_os.homedir(), ".cache/giget");
|
|
60
67
|
}
|
|
68
|
+
function normalizeHeaders(headers = {}) {
|
|
69
|
+
const normalized = {};
|
|
70
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
71
|
+
if (!value) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
normalized[key.toLowerCase()] = value;
|
|
75
|
+
}
|
|
76
|
+
return normalized;
|
|
77
|
+
}
|
|
61
78
|
function currentShell() {
|
|
62
79
|
if (process.env.SHELL) {
|
|
63
80
|
return process.env.SHELL;
|
|
@@ -88,7 +105,7 @@ const github = (input, options) => {
|
|
|
88
105
|
version: parsed.ref,
|
|
89
106
|
subdir: parsed.subdir,
|
|
90
107
|
headers: {
|
|
91
|
-
|
|
108
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
92
109
|
},
|
|
93
110
|
url: `${github2}/${parsed.repo}/tree/${parsed.ref}${parsed.subdir}`,
|
|
94
111
|
tar: `${github2}/${parsed.repo}/archive/${parsed.ref}.tar.gz`
|
|
@@ -102,7 +119,7 @@ const gitlab = (input, options) => {
|
|
|
102
119
|
version: parsed.ref,
|
|
103
120
|
subdir: parsed.subdir,
|
|
104
121
|
headers: {
|
|
105
|
-
|
|
122
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
106
123
|
},
|
|
107
124
|
url: `${gitlab2}/${parsed.repo}/tree/${parsed.ref}${parsed.subdir}`,
|
|
108
125
|
tar: `${gitlab2}/${parsed.repo}/-/archive/${parsed.ref}.tar.gz`
|
|
@@ -115,7 +132,7 @@ const bitbucket = (input, options) => {
|
|
|
115
132
|
version: parsed.ref,
|
|
116
133
|
subdir: parsed.subdir,
|
|
117
134
|
headers: {
|
|
118
|
-
|
|
135
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
119
136
|
},
|
|
120
137
|
url: `https://bitbucket.com/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`,
|
|
121
138
|
tar: `https://bitbucket.org/${parsed.repo}/get/${parsed.ref}.tar.gz`
|
|
@@ -128,7 +145,7 @@ const sourcehut = (input, options) => {
|
|
|
128
145
|
version: parsed.ref,
|
|
129
146
|
subdir: parsed.subdir,
|
|
130
147
|
headers: {
|
|
131
|
-
|
|
148
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
132
149
|
},
|
|
133
150
|
url: `https://git.sr.ht/~${parsed.repo}/tree/${parsed.ref}/item${parsed.subdir}`,
|
|
134
151
|
tar: `https://git.sr.ht/~${parsed.repo}/archive/${parsed.ref}.tar.gz`
|
|
@@ -150,7 +167,7 @@ const registryProvider = (registryEndpoint = DEFAULT_REGISTRY, options) => {
|
|
|
150
167
|
const registryURL = `${registryEndpoint}/${input}.json`;
|
|
151
168
|
const result = await sendFetch(registryURL, {
|
|
152
169
|
headers: {
|
|
153
|
-
|
|
170
|
+
authorization: options.auth ? `Bearer ${options.auth}` : void 0
|
|
154
171
|
}
|
|
155
172
|
});
|
|
156
173
|
if (result.status >= 400) {
|
|
@@ -229,7 +246,7 @@ async function downloadTemplate(input, options = {}) {
|
|
|
229
246
|
await download(template.tar, tarPath, {
|
|
230
247
|
headers: {
|
|
231
248
|
authorization: options.auth ? `Bearer ${options.auth}` : void 0,
|
|
232
|
-
...template.headers
|
|
249
|
+
...normalizeHeaders(template.headers)
|
|
233
250
|
}
|
|
234
251
|
}).catch((error) => {
|
|
235
252
|
if (!node_fs.existsSync(tarPath)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "giget",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Download templates and git repositories with pleasure!",
|
|
5
5
|
"repository": "unjs/giget",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"changelogen": "^0.4.1",
|
|
50
50
|
"eslint": "^8.34.0",
|
|
51
51
|
"eslint-config-unjs": "^0.1.0",
|
|
52
|
-
"jiti": "^1.17.
|
|
52
|
+
"jiti": "^1.17.1",
|
|
53
53
|
"prettier": "^2.8.4",
|
|
54
54
|
"typescript": "^4.9.5",
|
|
55
|
-
"unbuild": "^1.1.
|
|
55
|
+
"unbuild": "^1.1.2",
|
|
56
56
|
"vitest": "^0.28.5"
|
|
57
57
|
},
|
|
58
58
|
"packageManager": "pnpm@7.27.0"
|