✨ Download templates and git repositories with pleasure!

Overview

giget

npm version npm downloads Github Actions Codecov

Download templates and git repositories with pleasure!

Features

Support popular git providers (GitHub, GitLab, Bitbucket, Sourcehut) out of the box.

Built-in and custom template registry.

Fast cloning using tarball gzip without depending on local git and tar.

Works online and offline with disk cache support.

Custom template provider support with programmatic usage.

Support extracting with a subdir.

Authorization support to download private templates

Usage (CLI)

npx giget@latest <template> [<dir>] [...options]

Arguments

  • template: Template name or a a URI describing provider, repository, subdir, and branch/ref. (See Examples)
  • dir: A relative or absolute path where to extract the template.

Options

  • --force: Clone to exsiting directory even if exists.
  • --offline: Do not attempt to download and use cached version.
  • --prefer-offline: Use cache if exists otherwise try to download.
  • --force-clean: ⚠️ Remove any existing directory or file recusively before cloning.
  • --shell: ⚠️ Open a new shell with current working directory in cloned dir. (Experimental).
  • --registry: URL to a custom registry. (Can be overriden with GIGET_REGISTRY environment variable).
  • --no-registry: Disable registry lookup and functionality.
  • --verbose: Show verbose debugging info.
  • --cwd: Set current working directory to resolve dirs relative to it.
  • --auth: Custom Authorization token to use for downloading template. (Can be overriden with GIGET_AUTH environment variable).

Examples

# Clone nuxt starter from giget template registry
npx giget@latest nuxt

# Clone the main branch of github.com/unjs/template to unjs-template directory
npx giget@latest gh:unjs/template

# Clone to myProject directory
npx giget@latest gh:unjs/template myProject

# Clone dev branch
npx giget@latest gh:unjs/template#dev

# Clone /test directory from main branch
npx giget@latest gh:unjs/template/test

# Clone from gitlab
npx giget@latest gitlab:unjs/template

# Clone from bitbucket
npx giget@latest bitbucket:unjs/template

# Clone from sourcehut
npx giget@latest sourcehut:pi0/unjs-template

Template Registry

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.

If you want to add your template to the built-in registry, just drop a PR to add it to the ./templates directory. Slugs are added on first-come first-served basis but this might change in the future.

Custom Registry

A custom registry should provide an endpoint with dynamic path /:template.json that returns a JSON response with keys same as custom providers.

  • name: (required) Name of the template.
  • tar (required) Link to the tar download link.
  • defaultDir: (optional) Default cloning directory.
  • url: (optional) Webpage of the template.
  • subpath: (optional) Subpath inside the tar file.
  • headers: (optional) Custom headers to send while downloading template.

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.

Usage (Programmatic)

Install package:

# npm
npm install giget

# yarn
yarn install giget

# pnpm
pnpm install giget

Import:

// ESM
import { downloadTemplate } from 'giget'

// CommonJS
const { downloadTemplate } = require('giget')

downloadTemplate(source, options?)

Example:

const { source, dir } = await downloadTemplate('github:unjs/template')

Options:

  • source: (string) Input source in format of [provider]:repo[/subpath][#ref].
  • dir: (string) Destination directory to clone to. If not provided, user-name will be used relative to the current directory.
  • options: (object) Options are usually inferred from the input string. You can customize them.
    • provider: (string) Either github, gitlab, bitbucket or sourcehut. The default is github.
    • repo: (string) Name of repository in format of {username}/{reponame}.
    • ref: (string) Git ref (branch or commit or tag). The default value is main.
    • subdirpath: (string) subdir of the repo to clone from. The default value is none.
    • force: (boolean) Extract to the exisiting dir even if already exsists.
    • forceClean: (boolean) ⚠️ Clean ups any existing directory or file before cloning.
    • offline: (boolean) Do not attempt to download and use cached version.
    • preferOffline: (boolean) Use cache if exists otherwise try to download.
    • providers: (object) A map from provider name to custom providers. Can be used to override built-ins too.
    • 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).
    • cwd: (string) Current working directory to resolve dirs relative to it.
    • auth: (string) Custom Authorization token to use for downloading template. (Can be overriden with GIGET_AUTH environment variable).

Return value:

The return value is a promise that resolves to the resolved template.

  • dir: (string) Path to extracted dir.
  • source: (string) Normalized version of the input source without provider.
  • [other provider template keys]
    • url: (string) URL of repostiroy that can be opened in browser. Useful for logging.

Custom Providers

Using programmatic method, you can make your own custom template providers.

import type { TemplateProvider } from 'giget'

const rainbow: TemplateProvider = async (input, { auth }) => {
  return {
    name: 'rainbow',
    version: input,
    headers: { Authorization: auth },
    url: `https://rainbow.template/?variant=${input}`,
    tar: `https://rainbow.template/dl/rainbow.${input}.tar.gz`
  }
}

const { source, dir } = await downloadRepo('rainbow:one', { providers: { rainbow } })

Custom Registry Providers

You can define additional custom registry providers using registryProvider utility and register to providers.

import { registryProvider } from 'giget'

const themes = registryProvider('https://raw.githubusercontent.com/unjs/giget/main/templates')

const { source, dir } = await downloadRepo('themes:test', { providers: { themes } })

Related projects

Giget wouldn't be possible without inspering from former projects. In comparation 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.

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with 💛

Published under MIT License.

Comments
  • docs: add sidebase template to template registry

    docs: add sidebase template to template registry

    As per:

    If you want to add your template to the built-in registry, just drop a PR to add it to the ./templates directory. Slugs are added on first-come first-served basis but this might change in the future.

    from https://github.com/unjs/giget#template-registry I want to add sidebase as a template, so that it can be used via the nuxi init command (:

    As per https://github.com/sidestream-tech/sidebase/issues/33 we will talk on twitter about this after:

    • [ ] we flattened the repo + upgrade to RC10 (https://github.com/sidestream-tech/sidebase/tree/upgrade_to_rc10)
    • [ ] this PR was merged
    • [ ] sidebase-docs were updated
    opened by BracketJohn 3
  • Readme section on differences between degit/tiged

    Readme section on differences between degit/tiged

    Hey! After seeing this being published, definitely gonna be my default cloner after using degit/tiged. Curious what are the differences between other packages? I'd love to help contribute the readme.

    documentation 
    opened by grikomsn 3
  • CLI: Change the directory to the new successfully cloned repo

    CLI: Change the directory to the new successfully cloned repo

    To avoid cd into the new repo after the cloning, add on the CLI an opt-in feature to do the directory change automatically

    Bonus: an opt-out feature to automatically install deps using ni ?

    opened by edimitchel 3
  • feat: add `stacks` template

    feat: add `stacks` template

    Great project! Thanks for all of the work!

    Looking forward to helping out, wherever possible, and to making it one of the default ways to get started with the Stacks framework, as we're finalizing & stabilizing it for the initial launch 🙏🏼

    opened by chrisbbreuer 2
  • docs: add comparation notes to the related projects

    docs: add comparation notes to the related projects

    Description

    This PR adds a "Comparison" section to explain differences between degit/tiged.

    Changes

    Notes

    • We could add a short description about the section, but current attempt aims to be concise like other sections.
    opened by grikomsn 2
  • chore(deps): update all non-major dependencies

    chore(deps): update all non-major dependencies

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | jiti | ^1.16.0 -> ^1.16.1 | age | adoption | passing | confidence | | pnpm (source) | 7.21.0 -> 7.22.0 | age | adoption | passing | confidence |


    Release Notes

    unjs/jiti

    v1.16.1

    Compare Source

    pnpm/pnpm

    v7.22.0

    Compare Source

    Minor Changes

    • The pnpm list and pnpm why commands will now look through transitive dependencies of workspace: packages. A new --only-projects flag is available to only print workspace: packages.
    • pnpm exec and pnpm run command support --resume-from option. When used, the command will executed from given package #​4690.
    • Expose the npm_command environment variable to lifecycle hooks & scripts.

    Patch Changes

    • Fix a situation where pnpm list and pnpm why may not respect the --depth argument.
    • Report to the console when a git-hosted dependency is built #​5847.
    • Throw an accurate error message when trying to install a package that has no versions, or all of its versions are unpublished #​5849.
    • replace dependency is-ci by ci-info (is-ci is just a simple wrapper around ci-info).
    • Only run prepublish scripts of git-hosted dependencies, if the dependency doesn't have a main file. In this case we can assume that the dependencies has to be built.
    • Print more contextual information when a git-hosted package fails to be prepared for installation #​5847.

    Our Gold Sponsors

    Our Silver Sponsors


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    👻 Immortal: This PR will be recreated if closed unmerged. Get config help if that's undesired.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 1
  • chore(deps): update all non-major dependencies to ^0.26.3

    chore(deps): update all non-major dependencies to ^0.26.3

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | @vitest/coverage-c8 | ^0.26.2 -> ^0.26.3 | age | adoption | passing | confidence | | vitest | ^0.26.2 -> ^0.26.3 | age | adoption | passing | confidence |


    Release Notes

    vitest-dev/vitest

    v0.26.3

    Compare Source

       🚀 Features
       🐞 Bug Fixes
        View changes on GitHub

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about these updates again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 1
  • chore(deps): update devdependency eslint to ^8.31.0

    chore(deps): update devdependency eslint to ^8.31.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | eslint (source) | ^8.30.0 -> ^8.31.0 | age | adoption | passing | confidence |


    Release Notes

    eslint/eslint

    v8.31.0

    Compare Source

    Features
    • 52c7c73 feat: check assignment patterns in no-underscore-dangle (#​16693) (Milos Djermanovic)
    • b401cde feat: add options to check destructuring in no-underscore-dangle (#​16006) (Morten Kaltoft)
    • 30d0daf feat: group properties with values in parentheses in key-spacing (#​16677) (Francesco Trotta)
    Bug Fixes
    • 35439f1 fix: correct syntax error in prefer-arrow-callback autofix (#​16722) (Francesco Trotta)
    • 87b2470 fix: new instance of FlatESLint should load latest config file version (#​16608) (Milos Djermanovic)
    Documentation
    Chores

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 1
  • chore(deps): update pnpm to v7.21.0

    chore(deps): update pnpm to v7.21.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | pnpm (source) | 7.20.0 -> 7.21.0 | age | adoption | passing | confidence |


    Release Notes

    pnpm/pnpm

    v7.21.0

    Compare Source

    Minor Changes

    • The pnpm dlx command supports the --shell-mode (or -c) option. When used, the script is executed by a shell #​5679.

    Patch Changes

    • The config command should work with the --location=global CLI option #​5841.
    • Only the pnpm add --global <pkg> command should fail if there is no global pnpm bin directory in the system PATH #​5841.

    Our Gold Sponsors

    Our Silver Sponsors


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 1
  • chore(deps): update devdependency @types/node to ^18.11.18

    chore(deps): update devdependency @types/node to ^18.11.18

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | @types/node (source) | ^18.11.17 -> ^18.11.18 | age | adoption | passing | confidence |


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 1
  • chore(deps): update pnpm to v7.20.0

    chore(deps): update pnpm to v7.20.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | pnpm (source) | 7.19.0 -> 7.20.0 | age | adoption | passing | confidence |


    Release Notes

    pnpm/pnpm

    v7.20.0

    Compare Source

    Minor Changes

    • pnpm gets its own implementation of the following commands:

      • pnpm config get
      • pnpm config set
      • pnpm config delete
      • pnpm config list

      In previous versions these commands were passing through to npm CLI.

      PR: #​5829 Related issue: #​5621

    • Add show alias to pnpm view #​5835.

    • pnpm reads settings from its own global configuration file at $XDG_CONFIG_HOME/pnpm/rc #​5829.

    • Add the 'description'-field to the licenses output #​5836.

    Patch Changes

    • pnpm rebuild should not fail if node_modules was created by pnpm version 7.18 or older #​5815.
    • pnpm env should print help.
    • Run the prepublish scripts of packages installed from Git #​5826.
    • pnpm rebuild should print a better error message when a hoisted dependency is not found #​5815.

    Our Gold Sponsors

    Our Silver Sponsors


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 1
  • Typo in cli usage

    Typo in cli usage

    @pi0

    3 months and counting... is nobody else confused?

    https://github.com/unjs/giget/blob/fbce78ab6f47e24f27e0c626d4d8aaf5070e612b/src/cli.ts#L13

    Perhaps an origin story unfolding...

    opened by ashbeats 1
  • Improve docs for vendor specific private tokens + github fine ganed tokens

    Improve docs for vendor specific private tokens + github fine ganed tokens

    Describe the feature

    I've been happy to see that you've added support for accessing private repos via Token. In our organisation we use the new fine-graded tokens. Which permissions do we need to set in order to use giget? Content + Metadata readonly doesn't seem to work (returns a 404 error).

    Would be great to get some documentation

    Thanks a lot! :)

    Additional information

    • [ ] Would you be willing to help implement this feature?
    opened by Dominic-Marcelino 1
  • perf: directly use `codeload.github.com` to reduce http redirect

    perf: directly use `codeload.github.com` to reduce http redirect

    We could improve online performance by reducing one HTTP redirect and directly use codeload.github.com.

    https://codeload.github.com/unjs/template/tar.gz/refs/heads/main

    The challenge is that we must guess the ref type and change heads/ to either tags/ or commits/.

    idea 
    opened by pi0 0
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    This repository currently has no open or pending branches.

    Detected dependencies

    github-actions
    .github/workflows/ci.yml
    • actions/checkout v3
    • actions/setup-node v3
    • codecov/codecov-action v3
    npm
    package.json
    • colorette ^2.0.19
    • defu ^6.1.1
    • https-proxy-agent ^5.0.1
    • mri ^1.2.0
    • node-fetch-native ^1.0.1
    • pathe ^1.0.0
    • tar ^6.1.13
    • @types/node ^18.11.18
    • @types/tar ^6.1.3
    • @vitest/coverage-c8 ^0.26.3
    • eslint ^8.31.0
    • eslint-config-unjs ^0.0.3
    • jiti ^1.16.1
    • standard-version ^9.5.0
    • typescript ^4.9.4
    • unbuild ^1.0.2
    • vitest ^0.26.3
    • pnpm 7.22.0

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
Owner
unjs
Unified JavaScript Tools
unjs
Search your code and 2M+ public repositories on Sourcegraph directly within Raycast.

Sourcegraph for Raycast Search your code and 2M+ public repositories on Sourcegraph directly within Raycast. Install · Setup · Commands · Issues · Cha

Robert Lin 5 Jul 10, 2022
Node js package makes creating node jd dependincies files like Controllers,Entities and Repositories easier by executing a few instructions

Nodejs Studio Node js package makes creating node js project dependincies files like Controllers,Entities and Repositories easier by executing a few i

Syrian Open Source 9 Oct 12, 2022
Make your repositories and READMEs more beautiful!

Dynamic Image Renderer API easy to use - open source Make your repositories and READMEs more beautiful! This API generate an image dynamically with yo

Thiago 12 Nov 19, 2022
GitHub action to automate managing repositories with labels, milestones and projects.

triagecat GitHub action to automate managing repositories with labels, milestones and projects. Link issues and PRs labels. Add issues and PRs to a pr

Oliver Wilkes 6 Jun 14, 2022
Tool for GitHub/GitLab to keep Repositories/Projects you are interested in and their Pull/Merge Requests in desktop Tray Menu

Tool for GitHub/GitLab to keep Repositories/Projects you are interested in and their Pull/Merge Requests in desktop Tray Menu. More info in User Guide.

Oleksii Bilyk 5 Jul 31, 2022
A GUI to browse and restore restic backup repositories.

A simple, cross-platform restic backup GUI for browsing and restoring restic repositories. Built with Wails2, based on leaanthony's Restoric PoC. Down

Eduard Müller / taktik 91 Dec 29, 2022
Manage GitHub resources like repositories, teams, members, integrations and workflows with the AWS CDK as Custom Resources in CloudFormation.

CDK Github Manage GitHub resources like repositories, teams, members, integrations and workflows with the AWS CDK as Custom Resources in CloudFormatio

Pepperize 8 Nov 25, 2022
portfolio-project is a npm package to automatically update your projects section in your portfolio website. It will fetch the selected repositories directly from your GitHub account.

portfolio-project Those days of manually updating portfolio website after every new project made are gone ⚡ Yesss . . . you read that right. ?? portfo

Gaurav Gulati 15 Aug 3, 2021
🚀 📈 Stock market game where the stocks are github repositories

GitHubStonks What is githubstonks ? githubstonks.com Githubstonks is a stock market game where the stocks are popular GitHub repositories. You can buy

Mustafa Ozturk 40 Sep 27, 2022
Cloney - Clone all Github repositories from a user or organization

Cloney - Clone all Github repositories from a user or organization How to use $ cloney (users|orgs) (name) Preview Installation Prerequisites NodeJS E

Breydan 2 May 28, 2022
A Leaderboard that shows who has given your stars to your repositories

A Leaderboard that shows who has given your stars to your repositories

Victor Peralta 6 Mar 22, 2022
Token-gated repositories via GitHub API.

GateRepo About | Implementation | License About Simple implementation of ERC20 token-gating GitHub repositories. Fueled by Mike's tweet. Implementatio

Anish Agnihotri 114 Oct 16, 2022
Use signature-based minting to allow users who have contributed to your github repositories to claim an NFT!

GitHub contributors NFT rewards This project demonstrates how you can build a full-stack web3 application that allows github contributors of certain r

thirdweb templates 8 Nov 5, 2022
Repository for hands on practice in Git and GitHub workshop

Git and Github Workshop Jan 2022 Successful contributors ✨ of this project will be featured on the GDSC website so as to bring attraction and learn vi

IIIT Vadodara Open Source 2 Feb 10, 2022
Visualize the Directed Acyclic Graph that Git creates to connect Commit, Tree and Blob objects internally.

Git Graph Visualize the Directed Acyclic Graph that Git creates to connect Commit, Tree and Blob objects. Hosted at HarshKapadia2.github.io/git-graph.

Harsh Kapadia 15 Aug 21, 2022
Get a diff view of your Obsidian Sync, File Recovery and Git version history

Version History Diff (for Sync and File Recovery Core plugins and Git) Note This plugin uses private APIs, so it may break at any time. Use at your ow

null 39 Dec 26, 2022
🧘‍♀️ Chamomile simplifies issue and git tracking from the command line.

Chamomile What is Chamomile? Chamomile simplifies issue and git tracking from the command line. As of now the focus is bridging workflows involving Gr

Zev Stravitz 3 Aug 4, 2022
A command line application to simplify the git workflow on committing, pushing and others commands.

Git-Suite A command line application to simplify the git workflow on committing, pushing and others commands. Prerequisites Install Node Package Manag

Lucas Gobatto 5 Aug 10, 2022
Learn Basic of Node Express Server and Git & Github by creating Pull Request in this repository.

hacktoberfest-express-server-2022 Learn Basic of Node Express Server and Git & Github by creating Pull Request in this repository. Special Note For Ev

NetScape-Web 3 Oct 6, 2022