diff --git a/README.md b/README.md index cf1b3a3..3c9c9ff 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Features -✨ Support popular git providers (GitHub, GitLab, Bitbucket, Sourcehut) out of the box. +✨ Support popular git providers (GitHub, GitLab, Bitbucket, Sourcehut, Codeberg) out of the box. ✨ Built-in and custom [template registry](#template-registry). @@ -78,6 +78,9 @@ npx giget@latest bitbucket:unjs/template # Clone from sourcehut npx giget@latest sourcehut:pi0/unjs-template +# Clone from codeberg +npx giget@latest codeberg:unjs/template + # Clone from https URL (tarball) npx giget@latest https://api.github.com/repos/unjs/template/tarball/main @@ -142,7 +145,7 @@ const { source, dir } = await downloadTemplate("github:unjs/template"); - `source`: (string) Input source in format of `[provider]:repo[/subpath][#ref]`. - `options`: (object) Options are usually inferred from the input string. You can customize them. - `dir`: (string) Destination directory to clone to. If not provided, `user-name` will be used relative to the current directory. - - `provider`: (string) Either `github`, `gitlab`, `bitbucket` or `sourcehut`. The default is `github`. + - `provider`: (string) Either `github`, `gitlab`, `bitbucket`, `sourcehut` or `codeberg`. The default is `github`. - `force`: (boolean) Extract to the existing dir even if already exists. - `forceClean`: (boolean) ⚠️ Clean up any existing directory or file before cloning. - `offline`: (boolean) Do not attempt to download and use the cached version. diff --git a/src/providers.ts b/src/providers.ts index ba8ce43..88549fd 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -128,6 +128,20 @@ export const sourcehut: TemplateProvider = (input, options) => { }; }; +export const codeberg: TemplateProvider = (input, options) => { + const parsed = parseGitURI(input); + return { + name: parsed.repo.replace("/", "-"), + version: parsed.ref, + subdir: parsed.subdir, + headers: { + authorization: options.auth ? `token ${options.auth}` : undefined, + }, + url: `https://codeberg.org/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`, + tar: `https://codeberg.org/${parsed.repo}/archive/${parsed.ref}.tar.gz`, + }; +}; + export const providers: Record = { http, https: http, @@ -136,4 +150,5 @@ export const providers: Record = { gitlab, bitbucket, sourcehut, + codeberg, }; diff --git a/src/types.ts b/src/types.ts index b9c3ac4..871c99d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,5 @@ export interface GitInfo { - provider: "github" | "gitlab" | "bitbucket" | "sourcehut"; + provider: "github" | "gitlab" | "bitbucket" | "sourcehut" | "codeberg"; repo: string; subdir: string; ref: string; diff --git a/test/getgit.test.ts b/test/getgit.test.ts index 96e7ddc..15ec2cd 100644 --- a/test/getgit.test.ts +++ b/test/getgit.test.ts @@ -15,11 +15,11 @@ describe("downloadTemplate", () => { dir: destinationDirectory, preferOffline: true, }); - expect(await existsSync(resolve(dir, "package.json"))); + expect(existsSync(resolve(dir, "package.json"))); }); - it("do not clone to exisiting dir", async () => { - const destinationDirectory = resolve(__dirname, ".tmp/exisiting"); + it("do not clone to existing dir", async () => { + const destinationDirectory = resolve(__dirname, ".tmp/existing"); await mkdir(destinationDirectory).catch(() => {}); await writeFile(resolve(destinationDirectory, "test.txt"), "test"); await expect(