Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support installing dependencies #134

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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