Skip to content

Commit 64a88d8

Browse files
authored
feat: add CLI flag for report server port (#28)
1 parent f7aedf2 commit 64a88d8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ $ graphql-usage SCHEMA SOURCEDIR
6060
- `-h`, `--help`: show CLI help
6161
- `-v`, `--version`: show CLI version
6262
- `--exclude`: Directories to ignore under src
63+
- `--port`: Port to run the report server on
6364
- `--quiet`: No output to stdout
6465

6566
## Example:

src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class GraphqlStats extends Command {
3434
description: "Directories to ignore under src",
3535
multiple: true
3636
}),
37+
port: flags.integer({
38+
description: "Port to run the report server on",
39+
default: 3001
40+
}),
3741
quiet: flags.boolean({
3842
description: "No output to stdout",
3943
default: false
@@ -58,7 +62,7 @@ class GraphqlStats extends Command {
5862
async run() {
5963
const { args, flags } = this.parse(GraphqlStats);
6064
const { schema, sourceDir } = args;
61-
const { json, exclude, quiet } = flags;
65+
const { json, exclude, port, quiet } = flags;
6266
const renderer = quiet ? "silent" : "default";
6367

6468
const analyzeFilesTask = {
@@ -85,9 +89,9 @@ class GraphqlStats extends Command {
8589
[
8690
analyzeFilesTask,
8791
{
88-
title: "Starting server at http://localhost:3001",
92+
title: `Starting server at http://localhost:${port}`,
8993
task: ({ report }: { report: Report }) => {
90-
startServer(report);
94+
startServer(report, port);
9195
}
9296
}
9397
],
@@ -181,8 +185,7 @@ function writeJSON(report: Report): Promise<void> {
181185
);
182186
}
183187

184-
function startServer(report: Report): void {
185-
const port = 3001;
188+
function startServer(report: Report, port: number): void {
186189
createServer(report).listen(port, async () => {
187190
// tslint:disable-next-line:no-http-string
188191
await open(`http://localhost:${port}`);

0 commit comments

Comments
 (0)