Skip to content

Commit

Permalink
feat: support installing dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 24, 2023
1 parent 6e2455a commit 9b37fa2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

✔ Authorization support to download private templates

✔ Optionally install dependencies after clone using [unjs/nypm](https://github.com/unjs/nypm)

## Usage (CLI)

```bash
Expand All @@ -46,6 +48,7 @@ npx giget@latest <template> [<dir>] [...options]
- `--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).
- `--install`: Install dependencies after cloning using [unjs/nypm](https://github.com/unjs/nypm).

### Examples

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"consola": "^3.2.3",
"defu": "^6.1.3",
"node-fetch-native": "^1.5.1",
"nypm": "^0.3.3",
"ohash": "^1.1.3",
"pathe": "^1.1.1",
"tar": "^6.2.0"
Expand Down
32 changes: 14 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const mainCommand = defineCommand({
type: "boolean",
description: "Open a new shell with current working ",
},
install: {
type: "boolean",
description: "Install dependencies after cloning",
},
verbose: {
type: "boolean",
description: "Show verbose debugging info",
Expand All @@ -71,6 +75,7 @@ const mainCommand = defineCommand({
offline: args.offline,
preferOffline: args.preferOffline,
auth: args.auth,
install: args.install,
});

const _from = r.name || r.url;
Expand Down
11 changes: 11 additions & 0 deletions src/giget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync, readdirSync } from "node:fs";
import { extract } from "tar";
import { resolve, dirname } from "pathe";
import { defu } from "defu";
import { installDependencies } from "nypm";
import { cacheDirectory, download, debug, normalizeHeaders } from "./_utils";
import { providers } from "./providers";
import { registryProvider } from "./registry";
Expand All @@ -19,6 +20,8 @@ export interface DownloadTemplateOptions {
registry?: false | string;
cwd?: string;
auth?: string;
install?: boolean;
silent?: boolean;
}

const sourceProtoRe = /^([\w-.]+):/;
Expand Down Expand Up @@ -155,6 +158,14 @@ export async function downloadTemplate(
});
debug(`Extracted to ${extractPath} in ${Date.now() - s}ms`);

if (options.install) {
debug("Installing dependencies...");
await installDependencies({
cwd: extractPath,
silent: options.silent,
});
}

return {
...template,
source,
Expand Down

0 comments on commit 9b37fa2

Please sign in to comment.