Skip to content

Commit 8d63583

Browse files
authored
feat(cli): add fetch command (#720)
* fix: playground * feat(cli): add fetch command * feat(cli): add fetch command * feat(cli): add fetch command
1 parent 8712d60 commit 8d63583

File tree

5 files changed

+88
-7
lines changed

5 files changed

+88
-7
lines changed

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"nypm": "0.6.4",
3838
"pathe": "catalog:",
3939
"std-env": "3.10.0",
40+
"srvx": "catalog:",
4041
"tinyexec": "1.0.2"
4142
},
4243
"publishConfig": {

packages/cli/src/commands/fetch.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { build, createVercube } from '@vercube/devkit';
2+
import { defineCommand } from 'citty';
3+
import { cliFetch } from 'srvx/cli';
4+
import type { CommandDef } from 'citty';
5+
6+
export const fetchCommand = defineCommand({
7+
meta: {
8+
name: 'fetch',
9+
description: 'Fetch a request from the application',
10+
},
11+
args: {
12+
url: {
13+
type: 'positional',
14+
description: 'URL to fetch',
15+
default: '/',
16+
},
17+
entry: {
18+
type: 'string',
19+
description: 'Entry point for the application',
20+
default: 'index.mjs',
21+
},
22+
method: {
23+
type: 'string',
24+
description: 'HTTP method (default: GET, or POST if body is provided)',
25+
default: 'GET',
26+
alias: 'X',
27+
valueHint: 'GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS',
28+
},
29+
headers: {
30+
type: 'string',
31+
description: 'Add header (format: "Name: Value, Name: Value, ...")',
32+
alias: 'H',
33+
},
34+
data: {
35+
type: 'string',
36+
description: 'Request body (use @- for stdin, @file for file)',
37+
alias: 'd',
38+
},
39+
verbose: {
40+
type: 'boolean',
41+
description: 'Show request and response headers',
42+
alias: 'v',
43+
default: false,
44+
},
45+
},
46+
async run(ctx) {
47+
const app = await createVercube({ build: { dts: false } });
48+
49+
// build app before running the command
50+
await build(app);
51+
52+
await cliFetch({
53+
verbose: ctx.args.verbose,
54+
dir: app.config.build?.output?.dir ?? 'dist',
55+
entry: ctx.args.entry,
56+
url: ctx.args.url,
57+
method: ctx.args.method,
58+
headers: ctx.args.headers?.split(',') ?? [],
59+
data: ctx.args.data,
60+
});
61+
},
62+
}) as CommandDef;

packages/cli/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineCommand, runMain } from 'citty';
33
import { version } from '../package.json';
44
import { buildCommand } from './commands/build';
55
import { devCommand } from './commands/dev';
6+
import { fetchCommand } from './commands/fetch';
67
import { initCommand } from './commands/init';
78

89
const main = defineCommand({
@@ -15,6 +16,7 @@ const main = defineCommand({
1516
build: buildCommand,
1617
dev: devCommand,
1718
init: initCommand,
19+
fetch: fetchCommand,
1820
},
1921
});
2022

pnpm-lock.yaml

Lines changed: 22 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ catalog:
1111
defu: 6.1.4
1212
pathe: 2.0.3
1313
rolldown: 1.0.0-rc.2
14-
srvx: 0.10.1
14+
srvx: npm:srvx-nightly
1515
zod: 4.3.6
1616

1717
ignoredBuiltDependencies:

0 commit comments

Comments
 (0)